use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline 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;
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline 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));
}
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class SharedManagedServiceAccountsMigration method migrate.
private void migrate(Pipeline pipeline, Map<String, ServiceAccount> serviceAccounts) {
log.info("Starting migration of pipeline '{}' with id '{}' for application '{}'", value("pipelineName", pipeline.getName()), value("application", pipeline.getApplication()), value("pipelineId", pipeline.getId()));
Set<String> newRoles = new HashSet<>();
List<String> existingRoles = (List) pipeline.getRoles();
if (existingRoles != null) {
existingRoles.stream().map(String::toLowerCase).forEach(newRoles::add);
}
List<Trigger> triggers = pipeline.getTriggers();
triggers.forEach(trigger -> {
String runAsUser = (String) trigger.get(RUN_AS_USER);
if (hasManagedServiceAccountUser(runAsUser)) {
ServiceAccount managedServiceAccount = serviceAccounts.get(runAsUser);
if (managedServiceAccount != null && !managedServiceAccount.getMemberOf().isEmpty()) {
managedServiceAccount.getMemberOf().stream().map(String::toLowerCase).forEach(newRoles::add);
}
}
});
String sharedManagedServiceAccountName = generatedSharedManagedServiceAccountName(newRoles);
ServiceAccount sharedManagedServiceAccount = new ServiceAccount();
sharedManagedServiceAccount.setName(sharedManagedServiceAccountName);
triggers.forEach(trigger -> {
String runAsUser = (String) trigger.get(RUN_AS_USER);
log.info("Replacing '{}' with automatic service user '{}' (application: '{}', pipelineName: '{}', " + "pipelineId: '{}')", value("oldServiceUser", runAsUser), value("newServiceUser", sharedManagedServiceAccountName), value("application", pipeline.getApplication()), value("pipelineName", pipeline.getName()), value("pipelineId", pipeline.getId()));
trigger.put(RUN_AS_USER, sharedManagedServiceAccountName);
});
log.info("Creating service user '{}' wih roles {}", sharedManagedServiceAccountName, newRoles);
sharedManagedServiceAccount.getMemberOf().addAll(newRoles);
pipeline.setRoles(new ArrayList(newRoles));
pipeline.setTriggers(triggers);
serviceAccountDAO.create(sharedManagedServiceAccount.getId(), sharedManagedServiceAccount);
pipelineDAO.update(pipeline.getId(), pipeline);
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class SpelLoadBalancersMigration method run.
public void run() {
log.info("Starting spelLoadBalancers migration");
Collection<Pipeline> pipelines = pipelineDAO.all();
int migratedCount = 0;
int failureCount = 0;
for (Pipeline pipeline : pipelines) {
try {
if (migrate(pipeline)) {
migratedCount++;
}
} catch (Exception e) {
log.error("Failed to migrate pipeline {} ({}) for {} spelLoadBalancersMigration", pipeline.getName(), pipeline.getId(), pipeline.getApplication(), e);
failureCount++;
}
}
log.info("Done with spelLoadBalancers migration (migrated {} pipelines; {} failed to migrate)", migratedCount, failureCount);
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline 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);
}
}
Aggregations