Search in sources :

Example 1 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationController method updateImage.

/**
 * Update application's image.
 *
 * @param applicationId The application id.
 * @param image new image of the application
 * @return nothing if success, error will be handled in global exception strategy
 */
@ApiOperation(value = "Updates the image for the application.", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/image", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<String> updateImage(@PathVariable String applicationId, @RequestParam("file") MultipartFile image) {
    Application application = applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    String imageId;
    try {
        imageId = imageDAO.writeImage(image.getBytes());
    } catch (IOException e) {
        throw new ImageUploadException("Unable to read image from file upload [" + image.getOriginalFilename() + "] to update application [" + applicationId + "]", e);
    }
    application.setImageId(imageId);
    alienDAO.save(application);
    return RestResponseBuilder.<String>builder().data(imageId).build();
}
Also used : ImageUploadException(alien4cloud.images.exception.ImageUploadException) IOException(java.io.IOException) Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method launchWorkflow.

@ApiOperation(value = "Launch a given workflow.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/workflows/{workflowName}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "credentials" })
public DeferredResult<RestResponse<Void>> launchWorkflow(@ApiParam(value = "Application id.", required = true) @Valid @NotBlank @PathVariable String applicationId, @ApiParam(value = "Deployment id.", required = true) @Valid @NotBlank @PathVariable String applicationEnvironmentId, @ApiParam(value = "Workflow name.", required = true) @Valid @NotBlank @PathVariable String workflowName, @ApiParam(value = "The secret provider configuration and credentials.") @RequestBody(required = false) SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
    final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
    ApplicationEnvironment environment = getAppEnvironmentAndCheckAuthorization(applicationId, applicationEnvironmentId);
    // TODO merge with incoming params
    Map<String, Object> params = Maps.newHashMap();
    try {
        workflowExecutionService.launchWorkflow(secretProviderConfigurationAndCredentials, environment.getId(), workflowName, params, new IPaaSCallback<Object>() {

            @Override
            public void onSuccess(Object data) {
                result.setResult(RestResponseBuilder.<Void>builder().build());
            }

            @Override
            public void onFailure(Throwable e) {
                result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.RUNTIME_WORKFLOW_ERROR.getCode(), e.getMessage())).build());
            }
        });
    } catch (OrchestratorDisabledException e) {
        result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
    } catch (PaaSDeploymentException e) {
        result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.SCALING_ERROR.getCode(), e.getMessage())).build());
    }
    return result;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestError(alien4cloud.rest.model.RestError) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method scale.

/**
 * Scale an application on a particular node.
 *
 * @param applicationId The id of the application to be scaled.
 * @param nodeTemplateId The id of the node template to be scaled.
 * @param instances The instances number to be scaled up (if > 0)/ down (if < 0)
 * @return A {@link RestResponse} that contains the application's current {@link DeploymentStatus}.
 */
@ApiOperation(value = "Scale the application on a particular node.", notes = "Returns the detailed informations of the application on the PaaS it is deployed." + " Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/scale/{nodeTemplateId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "credentials" })
public DeferredResult<RestResponse<Void>> scale(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @PathVariable String nodeTemplateId, @RequestParam int instances, @ApiParam(value = "The secret provider configuration ans credentials.") @RequestBody SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
    final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
    ApplicationEnvironment environment = getAppEnvironmentAndCheckAuthorization(applicationId, applicationEnvironmentId);
    try {
        deploymentRuntimeService.scale(secretProviderConfigurationAndCredentials, environment.getId(), nodeTemplateId, instances, new IPaaSCallback<Object>() {

            @Override
            public void onSuccess(Object data) {
                result.setResult(RestResponseBuilder.<Void>builder().build());
            }

            @Override
            public void onFailure(Throwable e) {
                result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.SCALING_ERROR.getCode(), e.getMessage())).build());
            }
        });
    } catch (OrchestratorDisabledException e) {
        result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
    } catch (PaaSDeploymentException e) {
        result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.SCALING_ERROR.getCode(), e.getMessage())).build());
    }
    return result;
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestResponse(alien4cloud.rest.model.RestResponse) RestError(alien4cloud.rest.model.RestError) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method create.

/**
 * Create the application environment for an application
 *
 * @param request data to create an application environment
 * @return application environment id
 */
@ApiOperation(value = "Create a new application environment", notes = "If successfull returns a rest response with the id of the created application environment in data. If not successful a rest response with an error content is returned. Role required [ APPLICATIONS_MANAGER ]" + "By default the application environment creator will have application roles [ APPLICATION_MANAGER, DEPLOYMENT_MANAGER ]")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<String> create(@PathVariable String applicationId, @RequestBody ApplicationEnvironmentRequest request) throws OrchestratorDisabledException {
    // User should be APPLICATION_MANAGER to create an environment
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    ApplicationEnvironment appEnvironment = applicationEnvironmentService.createApplicationEnvironment(auth.getName(), applicationId, request.getName(), request.getDescription(), request.getEnvironmentType(), request.getVersionId());
    alienDAO.save(appEnvironment);
    if (StringUtils.isNotBlank(request.getInputCandidate())) {
        // Client ask to copy inputs from other environment
        ApplicationEnvironment environmentToCopyInputs = applicationEnvironmentService.checkAndGetApplicationEnvironment(request.getInputCandidate(), ApplicationRole.APPLICATION_MANAGER);
        applicationEnvironmentService.synchronizeEnvironmentInputs(environmentToCopyInputs, appEnvironment);
    }
    return RestResponseBuilder.<String>builder().data(appEnvironment.getId()).build();
}
Also used : Authentication(org.springframework.security.core.Authentication) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentRolesController method removeGroupRole.

/**
 * Remove a role from a group on a specific application environment
 *
 * @param applicationEnvironmentId application environment id
 * @param groupId The id of the group to update roles
 * @param role The role to add to the user on the application environment
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Remove a role of a group on a specific application environment", notes = "Any user with application role APPLICATION_MANAGER can un-assign any role to a group. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/groups/{groupId}/{role}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> removeGroupRole(@PathVariable String applicationEnvironmentId, @PathVariable String groupId, @PathVariable String role) {
    ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
    resourceRoleService.removeGroupRole(applicationEnvironment, groupId, role);
    handleRemoveGrpRoleOnApplication(applicationEnvironment.getApplicationId(), groupId);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Audit (alien4cloud.audit.annotation.Audit)71 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)69 ApiOperation (io.swagger.annotations.ApiOperation)67 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)63 Application (alien4cloud.model.application.Application)27 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)24 Location (alien4cloud.model.orchestrators.locations.Location)15 List (java.util.List)15 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)11 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)11 RestResponse (alien4cloud.rest.model.RestResponse)10 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)9 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)7 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)7 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)7 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)7 Subject (alien4cloud.security.Subject)7