Search in sources :

Example 1 with ApiSecurity

use of com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity in project halyard by spinnaker.

the class ApiSecurityEditCommand method executeThis.

@Override
protected void executeThis() {
    String currentDeployment = getCurrentDeployment();
    ApiSecurity apiSecurity = new OperationHandler<ApiSecurity>().setOperation(Daemon.getApiSecurity(currentDeployment, false)).setFailureMesssage("Failed to load API security settings.").get();
    int originalHash = apiSecurity.hashCode();
    apiSecurity.setOverrideBaseUrl(isSet(overrideBaseUrl) ? overrideBaseUrl : apiSecurity.getOverrideBaseUrl());
    apiSecurity.setCorsAccessPattern(isSet(corsAccessPattern) ? corsAccessPattern : apiSecurity.getCorsAccessPattern());
    if (originalHash == apiSecurity.hashCode()) {
        AnsiUi.failure("No changes supplied.");
        return;
    }
    new OperationHandler<Void>().setOperation(Daemon.setApiSecurity(currentDeployment, !noValidate, apiSecurity)).setFailureMesssage("Failed to edit API security settings.").setFailureMesssage("Successfully updated API security settings.").get();
}
Also used : ApiSecurity(com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with ApiSecurity

use of com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity in project halyard by spinnaker.

the class SecurityController method setApiSecurity.

@RequestMapping(value = "/api/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setApiSecurity(@PathVariable String deploymentName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawApiSecurity) {
    ApiSecurity apiSecurity = objectMapper.convertValue(rawApiSecurity, ApiSecurity.class);
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> apiSecurity.stageLocalFiles(configPath));
    builder.setSeverity(severity);
    builder.setUpdate(() -> securityService.setApiSecurity(deploymentName, apiSecurity));
    builder.setValidate(ProblemSet::new);
    if (validate) {
        builder.setValidate(() -> securityService.validateApiSecurity(deploymentName));
    }
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Edit API security settings");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ApiSecurity(com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiSecurity (com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity)2 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)1 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)1 Path (java.nio.file.Path)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1