Search in sources :

Example 1 with PipelineTemplate

use of com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate 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 2 with PipelineTemplate

use of com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate in project front50 by spinnaker.

the class V2PipelineTemplateController method get.

@RequestMapping(value = "{id}", method = RequestMethod.GET)
PipelineTemplate get(@PathVariable String id, @RequestParam(value = "tag", required = false) String tag, @RequestParam(value = "digest", required = false) String digest) {
    String templateId = formatId(id, tag, digest);
    // We don't need to surface our internal accounting information to the user.
    // This would muddle the API and probably be bug-friendly.
    PipelineTemplate foundTemplate = getPipelineTemplateDAO().findById(templateId);
    foundTemplate.remove("digest");
    foundTemplate.remove("tag");
    return foundTemplate;
}
Also used : PipelineTemplate(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PipelineTemplate

use of com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate 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)

Aggregations

InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)2 PipelineTemplate (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1