Search in sources :

Example 1 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigsControllerV3 method create.

public String create(Request request, Response response) {
    final SecretConfig secretConfigToCreate = buildEntityFromRequestBody(request);
    haltIfEntityWithSameIdExists(secretConfigToCreate);
    final HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    configService.create(currentUsername(), secretConfigToCreate, operationResult);
    return handleCreateOrUpdateResponse(request, response, secretConfigToCreate, operationResult);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig)

Example 2 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigsControllerV3 method update.

public String update(Request request, Response response) {
    String configId = request.params(CONFIG_ID_PARAM);
    SecretConfig oldSecretConfig = fetchEntityFromConfig(configId);
    SecretConfig newSecretConfig = buildEntityFromRequestBody(request);
    if (isRenameAttempt(oldSecretConfig.getId(), newSecretConfig.getId())) {
        throw haltBecauseRenameOfEntityIsNotSupported(getEntityType().getEntityNameLowerCase());
    }
    if (isPutRequestStale(request, oldSecretConfig)) {
        throw haltBecauseEtagDoesNotMatch();
    }
    final HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    configService.update(currentUsername(), etagFor(newSecretConfig), newSecretConfig, operationResult);
    return handleCreateOrUpdateResponse(request, response, newSecretConfig, operationResult);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig)

Example 3 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigUpdateCommand method isRequestFresh.

private boolean isRequestFresh(CruiseConfig cruiseConfig) {
    SecretConfig existingSecretConfig = findExistingProfile(cruiseConfig);
    boolean freshRequest = hashingService.hashForEntity(existingSecretConfig).equals(md5);
    if (!freshRequest) {
        result.stale(getObjectDescriptor().staleConfig(existingSecretConfig.getId()));
    }
    return freshRequest;
}
Also used : SecretConfig(com.thoughtworks.go.config.SecretConfig)

Example 4 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class RuleAwarePluginProfileCommandTest method shouldNotContinueWithConfigSaveIfUserIsUnauthorized.

@Test
public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() throws Exception {
    SecretConfig securityAuthConfig = new SecretConfig("ldap", "cd.go.ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RuleAwarePluginProfileCommand command = new StubSecretConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.message(), equalTo("Unauthorized to edit."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Example 5 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class RuleAwarePluginProfileCommandTest method shouldContinueWithConfigSaveIfUserIsAdmin.

@Test
public void shouldContinueWithConfigSaveIfUserIsAdmin() throws Exception {
    SecretConfig securityAuthConfig = new SecretConfig("ldap", "cd.go.ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RuleAwarePluginProfileCommand command = new StubSecretConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("ldap"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SecretConfig (com.thoughtworks.go.config.SecretConfig)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 Test (org.junit.jupiter.api.Test)13 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)2 SecretConfigs (com.thoughtworks.go.config.SecretConfigs)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 SecretConfigUsage (com.thoughtworks.go.domain.SecretConfigUsage)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 EntityHashingService (com.thoughtworks.go.server.service.EntityHashingService)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HashSet (java.util.HashSet)1