Merge "Add ssh command to list groups."
This commit is contained in:
@@ -54,6 +54,9 @@ see link:user-upload.html#test_ssh[Testing Your SSH Connection].
|
|||||||
'gerrit approve'::
|
'gerrit approve'::
|
||||||
'Deprecated alias for `gerrit review`.'
|
'Deprecated alias for `gerrit review`.'
|
||||||
|
|
||||||
|
link:cmd-ls-groups.html[gerrit ls-groups]::
|
||||||
|
List groups visible to the caller.
|
||||||
|
|
||||||
link:cmd-ls-projects.html[gerrit ls-projects]::
|
link:cmd-ls-projects.html[gerrit ls-projects]::
|
||||||
List projects visible to the caller.
|
List projects visible to the caller.
|
||||||
|
|
||||||
|
44
Documentation/cmd-ls-groups.txt
Normal file
44
Documentation/cmd-ls-groups.txt
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
gerrit ls-groups
|
||||||
|
================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
gerrit ls-groups - List groups visible to caller
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
--------
|
||||||
|
[verse]
|
||||||
|
'ssh' -p <port> <host> 'gerrit ls-groups'
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
Displays the list of group names, one per line, that are visible to
|
||||||
|
the account of the calling user.
|
||||||
|
|
||||||
|
If the caller is a member of the privileged 'Administrators' group,
|
||||||
|
all groups are listed.
|
||||||
|
|
||||||
|
ACCESS
|
||||||
|
------
|
||||||
|
Any user who has configured an SSH key.
|
||||||
|
|
||||||
|
SCRIPTING
|
||||||
|
---------
|
||||||
|
This command is intended to be used in scripts.
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
List visible groups:
|
||||||
|
=====
|
||||||
|
$ ssh -p 29418 review.example.com gerrit ls-groups
|
||||||
|
Administrators
|
||||||
|
Anonymous Users
|
||||||
|
MyProject_Committers
|
||||||
|
Project Owners
|
||||||
|
Registered Users
|
||||||
|
=====
|
||||||
|
|
||||||
|
GERRIT
|
||||||
|
------
|
||||||
|
Part of link:index.html[Gerrit Code Review]
|
@@ -35,7 +35,7 @@ public class AccountModule extends RpcServletModule {
|
|||||||
factory(GroupDetailHandler.Factory.class);
|
factory(GroupDetailHandler.Factory.class);
|
||||||
factory(MyGroupsFactory.Factory.class);
|
factory(MyGroupsFactory.Factory.class);
|
||||||
factory(RenameGroup.Factory.class);
|
factory(RenameGroup.Factory.class);
|
||||||
factory(VisibleGroups.Factory.class);
|
factory(VisibleGroupsHandler.Factory.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rpc(AccountSecurityImpl.class);
|
rpc(AccountSecurityImpl.class);
|
||||||
|
@@ -63,7 +63,7 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
|||||||
private final CreateGroup.Factory createGroupFactory;
|
private final CreateGroup.Factory createGroupFactory;
|
||||||
private final RenameGroup.Factory renameGroupFactory;
|
private final RenameGroup.Factory renameGroupFactory;
|
||||||
private final GroupDetailHandler.Factory groupDetailFactory;
|
private final GroupDetailHandler.Factory groupDetailFactory;
|
||||||
private final VisibleGroups.Factory visibleGroupsFactory;
|
private final VisibleGroupsHandler.Factory visibleGroupsFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GroupAdminServiceImpl(final Provider<ReviewDb> schema,
|
GroupAdminServiceImpl(final Provider<ReviewDb> schema,
|
||||||
@@ -76,7 +76,7 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
|||||||
final CreateGroup.Factory createGroupFactory,
|
final CreateGroup.Factory createGroupFactory,
|
||||||
final RenameGroup.Factory renameGroupFactory,
|
final RenameGroup.Factory renameGroupFactory,
|
||||||
final GroupDetailHandler.Factory groupDetailFactory,
|
final GroupDetailHandler.Factory groupDetailFactory,
|
||||||
final VisibleGroups.Factory visibleGroupsFactory) {
|
final VisibleGroupsHandler.Factory visibleGroupsFactory) {
|
||||||
super(schema, currentUser);
|
super(schema, currentUser);
|
||||||
this.accountCache = accountCache;
|
this.accountCache = accountCache;
|
||||||
this.groupIncludeCache = groupIncludeCache;
|
this.groupIncludeCache = groupIncludeCache;
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.httpd.rpc.account;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.GroupList;
|
||||||
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
|
import com.google.gerrit.server.account.VisibleGroups;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class VisibleGroupsHandler extends Handler<GroupList> {
|
||||||
|
|
||||||
|
interface Factory {
|
||||||
|
VisibleGroupsHandler create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final VisibleGroups.Factory visibleGroupsFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
VisibleGroupsHandler(final VisibleGroups.Factory visibleGroupsFactory) {
|
||||||
|
this.visibleGroupsFactory = visibleGroupsFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroupList call() throws Exception {
|
||||||
|
return visibleGroupsFactory.create().get();
|
||||||
|
}
|
||||||
|
}
|
@@ -10,17 +10,16 @@
|
|||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License
|
||||||
|
|
||||||
package com.google.gerrit.httpd.rpc.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.gerrit.common.data.GroupDetail;
|
import com.google.gerrit.common.data.GroupDetail;
|
||||||
import com.google.gerrit.common.data.GroupList;
|
import com.google.gerrit.common.data.GroupList;
|
||||||
import com.google.gerrit.httpd.rpc.Handler;
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
import com.google.gerrit.reviewdb.AccountGroup;
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.account.GroupCache;
|
import com.google.gwtorm.client.OrmException;
|
||||||
import com.google.gerrit.server.account.GroupControl;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
@@ -29,30 +28,29 @@ import org.apache.commons.collections.CollectionUtils;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VisibleGroups extends Handler<GroupList> {
|
public class VisibleGroups {
|
||||||
|
|
||||||
interface Factory {
|
public interface Factory {
|
||||||
VisibleGroups create();
|
VisibleGroups create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Provider<IdentifiedUser> identifiedUser;
|
private final Provider<IdentifiedUser> identifiedUser;
|
||||||
private final GroupCache groupCache;
|
private final GroupCache groupCache;
|
||||||
private final GroupControl.Factory groupControlFactory;
|
private final GroupControl.Factory groupControlFactory;
|
||||||
private final GroupDetailHandler.Factory groupDetailFactory;
|
private final GroupDetailFactory.Factory groupDetailFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VisibleGroups(final Provider<IdentifiedUser> currentUser,
|
VisibleGroups(final Provider<IdentifiedUser> currentUser,
|
||||||
final GroupCache groupCache,
|
final GroupCache groupCache,
|
||||||
final GroupControl.Factory groupControlFactory,
|
final GroupControl.Factory groupControlFactory,
|
||||||
final GroupDetailHandler.Factory groupDetailFactory) {
|
final GroupDetailFactory.Factory groupDetailFactory) {
|
||||||
this.identifiedUser = currentUser;
|
this.identifiedUser = currentUser;
|
||||||
this.groupCache = groupCache;
|
this.groupCache = groupCache;
|
||||||
this.groupControlFactory = groupControlFactory;
|
this.groupControlFactory = groupControlFactory;
|
||||||
this.groupDetailFactory = groupDetailFactory;
|
this.groupDetailFactory = groupDetailFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public GroupList get() throws OrmException, NoSuchGroupException {
|
||||||
public GroupList call() throws Exception {
|
|
||||||
final IdentifiedUser user = identifiedUser.get();
|
final IdentifiedUser user = identifiedUser.get();
|
||||||
final List<AccountGroup> list = new ArrayList<AccountGroup>();
|
final List<AccountGroup> list = new ArrayList<AccountGroup>();
|
||||||
if (user.getCapabilities().canAdministrateServer()) {
|
if (user.getCapabilities().canAdministrateServer()) {
|
@@ -26,6 +26,7 @@ import com.google.gerrit.server.account.GroupDetailFactory;
|
|||||||
import com.google.gerrit.server.account.GroupMembersFactory;
|
import com.google.gerrit.server.account.GroupMembersFactory;
|
||||||
import com.google.gerrit.server.account.PerformCreateGroup;
|
import com.google.gerrit.server.account.PerformCreateGroup;
|
||||||
import com.google.gerrit.server.account.PerformRenameGroup;
|
import com.google.gerrit.server.account.PerformRenameGroup;
|
||||||
|
import com.google.gerrit.server.account.VisibleGroups;
|
||||||
import com.google.gerrit.server.git.CreateCodeReviewNotes;
|
import com.google.gerrit.server.git.CreateCodeReviewNotes;
|
||||||
import com.google.gerrit.server.git.MergeOp;
|
import com.google.gerrit.server.git.MergeOp;
|
||||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||||
@@ -91,6 +92,7 @@ public class GerritRequestModule extends FactoryModule {
|
|||||||
factory(RegisterNewEmailSender.Factory.class);
|
factory(RegisterNewEmailSender.Factory.class);
|
||||||
factory(PerformCreateGroup.Factory.class);
|
factory(PerformCreateGroup.Factory.class);
|
||||||
factory(PerformRenameGroup.Factory.class);
|
factory(PerformRenameGroup.Factory.class);
|
||||||
|
factory(VisibleGroups.Factory.class);
|
||||||
factory(GroupDetailFactory.Factory.class);
|
factory(GroupDetailFactory.Factory.class);
|
||||||
factory(GroupMembersFactory.Factory.class);
|
factory(GroupMembersFactory.Factory.class);
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,7 @@ public class DefaultCommandModule extends CommandModule {
|
|||||||
command(gerrit).toProvider(new DispatchCommandProvider(gerrit));
|
command(gerrit).toProvider(new DispatchCommandProvider(gerrit));
|
||||||
command(gerrit, "flush-caches").to(FlushCaches.class);
|
command(gerrit, "flush-caches").to(FlushCaches.class);
|
||||||
command(gerrit, "ls-projects").to(ListProjects.class);
|
command(gerrit, "ls-projects").to(ListProjects.class);
|
||||||
|
command(gerrit, "ls-groups").to(ListGroupsCommand.class);
|
||||||
command(gerrit, "query").to(Query.class);
|
command(gerrit, "query").to(Query.class);
|
||||||
command(gerrit, "show-caches").to(ShowCaches.class);
|
command(gerrit, "show-caches").to(ShowCaches.class);
|
||||||
command(gerrit, "show-connections").to(ShowConnections.class);
|
command(gerrit, "show-connections").to(ShowConnections.class);
|
||||||
|
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.sshd.commands;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.GroupDetail;
|
||||||
|
import com.google.gerrit.common.data.GroupList;
|
||||||
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
|
import com.google.gerrit.server.account.VisibleGroups;
|
||||||
|
import com.google.gerrit.sshd.BaseCommand;
|
||||||
|
import com.google.gwtorm.client.OrmException;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.apache.sshd.server.Environment;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
public class ListGroupsCommand extends BaseCommand {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private VisibleGroups.Factory visibleGroupsFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(final Environment env) throws IOException {
|
||||||
|
startThread(new CommandRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() throws Exception {
|
||||||
|
parseCommandLine();
|
||||||
|
ListGroupsCommand.this.display();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void display() throws Failure {
|
||||||
|
final PrintWriter stdout = toPrintWriter(out);
|
||||||
|
try {
|
||||||
|
final GroupList visibleGroups =
|
||||||
|
visibleGroupsFactory.create().get();
|
||||||
|
for (final GroupDetail groupDetail : visibleGroups.getGroups()) {
|
||||||
|
stdout.print(groupDetail.group.getName() + "\n");
|
||||||
|
}
|
||||||
|
} catch (OrmException e) {
|
||||||
|
throw die(e);
|
||||||
|
} catch (NoSuchGroupException e) {
|
||||||
|
throw die(e);
|
||||||
|
} finally {
|
||||||
|
stdout.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user