use of com.google.gerrit.entities.GroupReference 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.GroupReference in project gerrit by GerritCodeReview.
the class PluginConfig method withInheritance.
PluginConfig withInheritance(ProjectState.Factory projectStateFactory) {
checkState(projectConfig().isPresent(), "no project config provided");
ProjectState state = projectStateFactory.create(projectConfig().get());
ProjectState parent = Iterables.getFirst(state.parents(), null);
if (parent == null) {
return this;
}
Map<AccountGroup.UUID, GroupReference> groupReferences = new HashMap<>();
groupReferences.putAll(groupReferences());
PluginConfig parentPluginConfig = parent.getPluginConfig(pluginName()).withInheritance(projectStateFactory);
Set<String> allNames = cfg().getNames(PLUGIN, pluginName());
Config newCfg = copyConfig(cfg());
for (String name : parentPluginConfig.cfg().getNames(PLUGIN, pluginName())) {
if (!allNames.contains(name)) {
List<String> values = Arrays.asList(parentPluginConfig.cfg().getStringList(PLUGIN, pluginName(), name));
for (String value : values) {
Optional<GroupReference> groupRef = parentPluginConfig.projectConfig().get().getGroupByName(GroupReference.extractGroupName(value));
if (groupRef.isPresent()) {
groupReferences.putIfAbsent(groupRef.get().getUUID(), groupRef.get());
}
}
newCfg.setStringList(PLUGIN, pluginName(), name, values);
}
}
return new AutoValue_PluginConfig(pluginName(), newCfg, projectConfig(), ImmutableMap.copyOf(groupReferences));
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectWatch method add.
private void add(Watchers matching, Project.NameKey projectName, NotifyConfig nc) throws QueryParseException {
logger.atFine().log("Checking watchers for notify config %s from project %s", nc, projectName);
for (GroupReference groupRef : nc.getGroups()) {
CurrentUser user = new GroupBackedUser(ImmutableSet.of(groupRef.getUUID()));
if (filterMatch(user, nc.getFilter())) {
deliverToMembers(matching.list(nc.getHeader()), groupRef.getUUID());
logger.atFine().log("Added watchers for group %s", groupRef);
} else {
logger.atFine().log("The filter did not match for group %s; skip notification", groupRef);
}
}
if (!nc.getAddresses().isEmpty()) {
if (filterMatch(null, nc.getFilter())) {
matching.list(nc.getHeader()).emails.addAll(nc.getAddresses());
logger.atFine().log("Added watchers for these addresses: %s", nc.getAddresses());
} else {
logger.atFine().log("The filter did not match; skip notification for these addresses: %s", nc.getAddresses());
}
}
}
use of com.google.gerrit.entities.GroupReference 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);
}
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupsNoteDbConsistencyChecker method readGroupNames.
private void readGroupNames(Repository repo, List<Ref> refs, Result result, BiMap<AccountGroup.UUID, String> uuidNameBiMap) throws IOException {
Optional<Ref> maybeRef = refs.stream().filter(r -> r.getName().equals(RefNames.REFS_GROUPNAMES)).findFirst();
if (!maybeRef.isPresent()) {
result.problems.add(error("ref %s does not exist", RefNames.REFS_GROUPNAMES));
return;
}
Ref ref = maybeRef.get();
try (RevWalk rw = new RevWalk(repo)) {
RevCommit c = rw.parseCommit(ref.getObjectId());
NoteMap nm = NoteMap.read(rw.getObjectReader(), c);
for (Note note : nm) {
ObjectLoader ld = rw.getObjectReader().open(note.getData());
byte[] data = ld.getCachedBytes();
GroupReference gRef;
try {
gRef = GroupNameNotes.getFromNoteData(data);
} catch (ConfigInvalidException e) {
result.problems.add(error("notename entry %s: %s does not parse: %s", note, new String(data, StandardCharsets.UTF_8), e.getMessage()));
continue;
}
ObjectId nameKey = GroupNameNotes.getNoteKey(AccountGroup.nameKey(gRef.getName()));
if (!Objects.equals(nameKey, note)) {
result.problems.add(error("notename entry %s does not match name %s", note, gRef.getName()));
}
// We trust SHA1 to have no collisions, so no need to check uniqueness of name.
uuidNameBiMap.put(gRef.getUUID(), gRef.getName());
}
}
}
Aggregations