Search in sources :

Example 1 with InvalidRequestException

use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.

the class DeliveryController method deleteConfig.

@PreAuthorize("hasPermission(#application, 'APPLICATION', 'WRITE')")
@ApiOperation(value = "", notes = "Delete a delivery config")
@RequestMapping(method = RequestMethod.DELETE, value = "/applications/{application}/deliveries/{id}")
void deleteConfig(@PathVariable String application, @PathVariable String id) {
    Delivery config = deliveryRepository.findById(id);
    if (!config.getApplication().equals(application)) {
        throw new InvalidRequestException("No config with id " + id + " found in application " + application);
    }
    deliveryRepository.delete(id);
}
Also used : InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Delivery(com.netflix.spinnaker.front50.model.delivery.Delivery) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with InvalidRequestException

use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.

the class PipelineController method update.

@PreAuthorize("hasPermission(#pipeline.application, 'APPLICATION', 'WRITE')")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Pipeline update(@PathVariable final String id, @RequestParam(value = "staleCheck", required = false, defaultValue = "false") Boolean staleCheck, @RequestBody Pipeline pipeline) {
    Pipeline existingPipeline = pipelineDAO.findById(id);
    if (!pipeline.getId().equals(existingPipeline.getId())) {
        throw new InvalidRequestException(format("The provided id %s doesn't match the pipeline id %s", pipeline.getId(), existingPipeline.getId()));
    }
    validatePipeline(pipeline, staleCheck);
    pipeline.setName(pipeline.getName().trim());
    pipeline.setLastModified(System.currentTimeMillis());
    pipeline = ensureCronTriggersHaveIdentifier(pipeline);
    pipelineDAO.update(id, pipeline);
    return pipeline;
}
Also used : InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with InvalidRequestException

use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.

the class PipelineTemplateController method update.

@RequestMapping(value = "{id}", method = RequestMethod.PUT)
PipelineTemplate update(@PathVariable String id, @RequestBody PipelineTemplate pipelineTemplate) {
    PipelineTemplate existingPipelineTemplate = getPipelineTemplateDAO().findById(id);
    if (!pipelineTemplate.getId().equals(existingPipelineTemplate.getId())) {
        throw new InvalidRequestException("The provided id " + id + " doesn't match the pipeline template id " + pipelineTemplate.getId());
    }
    pipelineTemplate.setLastModified(System.currentTimeMillis());
    getPipelineTemplateDAO().update(id, pipelineTemplate);
    return pipelineTemplate;
}
Also used : InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) PipelineTemplate(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with InvalidRequestException

use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.

the class V2PipelineTemplateController method computeSHA256Digest.

@VisibleForTesting
public String computeSHA256Digest(PipelineTemplate pipelineTemplate) {
    Map<String, Object> sortedMap = (Map<String, Object>) sortObjectRecursive(pipelineTemplate);
    try {
        String jsonPayload = objectMapper.writeValueAsString(sortedMap).replaceAll("\\s+", "");
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hashBytes = digest.digest(jsonPayload.getBytes(StandardCharsets.UTF_8));
        return Hex.encodeHexString(hashBytes);
    } catch (NoSuchAlgorithmException | JsonProcessingException e) {
        throw new InvalidRequestException(String.format("Computing digest for pipeline template %s failed. Nested exception is %s", pipelineTemplate.undecoratedId(), e));
    }
}
Also used : InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) Map(java.util.Map) TreeMap(java.util.TreeMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with InvalidRequestException

use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.

the class ProjectsController method put.

@ApiOperation(value = "", notes = "Update an existing project")
@RequestMapping(method = RequestMethod.PUT, value = "/{projectId}")
public Project put(@PathVariable final String projectId, @RequestBody final Project project) {
    Project existingProject = projectDAO.findById(projectId);
    project.setId(existingProject.getId());
    project.setCreateTs(existingProject.getCreateTs());
    project.setUpdateTs(System.currentTimeMillis());
    try {
        if (!projectDAO.findByName(project.getName()).getId().equals(projectId)) {
            // renamed projects must still be uniquely named
            throw new InvalidRequestException(format("A Project named '%s' already exists", project.getName()));
        }
    } catch (NotFoundException ignored) {
    }
    projectDAO.update(projectId, project);
    return project;
}
Also used : Project(com.netflix.spinnaker.front50.model.project.Project) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)3 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Delivery (com.netflix.spinnaker.front50.model.delivery.Delivery)2 Map (java.util.Map)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DuplicateEntityException (com.netflix.spinnaker.front50.exceptions.DuplicateEntityException)1 PipelineTemplate (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate)1 Project (com.netflix.spinnaker.front50.model.project.Project)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 TreeMap (java.util.TreeMap)1 Authentication (org.springframework.security.core.Authentication)1