use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class AccountGroupUUIDHandler method parseArguments.
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
final String n = params.getParameter(0);
AccountGroup.UUID uuid = AccountGroup.uuid(n);
if (groupBackend.handles(uuid)) {
GroupDescription.Basic d = groupBackend.get(uuid);
if (d != null) {
setter.addValue(uuid);
return 1;
}
}
// Might be a numeric AccountGroup.Id. -> Internal group.
if (n.matches("^[1-9][0-9]*$")) {
try {
AccountGroup.Id groupId = AccountGroup.Id.parse(n);
Optional<InternalGroup> groupInternal = groupCache.get(groupId);
if (groupInternal.isPresent()) {
uuid = new InternalGroupDescription(groupInternal.get()).getGroupUUID();
setter.addValue(uuid);
return 1;
}
} catch (IllegalArgumentException e) {
// Ignored
}
}
GroupReference group = GroupBackends.findExactSuggestion(groupBackend, n);
if (group == null) {
throw new CmdLineException(owner, localizable("Group \"%s\" does not exist"), n);
}
setter.addValue(group.getUUID());
return 1;
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method assertGroupDoesNotExist.
protected void assertGroupDoesNotExist(String groupName) {
InternalGroup group = groupCache.get(AccountGroup.nameKey(groupName)).orElse(null);
assertWithMessage(groupName).that(group).isNull();
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class LuceneGroupIndex method add.
@Override
void add(Document doc, Values<InternalGroup> values) {
// Add separate DocValues field for the field that is needed for sorting.
FieldDef<InternalGroup, ?> f = values.getField();
if (f == UUID) {
String value = (String) getOnlyElement(values.getValues());
doc.add(new SortedDocValuesField(UUID_SORT_FIELD, new BytesRef(value)));
}
super.add(doc, values);
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class GroupsOnInit method addGroupMemberInNoteDb.
private void addGroupMemberInNoteDb(Repository repository, AccountGroup.UUID groupUuid, Account account) throws IOException, ConfigInvalidException, NoSuchGroupException {
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, repository, groupUuid);
InternalGroup group = groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupUuid));
GroupDelta groupDelta = getMemberAdditionDelta(account);
AuditLogFormatter auditLogFormatter = getAuditLogFormatter(account);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
commit(repository, groupConfig, group.getCreatedOn());
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class InitAdminUser method postRun.
@Override
public void postRun() throws Exception {
if (!accounts.hasAnyAccount()) {
welcome();
}
AuthType authType = flags.cfg.getEnum(AuthType.values(), "auth", null, "type", null);
if (authType != AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
return;
}
if (!accounts.hasAnyAccount()) {
ui.header("Gerrit Administrator");
if (ui.yesno(true, "Create administrator user")) {
Account.Id id = Account.id(sequencesOnInit.nextAccountId());
String username = ui.readString("admin", "username");
String name = ui.readString("Administrator", "name");
String httpPassword = ui.readString("secret", "HTTP password");
AccountSshKey sshKey = readSshKey(id);
String email = readEmail(sshKey);
List<ExternalId> extIds = new ArrayList<>(2);
extIds.add(externalIdFactory.createUsername(username, id, httpPassword));
if (email != null) {
extIds.add(externalIdFactory.createEmail(id, email));
}
externalIds.insert("Add external IDs for initial admin user", extIds);
Account persistedAccount = accounts.insert(Account.builder(id, TimeUtil.now()).setFullName(name).setPreferredEmail(email));
// Only two groups should exist at this point in time and hence iterating over all of them
// is cheap.
Optional<GroupReference> adminGroupReference = groupsOnInit.getAllGroupReferences().filter(group -> group.getName().equals("Administrators")).findAny();
if (!adminGroupReference.isPresent()) {
throw new NoSuchGroupException("Administrators");
}
GroupReference adminGroup = adminGroupReference.get();
groupsOnInit.addGroupMember(adminGroup.getUUID(), persistedAccount);
if (sshKey != null) {
VersionedAuthorizedKeysOnInit authorizedKeys = authorizedKeysFactory.create(id).load();
authorizedKeys.addKey(sshKey.sshPublicKey());
authorizedKeys.save("Add SSH key for initial admin user\n");
}
AccountState as = AccountState.forAccount(persistedAccount, extIds);
for (AccountIndex accountIndex : accountIndexCollection.getWriteIndexes()) {
accountIndex.replace(as);
}
InternalGroup adminInternalGroup = groupsOnInit.getExistingGroup(adminGroup);
for (GroupIndex groupIndex : groupIndexCollection.getWriteIndexes()) {
groupIndex.replace(adminInternalGroup);
}
}
}
}
Aggregations