in src/main/java/com/googlesource/gerrit/plugins/adminconsole/ShowAccountCommand.java [90:189]
public void run() throws UnloggedFailure, Exception {
AccountState account;
if (name.isEmpty()) {
throw new UnloggedFailure(
1,
"You need to tell me who to find: LastName,\\\\ Firstname, email@address.com, account id or an user name. "
+ "Be sure to double-escape spaces, for example: \"show-account Last,\\\\ First\"");
}
Set<Account.Id> idList = accountResolver.resolve(name).asIdSet();
if (idList.isEmpty()) {
throw new UnloggedFailure(
1,
"No accounts found for your query: \""
+ name
+ "\""
+ " Tip: Try double-escaping spaces, for example: \"show-account Last,\\\\ First\"");
}
stdout.println(
"Found "
+ idList.size()
+ " result"
+ (idList.size() > 1 ? "s" : "")
+ ": for query: \""
+ name
+ "\"");
stdout.println();
for (Account.Id id : idList) {
account = accountResolver.resolve(id.toString()).asUnique();
if (account == null) {
throw new UnloggedFailure("Account " + id.toString() + " does not exist.");
}
stdout.println("Full name: " + account.account().fullName());
stdout.println("Account Id: " + id.toString());
stdout.println("Preferred Email: " + account.account().preferredEmail());
Optional<AccountState> accountState = accountCache.get(id);
if (accountState.isPresent()) {
stdout.println("User Name: " + accountState.get().userName().get());
}
stdout.println("Active: " + account.account().isActive());
stdout.println("Registered on: " + account.account().registeredOn());
stdout.println("");
stdout.println("External Ids:");
stdout.println(String.format("%-50s %s", "Email Address:", "External Id:"));
try {
for (ExternalId externalId : externalIds.byAccount(account.account().id())) {
stdout.println(
String.format(
"%-50s %s",
(externalId.email() == null ? "" : externalId.email()), externalId.key()));
}
} catch (IOException e) {
throw new UnloggedFailure(1, "Error getting external Ids: " + e.getMessage(), e);
}
if (showKeys) {
stdout.println("");
stdout.println("Public Keys:");
List<SshKeyInfo> sshKeys;
try {
sshKeys = getSshKeys.get().apply(new AccountResource(userFactory.create(id))).value();
} catch (AuthException
| IOException
| ConfigInvalidException
| PermissionBackendException e) {
throw new UnloggedFailure(1, "Error getting sshkeys: " + e.getMessage(), e);
}
if (sshKeys == null || sshKeys.isEmpty()) {
stdout.println("None");
} else {
stdout.println(String.format("%-9s %s", "Status:", "Key:"));
for (SshKeyInfo sshKey : sshKeys) {
stdout.println(
String.format(
"%-9s %s", (sshKey.valid ? "Active" : "Inactive"), sshKey.sshPublicKey));
}
}
}
if (showGroups) {
stdout.println();
stdout.println(
"Member of groups"
+ (filterGroups == null ? "" : " (Filtering on \"" + filterGroups + "\")")
+ ":");
List<GroupInfo> groupInfos =
accountGetGroups.get().apply(new AccountResource(userFactory.create(id))).value();
Collections.sort(groupInfos, new CustomComparator());
for (GroupInfo groupInfo : groupInfos) {
if (null == filterGroups
|| groupInfo.name.toLowerCase().contains(filterGroups.toLowerCase())) {
stdout.println(groupInfo.name);
}
}
}
stdout.println("");
}
}