use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV1Delegate method update.
public String update(Request req, Response res) throws IOException {
Role roleFromServer = roleConfigService.findRole(req.params(":role_name"));
Role roleFromRequest = getEntityFromRequestBody(req);
if (isRenameAttempt(roleFromServer, roleFromRequest)) {
throw haltBecauseRenameOfEntityIsNotSupported("roles");
}
if (!isPutRequestFresh(req, roleFromServer)) {
throw haltBecauseEtagDoesNotMatch("role", roleFromServer.getName());
}
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.update(UserHelper.getUserName(), etagFor(roleFromServer), roleFromRequest, result);
return handleCreateOrUpdateResponse(req, res, roleFromRequest, result);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV1Delegate method create.
public String create(Request req, Response res) throws IOException {
Role role = getEntityFromRequestBody(req);
haltIfEntityBySameNameInRequestExists(req, role);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.create(UserHelper.getUserName(), role, result);
return handleCreateOrUpdateResponse(req, res, role, result);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV1Delegate method destroy.
public String destroy(Request req, Response res) throws IOException {
Role role = getEntityFromConfig(req.params("role_name"));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.delete(UserHelper.getUserName(), role, result);
return renderHTTPOperationResult(result, req, res, localizer);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV3 method create.
public String create(Request req, Response res) {
Role role = buildEntityFromRequestBody(req);
haltIfEntityBySameNameInRequestExists(req, role);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.create(SessionUtils.currentUsername(), role, result);
return handleCreateOrUpdateResponse(req, res, role, result);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RoleRepresenter method fromJSON.
public static Role fromJSON(JsonReader jsonReader) {
Role model;
String type = jsonReader.optString("type").orElse("");
if ("gocd".equals(type)) {
model = GoCDRoleConfigRepresenter.fromJSON(jsonReader.readJsonObject("attributes"));
} else if ("plugin".equals(type)) {
model = PluginRoleConfigRepresenter.fromJSON(jsonReader.readJsonObject("attributes"));
} else {
throw new JsonParseException("Invalid role type '%s'. It has to be one of 'gocd' or 'plugin'");
}
model.setName(new CaseInsensitiveString(jsonReader.optString("name").orElse(null)));
Policy directives = new Policy();
jsonReader.readArrayIfPresent("policy", policy -> {
policy.forEach(directive -> directives.add(DirectiveRepresenter.fromJSON(new JsonReader(directive.getAsJsonObject()))));
});
model.setPolicy(directives);
return model;
}
Aggregations