Line data Source code
1 : // Copyright (C) 2011 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.sshd.commands; 16 : 17 : import com.google.gerrit.extensions.common.NameInput; 18 : import com.google.gerrit.extensions.restapi.IdString; 19 : import com.google.gerrit.extensions.restapi.RestApiException; 20 : import com.google.gerrit.extensions.restapi.TopLevelResource; 21 : import com.google.gerrit.server.group.GroupResource; 22 : import com.google.gerrit.server.restapi.group.GroupsCollection; 23 : import com.google.gerrit.server.restapi.group.PutName; 24 : import com.google.gerrit.sshd.CommandMetaData; 25 : import com.google.gerrit.sshd.SshCommand; 26 : import com.google.inject.Inject; 27 : import java.io.IOException; 28 : import org.eclipse.jgit.errors.ConfigInvalidException; 29 : import org.kohsuke.args4j.Argument; 30 : 31 : @CommandMetaData(name = "rename-group", description = "Rename an account group") 32 1 : public class RenameGroupCommand extends SshCommand { 33 : @Argument( 34 : index = 0, 35 : required = true, 36 : metaVar = "GROUP", 37 : usage = "name of the group to be renamed") 38 : private String groupName; 39 : 40 : @Argument(index = 1, required = true, metaVar = "NEWNAME", usage = "new name of the group") 41 : private String newGroupName; 42 : 43 : @Inject private GroupsCollection groups; 44 : 45 : @Inject private PutName putName; 46 : 47 : @Override 48 : protected void run() throws Failure { 49 0 : enableGracefulStop(); 50 : try { 51 0 : GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName)); 52 0 : NameInput input = new NameInput(); 53 0 : input.name = newGroupName; 54 0 : putName.apply(rsrc, input); 55 0 : } catch (RestApiException | IOException | ConfigInvalidException e) { 56 0 : throw die(e); 57 0 : } 58 0 : } 59 : }