private void haltIfEntityWithSameIdExists(ConfigRepoConfig repo) { String id = repo.getId(); if (doFetchEntityFromConfig(id) == null) { return; } repo.addError("id", "ConfigRepo ids should be unique. A ConfigRepo with the same id already exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(repo), "config-repo", id); } }
static TriState toTriState(String agentConfigState) { if (StringUtils.isBlank(agentConfigState)) { return TriState.UNSET; } else if (StringUtils.equalsIgnoreCase(agentConfigState, "enabled")) { return TriState.TRUE; } else if (StringUtils.equalsIgnoreCase(agentConfigState, "disabled")) { return TriState.FALSE; } else { throw HaltApiResponses.haltBecauseOfReason("The value of `agent_config_state` can be one of `Enabled`, `Disabled` or null."); } } }
private ConfigRepoConfig repoFromRequest(Request req) { String repoId = req.queryParams("repoId"); if (null == repoId) { return null; } ConfigRepoConfig repo = service.getConfigRepo(repoId); if (null == repo) { throw HaltApiResponses.haltBecauseNotFound("Could not find a config-repo with id `%s`", repoId); } return repo; } }
public String update(Request req, Response res) { Role roleFromServer = roleConfigService.findRole(req.params(":role_name")); Role roleFromRequest = buildEntityFromRequestBody(req); if (isRenameAttempt(roleFromServer, roleFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("roles"); } if (isPutRequestStale(req, roleFromServer)) { throw haltBecauseEtagDoesNotMatch("role", roleFromServer.getName()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); roleConfigService.update(SessionUtils.currentUsername(), etagFor(roleFromServer), roleFromRequest, result); return handleCreateOrUpdateResponse(req, res, roleFromRequest, result); }
public String update(Request request, Response response) { String fromCookie = request.cookie(COOKIE_NAME); final Long userId = currentUserId(request); if (!Objects.equals(pipelineSelectionsService.load(fromCookie, userId).etag(), getIfMatch(request))) { throw HaltApiResponses.haltBecauseEtagDoesNotMatch(DATA_IS_OUT_OF_DATE); } Filters filters; try { filters = Filters.fromJson(request.body()); } catch (FilterValidationException | JsonParseException e) { throw HaltApiResponses.haltBecauseOfReason(e.getMessage()); } Long recordId = pipelineSelectionsService.save(fromCookie, userId, filters); if (!apiAuthenticationHelper.securityEnabled()) { response.cookie("/go", COOKIE_NAME, String.valueOf(recordId), ONE_YEAR, systemEnvironment.isSessionCookieSecure(), true); } response.status(OK); return format("{ \"contentHash\": \"%s\" }", pipelineSelectionsService.load(fromCookie, userId).etag()); }
String updateRepo(Request req, Response res) { String id = req.params(":id"); ConfigRepoConfig repoFromConfig = fetchEntityFromConfig(id); ConfigRepoConfig repoFromRequest = buildEntityFromRequestBody(req); if (isPutRequestStale(req, repoFromConfig)) { throw haltBecauseEtagDoesNotMatch(); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.updateConfigRepo(id, repoFromRequest, etagFor(repoFromConfig), currentUsername(), result); return handleCreateOrUpdateResponse(req, res, repoFromRequest, result); }
public String patchUser(Request req, Response res) throws Exception { String username = req.params("login_name"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); User userFromRequest = buildUserEntityFromRequestBody(req, true); User existingUser = userService.findUserByName(username); if (existingUser.equals(new NullUser())) { throw haltBecauseNotFound(); } if (isRenameAttempted(req, userFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("User"); } return saveUserAndRenderResult(req, res, result, existingUser, userFromRequest, username); }
throw HaltApiResponses.haltBecauseNotFound(e.getMessage()); } catch (InvalidPartialConfigException e) { result.update(Collections.singletonList(e.getErrors()), false); result.update(e.getAllErrors(), false); } catch (Exception e) { throw HaltApiResponses.haltBecauseOfReason(e.getMessage());
private String requiredQueryParam(final Request req, final String name) { String value = req.queryParams(name); if (StringUtils.isBlank(value)) { throw HaltApiResponses.haltBecauseRequiredParamMissing(name); } return value; } }
public String update(Request req, Response res) { ArtifactStore artifactStoreFromServer = fetchEntityFromConfig(req.params(ID_PARAM)); ArtifactStore artifactStoreFromRequest = buildEntityFromRequestBody(req); if (isRenameAttempt(artifactStoreFromServer, artifactStoreFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("artifactStore"); } if (isPutRequestStale(req, artifactStoreFromServer)) { throw haltBecauseEtagDoesNotMatch("artifactStore", artifactStoreFromServer.getId()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); artifactStoreService.update(currentUsername(), etagFor(artifactStoreFromServer), artifactStoreFromRequest, result); return handleCreateOrUpdateResponse(req, res, artifactStoreFromRequest, result); }
public String update(Request req, Response res) { AdminsConfig adminsConfigFromRequest = buildEntityFromRequestBody(req); AdminsConfig adminsConfigFromServer = adminsConfigService.systemAdmins(); if (isPutRequestStale(req, adminsConfigFromServer)) { throw haltBecauseEtagDoesNotMatch(); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); adminsConfigService.update(currentUsername(), adminsConfigFromRequest, etagFor(adminsConfigFromServer), result); return handleCreateOrUpdateResponse(req, res, adminsConfigFromRequest, result); }
private String requiredParam(final Request req, final String name) { String value = req.params(name); if (StringUtils.isBlank(value)) { throw HaltApiResponses.haltBecauseRequiredParamMissing(name); } return value; }
public String update(Request req, Response res) { PipelineTemplateConfig existingTemplateConfig = fetchEntityFromConfig(req.params("template_name")); PipelineTemplateConfig templateConfigFromRequest = buildEntityFromRequestBody(req); if (isRenameAttempt(existingTemplateConfig, templateConfigFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("templates"); } if (isPutRequestStale(req, existingTemplateConfig)) { throw haltBecauseEtagDoesNotMatch("template", existingTemplateConfig.name()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); templateConfigService.updateTemplateConfig(SessionUtils.currentUsername(), templateConfigFromRequest, result, etagFor(existingTemplateConfig)); return handleCreateOrUpdateResponse(req, res, templateConfigFromRequest, result); }
private void haltIfEntityWithSameIdExists(ElasticProfile elasticProfile) { if (elasticProfileService.findProfile(elasticProfile.getId()) == null) { return; } elasticProfile.addError("id", format("Elastic profile ids should be unique. Elastic profile with id '%s' already exists.", elasticProfile.getId())); throw haltBecauseEntityAlreadyExists(jsonWriter(elasticProfile), "elasticProfile", elasticProfile.getId()); } }
public String update(Request req, Response res) { AdminsConfig adminsConfigFromRequest = buildEntityFromRequestBody(req); AdminsConfig adminsConfigFromServer = adminsConfigService.systemAdmins(); if (isPutRequestStale(req, adminsConfigFromServer)) { throw haltBecauseEtagDoesNotMatch(); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); adminsConfigService.update(currentUsername(), adminsConfigFromRequest, etagFor(adminsConfigFromServer), result); return handleCreateOrUpdateResponse(req, res, adminsConfigFromRequest, result); }
private void haltIfPipelineIsDefinedRemotely(PipelineConfig existingPipelineConfig) { if (!existingPipelineConfig.isLocal()) { throw haltBecauseOfReason(String.format("Can not operate on pipeline '%s' as it is defined remotely in '%s'.", existingPipelineConfig.name(), existingPipelineConfig.getOrigin().displayName())); } }
private ConfigRepoConfig repoFromRequest(Request req) { ConfigRepoConfig repo = service.getConfigRepo(req.params(":id")); if (null == repo) { throw HaltApiResponses.haltBecauseNotFound(); } return repo; }
private ConfigRepoPlugin pluginFromRequest(Request req) { String pluginId = req.queryParams("pluginId"); if (StringUtils.isBlank(pluginId)) { throw HaltApiResponses.haltBecauseRequiredParamMissing("pluginId"); } return (ConfigRepoPlugin) pluginService.partialConfigProviderFor(pluginId); }
public String update(Request req, Response res) { PipelineConfigs pipelineConfigsFromServer = fetchEntityFromConfig(req.params("group_name")); PipelineConfigs pipelineConfigsFromReq = buildEntityFromRequestBody(req); if (isRenameAttempt(pipelineConfigsFromServer, pipelineConfigsFromReq)) { throw haltBecauseRenameOfEntityIsNotSupported("pipeline group"); } if (isPutRequestStale(req, pipelineConfigsFromServer)) { throw haltBecauseEtagDoesNotMatch("pipeline group", pipelineConfigsFromServer.getGroup()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); PipelineConfigs updatedPipelineConfigs = pipelineConfigsService.updateGroupAuthorization(SessionUtils.currentUsername(), pipelineConfigsFromReq, etagFor(pipelineConfigsFromServer), entityHashingService, securityService, result); return handleCreateOrUpdateResponse(req, res, updatedPipelineConfigs, result); }
private void haltIfEntityWithSameIdExists(ArtifactStore artifactStore) { if (artifactStoreService.findArtifactStore(artifactStore.getId()) == null) { return; } artifactStore.addError("id", "Artifact store ids should be unique. Artifact store with the same id exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(artifactStore), "artifactStore", artifactStore.getId()); } }