Search in sources :

Example 6 with InvalidRequestException

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

the class ReorderPipelinesController method handlePipelineReorder.

private void handlePipelineReorder(Map<String, Object> requestBody, ItemDAO<Pipeline> pipelineItemDAO) {
    String application = (String) requestBody.get("application");
    Map<String, Integer> idsToIndices = (Map<String, Integer>) requestBody.get("idsToIndices");
    if (application == null) {
        throw new InvalidRequestException("`application` is required field on request body");
    }
    if (idsToIndices == null) {
        throw new InvalidRequestException("`idsToIndices` is required field on request body");
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!fiatPermissionEvaluator.storeWholePermission() && !fiatPermissionEvaluator.hasPermission(auth, application, "APPLICATION", "WRITE")) {
        throw new InvalidRequestException("Application write permission is required to reorder pipelines");
    }
    for (String id : idsToIndices.keySet()) {
        Pipeline pipeline = pipelineItemDAO.findById(id);
        if (pipeline == null) {
            throw new NotFoundException(String.format("No pipeline of id %s found", id));
        }
        if (!pipeline.getApplication().equals(application)) {
            throw new InvalidRequestException(String.format("Pipeline with id %s does not belong to application %s", id, application));
        }
        pipeline.setIndex(idsToIndices.get(id));
        pipelineItemDAO.update(id, pipeline);
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Map(java.util.Map) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)

Example 7 with InvalidRequestException

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

the class StrategyController method update.

@PreAuthorize("hasPermission(#strategy.application, 'APPLICATION', 'WRITE')")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Pipeline update(@PathVariable final String id, @RequestBody final Pipeline strategy) {
    Pipeline existingStrategy = pipelineStrategyDAO.findById(id);
    if (!strategy.getId().equals(existingStrategy.getId())) {
        throw new InvalidRequestException(format("The provided id '%s' doesn't match the strategy id '%s'", id, strategy.getId()));
    }
    boolean alreadyExists = pipelineStrategyDAO.getPipelinesByApplication(strategy.getApplication()).stream().anyMatch(it -> it.getName().equalsIgnoreCase(strategy.getName()) && !it.getId().equals(id));
    if (alreadyExists) {
        throw new DuplicateEntityException(format("A strategy with name '%s' already exists in application '%s'", strategy.getName(), strategy.getApplication()));
    }
    strategy.setLastModified(System.currentTimeMillis());
    pipelineStrategyDAO.update(id, strategy);
    return strategy;
}
Also used : DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with InvalidRequestException

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

the class DeliveryController method upsertConfig.

@PreAuthorize("hasPermission(#config.application, 'APPLICATION', 'WRITE')")
@ApiOperation(value = "", notes = "Update a delivery config")
@RequestMapping(method = RequestMethod.PUT, value = "/deliveries/{id}")
Delivery upsertConfig(@PathVariable String id, @RequestBody Delivery config) {
    if (!id.equals(config.getId())) {
        throw new InvalidRequestException("URL id (" + id + ") does not match submitted id (" + config.getId() + ")");
    }
    try {
        Delivery existing = deliveryRepository.findById(id);
        config.setCreateTs(existing.getCreateTs());
    } catch (NotFoundException e) {
    // ignore because we will create config
    }
    return deliveryRepository.upsertConfig(config);
}
Also used : NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) 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)

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