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);
}
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);
}
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;
}
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."));
}
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));
}
Aggregations