Search in sources :

Example 6 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class EntityTagsController method tag.

@RequestMapping(value = "/**", method = RequestMethod.GET)
public EntityTags tag(HttpServletRequest request) {
    String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    final String searchTerm = new AntPathMatcher().extractPathWithinPattern(pattern, request.getServletPath());
    return taggedEntityDAO.map(it -> it.findById(searchTerm)).orElseThrow(() -> new NotFoundException(format("No tags found for '%s'", searchTerm)));
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoggerFactory(org.slf4j.LoggerFactory) EntityTags(com.netflix.spinnaker.front50.model.tag.EntityTags) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Strings(com.google.common.base.Strings) HttpStatus(org.springframework.http.HttpStatus) HttpServletRequest(javax.servlet.http.HttpServletRequest) HandlerMapping(org.springframework.web.servlet.HandlerMapping) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) EntityTagsDAO(com.netflix.spinnaker.front50.model.tag.EntityTagsDAO) AntPathMatcher(org.springframework.util.AntPathMatcher) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 7 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException 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)

Example 8 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project fiat by spinnaker.

the class AuthorizeController method getUserAuthorization.

@RequestMapping(value = "/{userId:.+}/{resourceType:.+}/{resourceName:.+}/{authorization:.+}", method = RequestMethod.GET)
public void getUserAuthorization(@PathVariable String userId, @PathVariable String resourceType, @PathVariable String resourceName, @PathVariable String authorization, HttpServletResponse response) throws IOException {
    Authorization a = Authorization.valueOf(authorization.toUpperCase());
    ResourceType r = ResourceType.parse(resourceType);
    Set<Authorization> authorizations = new HashSet<>(0);
    try {
        if (r.equals(ResourceType.ACCOUNT)) {
            authorizations = getUserAccount(userId, resourceName).getAuthorizations();
        } else if (r.equals(ResourceType.APPLICATION)) {
            authorizations = getUserApplication(userId, resourceName).getAuthorizations();
        } else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Resource type " + resourceType + " does not contain authorizations");
            return;
        }
    } catch (NotFoundException nfe) {
    // Ignore. Will return 404 below.
    }
    if (authorizations.contains(a)) {
        response.setStatus(HttpServletResponse.SC_OK);
        return;
    }
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
Also used : Authorization(com.netflix.spinnaker.fiat.model.Authorization) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Example 9 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class ApplicationPermissionsService method update.

private Permission update(@Nonnull String appName, @Nonnull Permission newPermission) {
    try {
        Permission oldPerm = applicationPermissionDAO().findById(appName);
        applicationPermissionDAO().update(appName, newPermission);
        syncUsers(newPermission, oldPerm);
    } catch (NotFoundException e) {
        createApplicationPermission(newPermission);
    }
    return newPermission;
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Example 10 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class PluginInfoService method upsertRelease.

/**
 * Updates (not upserts) a release. Releases are effectively immutable, but this method can be
 * used to fixup data
 */
public PluginInfo upsertRelease(@Nonnull String id, @Nonnull PluginInfo.Release release) {
    release.setLastModifiedBy(AuthenticatedRequest.getSpinnakerUser().orElse("anonymous"));
    release.setLastModified(Instant.now());
    PluginInfo pluginInfo = repository.findById(id);
    PluginInfo.Release existingRelease = pluginInfo.getReleaseByVersion(release.getVersion()).orElseThrow(() -> new NotFoundException(String.format("Plugin %s with release %s version not found. ", id, release.getVersion())));
    pluginInfo.getReleases().remove(existingRelease);
    pluginInfo.getReleases().add(release);
    if (release.isPreferred()) {
        preferRelease(pluginInfo, release);
    }
    return savePluginInfo(pluginInfo);
}
Also used : NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Aggregations

NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)15 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Timestamped (com.netflix.spinnaker.front50.api.model.Timestamped)4 StructuredArguments.value (net.logstash.logback.argument.StructuredArguments.value)4 Lists (com.google.common.collect.Lists)3 Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)3 InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)3 AuthenticatedRequest (com.netflix.spinnaker.security.AuthenticatedRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Counter (com.netflix.spectator.api.Counter)2 Registry (com.netflix.spectator.api.Registry)2 Timer (com.netflix.spectator.api.Timer)2 BadRequestException (com.netflix.spinnaker.front50.exception.BadRequestException)2 PipelineMixins (com.netflix.spinnaker.front50.jackson.mixins.PipelineMixins)2 TimestampedMixins (com.netflix.spinnaker.front50.jackson.mixins.TimestampedMixins)2 User (com.netflix.spinnaker.security.User)2 CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)2