Search in sources :

Example 1 with Type

use of com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type in project front50 by spinnaker.

the class NotificationController method listByApplication.

@PostAuthorize("hasPermission(#name, 'APPLICATION', 'READ')")
@RequestMapping(value = "{type}/{name}", method = RequestMethod.GET)
public Notification listByApplication(@PathVariable(value = "type") String type, @PathVariable(value = "name") String name) {
    HierarchicalLevel level = getLevel(type);
    final Notification notification = notificationDAO.get(level, name);
    if (level.equals(HierarchicalLevel.APPLICATION)) {
        final Object global = getGlobal();
        NotificationDAO.NOTIFICATION_FORMATS.forEach(it -> {
            if (UntypedUtils.hasProperty(global, it)) {
                if (!UntypedUtils.hasProperty(notification, it)) {
                    UntypedUtils.setProperty(notification, it, new ArrayList<>());
                }
                ((List) UntypedUtils.getProperty(notification, it)).addAll((List) UntypedUtils.getProperty(global, it));
            }
        });
    }
    return notification;
}
Also used : HierarchicalLevel(com.netflix.spinnaker.front50.model.notification.HierarchicalLevel) ArrayList(java.util.ArrayList) List(java.util.List) Notification(com.netflix.spinnaker.front50.model.notification.Notification) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize)

Example 2 with Type

use of com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type in project front50 by spinnaker.

the class NotificationController method delete.

@PreAuthorize("@fiatPermissionEvaluator.storeWholePermission() and hasPermission(#name, 'APPLICATION', 'WRITE')")
@RequestMapping(value = "{type}/{name}", method = RequestMethod.DELETE)
public void delete(@PathVariable(value = "type") String type, @PathVariable(value = "name") String name) {
    HierarchicalLevel level = getLevel(type);
    notificationDAO.delete(level, name);
}
Also used : HierarchicalLevel(com.netflix.spinnaker.front50.model.notification.HierarchicalLevel) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with Type

use of com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type in project front50 by spinnaker.

the class PipelineController method validatePipeline.

/**
 * Ensure basic validity of the pipeline. Invalid pipelines will raise runtime exceptions.
 *
 * @param pipeline The Pipeline to validate
 */
private void validatePipeline(final Pipeline pipeline, Boolean staleCheck) {
    // Pipelines must have an application and a name
    if (StringUtils.isAnyBlank(pipeline.getApplication(), pipeline.getName())) {
        throw new InvalidEntityException("A pipeline requires name and application fields");
    }
    // Check if pipeline type is templated
    if (TYPE_TEMPLATED.equals(pipeline.getType())) {
        PipelineTemplateDAO templateDAO = getTemplateDAO();
        // Check templated pipelines to ensure template is valid
        String source;
        switch(pipeline.getSchema()) {
            case "v2":
                V2TemplateConfiguration v2Config = objectMapper.convertValue(pipeline, V2TemplateConfiguration.class);
                source = v2Config.getTemplate().getReference();
                break;
            default:
                TemplateConfiguration v1Config = objectMapper.convertValue(pipeline.getConfig(), TemplateConfiguration.class);
                source = v1Config.getPipeline().getTemplate().getSource();
                break;
        }
        // Check if template id which is after :// is in the store
        if (source.startsWith(SPINNAKER_PREFIX)) {
            String templateId = source.substring(SPINNAKER_PREFIX.length());
            try {
                templateDAO.findById(templateId);
            } catch (NotFoundException notFoundEx) {
                throw new BadRequestException("Configured pipeline template not found", notFoundEx);
            }
        }
    }
    checkForDuplicatePipeline(pipeline.getApplication(), pipeline.getName().trim(), pipeline.getId());
    final ValidatorErrors errors = new ValidatorErrors();
    pipelineValidators.forEach(it -> it.validate(pipeline, errors));
    if (staleCheck && !Strings.isNullOrEmpty(pipeline.getId()) && pipeline.getLastModified() != null) {
        checkForStalePipeline(pipeline, errors);
    }
    if (errors.hasErrors()) {
        String message = errors.getAllErrorsMessage();
        throw new ValidationException(message, errors.getAllErrors());
    }
}
Also used : ValidationException(com.netflix.spinnaker.kork.web.exceptions.ValidationException) PipelineTemplateDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) V2TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) ValidatorErrors(com.netflix.spinnaker.front50.api.validator.ValidatorErrors) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) V2TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration)

Aggregations

HierarchicalLevel (com.netflix.spinnaker.front50.model.notification.HierarchicalLevel)2 ValidatorErrors (com.netflix.spinnaker.front50.api.validator.ValidatorErrors)1 BadRequestException (com.netflix.spinnaker.front50.exception.BadRequestException)1 InvalidEntityException (com.netflix.spinnaker.front50.exceptions.InvalidEntityException)1 Notification (com.netflix.spinnaker.front50.model.notification.Notification)1 PipelineTemplateDAO (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO)1 TemplateConfiguration (com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration)1 V2TemplateConfiguration (com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration)1 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)1 ValidationException (com.netflix.spinnaker.kork.web.exceptions.ValidationException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PostAuthorize (org.springframework.security.access.prepost.PostAuthorize)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1