Search in sources :

Example 16 with SecretConfig

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

the class SecretConfigDeleteCommand method update.

@Override
public void update(CruiseConfig preprocessedConfig) {
    SecretConfig configToBeDeleted = findExistingProfile(preprocessedConfig);
    getPluginProfiles(preprocessedConfig).remove(configToBeDeleted);
}
Also used : SecretConfig(com.thoughtworks.go.config.SecretConfig)

Example 17 with SecretConfig

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

the class SecretConfigCreateCommandTest method shouldInvokePluginValidations.

@Test
public void shouldInvokePluginValidations() throws Exception {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "error"));
    SecretConfig newSecretConfig = new SecretConfig("foo", "file", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
    RuleAwarePluginProfileCommand command = new SecretConfigCreateCommand(mock(GoConfigService.class), newSecretConfig, extension, null, new HttpLocalizedOperationResult());
    when(extension.validateSecretsConfig(eq("file"), anyMap())).thenReturn(validationResult);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(RecordNotFoundException.class).hasMessageContaining(EntityType.SecretConfig.notFoundMessage(newSecretConfig.getId()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) SecretConfig(com.thoughtworks.go.config.SecretConfig) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Example 18 with SecretConfig

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

the class SecretConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    SecretConfig oldConfig = new SecretConfig("foo", "docker");
    SecretConfig newConfig = new SecretConfig("foo", "aws");
    cruiseConfig.getSecretConfigs().add(oldConfig);
    EntityHashingService entityHashingService = mock(EntityHashingService.class);
    when(entityHashingService.hashForEntity(oldConfig)).thenReturn("digest");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecretConfigUpdateCommand command = new SecretConfigUpdateCommand(goConfigService, newConfig, null, currentUser, result, entityHashingService, "bad-digest");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("Someone has modified the configuration for"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) Test(org.junit.jupiter.api.Test)

Example 19 with SecretConfig

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

the class SecretConfigUpdateCommandTest method shouldUpdateExistingSecretConfig.

@Test
public void shouldUpdateExistingSecretConfig() throws Exception {
    SecretConfig oldConfig = new SecretConfig("foo", "docker");
    SecretConfig newConfig = new SecretConfig("foo", "aws");
    cruiseConfig.getSecretConfigs().add(oldConfig);
    SecretConfigUpdateCommand command = new SecretConfigUpdateCommand(null, newConfig, null, null, null, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.getSecretConfigs().find("foo"), is(equalTo(newConfig)));
}
Also used : SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Example 20 with SecretConfig

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

the class SecretConfigDeleteCommandTest method shouldRaiseExceptionInCaseSecretConfigDoesNotExist.

@Test
public void shouldRaiseExceptionInCaseSecretConfigDoesNotExist() {
    SecretConfig secretConfig = new SecretConfig("foo", "file-based");
    assertThat(cruiseConfig.getSecretConfigs(), is(empty()));
    SecretConfigDeleteCommand command = new SecretConfigDeleteCommand(null, secretConfig, Collections.emptySet(), null, null, new HttpLocalizedOperationResult());
    assertThrows(RecordNotFoundException.class, () -> command.update(cruiseConfig));
    assertThat(cruiseConfig.getSecretConfigs(), is(empty()));
}
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