Search in sources :

Example 6 with Role

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);
}
Also used : Role(com.thoughtworks.go.config.Role) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 7 with Role

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);
}
Also used : Role(com.thoughtworks.go.config.Role) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 8 with Role

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);
}
Also used : Role(com.thoughtworks.go.config.Role) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 9 with Role

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);
}
Also used : Role(com.thoughtworks.go.config.Role) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 10 with Role

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;
}
Also used : Role(com.thoughtworks.go.config.Role) Policy(com.thoughtworks.go.config.policy.Policy) JsonReader(com.thoughtworks.go.api.representers.JsonReader) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JsonParseException(com.google.gson.JsonParseException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

Role (com.thoughtworks.go.config.Role)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 JsonParseException (com.google.gson.JsonParseException)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 Policy (com.thoughtworks.go.config.policy.Policy)1