use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIdIT method unsetHttpPassword.
@Test
public void unsetHttpPassword() throws Exception {
ExternalId extId = externalIdFactory.createWithPassword(externalIdKeyFactory.create("y", "1"), user.id(), null, "secret");
insertExtId(extId);
ExternalId extIdWithoutPassword = externalIdFactory.create("y", "1", user.id());
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
extIdNotes.upsert(extIdWithoutPassword);
extIdNotes.commit(md);
assertThat(extIdNotes.get(extId.key())).hasValue(extIdWithoutPassword);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ProjectCreator method createProjectConfig.
private void createProjectConfig(CreateProjectArgs args) throws IOException, ConfigInvalidException {
try (MetaDataUpdate md = metaDataUpdateFactory.create(args.getProject())) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(newProject -> {
newProject.setDescription(Strings.nullToEmpty(args.projectDescription));
newProject.setSubmitType(MoreObjects.firstNonNull(args.submitType, repositoryCfg.getDefaultSubmitType(args.getProject())));
newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, args.contributorAgreements);
newProject.setBooleanConfig(BooleanProjectConfig.USE_SIGNED_OFF_BY, args.signedOffBy);
newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTENT_MERGE, args.contentMerge);
newProject.setBooleanConfig(BooleanProjectConfig.CREATE_NEW_CHANGE_FOR_ALL_NOT_IN_TARGET, args.newChangeForAllNotInTarget);
newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_CHANGE_ID, args.changeIdRequired);
newProject.setBooleanConfig(BooleanProjectConfig.REJECT_EMPTY_COMMIT, args.rejectEmptyCommit);
newProject.setMaxObjectSizeLimit(args.maxObjectSizeLimit);
newProject.setBooleanConfig(BooleanProjectConfig.ENABLE_SIGNED_PUSH, args.enableSignedPush);
newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_SIGNED_PUSH, args.requireSignedPush);
if (args.newParent != null) {
newProject.setParent(args.newParent);
}
});
if (!args.ownerIds.isEmpty()) {
config.upsertAccessSection(AccessSection.ALL, all -> {
for (AccountGroup.UUID ownerId : args.ownerIds) {
GroupDescription.Basic g = groupBackend.get(ownerId);
if (g != null) {
GroupReference group = config.resolve(GroupReference.forGroup(g));
all.upsertPermission(Permission.OWNER).add(PermissionRule.builder(group));
}
}
});
}
md.setMessage("Created project\n");
config.commit(md);
md.getRepository().setGitwebDescription(args.projectDescription);
}
projectCache.onCreateProject(args.getProject());
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class PutConfig method apply.
public ConfigInfo apply(ProjectState projectState, ConfigInput input) throws ResourceNotFoundException, BadRequestException, ResourceConflictException {
Project.NameKey projectName = projectState.getNameKey();
if (input == null) {
throw new BadRequestException("config is required");
}
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(projectName)) {
ProjectConfig projectConfig = projectConfigFactory.read(md);
projectConfig.updateProject(p -> {
p.setDescription(Strings.emptyToNull(input.description));
for (BooleanProjectConfig cfg : BooleanProjectConfig.values()) {
InheritableBoolean val = BooleanProjectConfigTransformations.get(cfg, input);
if (val != null) {
p.setBooleanConfig(cfg, val);
}
}
if (input.maxObjectSizeLimit != null) {
p.setMaxObjectSizeLimit(input.maxObjectSizeLimit);
}
if (input.submitType != null) {
p.setSubmitType(input.submitType);
}
if (input.state != null) {
p.setState(input.state);
}
});
if (input.pluginConfigValues != null) {
setPluginConfigValues(projectState, projectConfig, input.pluginConfigValues);
}
if (input.commentLinks != null) {
updateCommentLinks(projectConfig, input.commentLinks);
}
md.setMessage("Modified project settings\n");
try {
projectConfig.commit(md);
projectCache.evictAndReindex(projectConfig.getProject());
md.getRepository().setGitwebDescription(projectConfig.getProject().getDescription());
} catch (IOException e) {
if (e.getCause() instanceof ConfigInvalidException) {
throw new ResourceConflictException("Cannot update " + projectName + ": " + e.getCause().getMessage());
}
logger.atWarning().withCause(e).log("Failed to update config of project %s.", projectName);
throw new ResourceConflictException("Cannot update " + projectName);
}
ProjectState state = projectStateFactory.create(projectConfigFactory.read(md).getCacheable());
return ConfigInfoCreator.constructInfo(serverEnableSignedPush, state, user.get(), pluginConfigEntries, cfgFactory, allProjects, uiActions, views);
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(projectName.get(), notFound);
} catch (ConfigInvalidException err) {
throw new ResourceConflictException("Cannot read project " + projectName, err);
} catch (IOException err) {
throw new ResourceConflictException("Cannot update project " + projectName, err);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AllUsersCreator method initAllUsers.
private void initAllUsers(Repository git) throws IOException, ConfigInvalidException {
try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage("Initialized Gerrit Code Review " + Version.getVersion());
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(p -> p.setDescription("Individual user settings and preferences."));
config.upsertAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", users -> {
grant(config, users, Permission.READ, false, true, registered);
grant(config, users, Permission.PUSH, false, true, registered);
grant(config, users, Permission.SUBMIT, false, true, registered);
grant(config, users, codeReviewLabel, -2, 2, true, registered);
});
// Initialize "Code-Review" label.
config.upsertLabelType(codeReviewLabel);
if (admin != null) {
config.upsertAccessSection(RefNames.REFS_USERS_DEFAULT, defaults -> {
defaults.upsertPermission(Permission.READ).setExclusiveGroup(true);
grant(config, defaults, Permission.READ, admin);
defaults.upsertPermission(Permission.PUSH).setExclusiveGroup(true);
grant(config, defaults, Permission.PUSH, admin);
defaults.upsertPermission(Permission.CREATE).setExclusiveGroup(true);
grant(config, defaults, Permission.CREATE, admin);
});
}
// Grant read permissions on the group branches to all users.
// This allows group owners to see the group refs. VisibleRefFilter ensures that read
// permissions for non-group-owners are ignored.
config.upsertAccessSection(RefNames.REFS_GROUPS + "*", groups -> {
grant(config, groups, Permission.READ, false, true, registered);
});
config.commit(md);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class SetLabel method apply.
@Override
public Response<LabelDefinitionInfo> apply(LabelResource rsrc, LabelDefinitionInput input) throws AuthException, BadRequestException, ResourceConflictException, PermissionBackendException, IOException, ConfigInvalidException {
if (!user.get().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
permissionBackend.currentUser().project(rsrc.getProject().getNameKey()).check(ProjectPermission.WRITE_CONFIG);
if (input == null) {
input = new LabelDefinitionInput();
}
LabelType labelType = rsrc.getLabelType();
try (MetaDataUpdate md = updateFactory.create(rsrc.getProject().getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
if (updateLabel(config, labelType, input)) {
if (input.commitMessage != null) {
md.setMessage(Strings.emptyToNull(input.commitMessage.trim()));
} else {
md.setMessage("Update label");
}
String newName = Strings.nullToEmpty(input.name).trim();
labelType = config.getLabelSections().get(newName.isEmpty() ? labelType.getName() : newName);
config.commit(md);
projectCache.evictAndReindex(rsrc.getProject().getProjectState().getProject());
}
}
return Response.ok(LabelDefinitionJson.format(rsrc.getProject().getNameKey(), labelType));
}
Aggregations