Search in sources :

Example 26 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class UpdateGithubAction method doHandle.

private void doHandle(Request request) {
    String key = request.mandatoryParam(PARAM_KEY);
    String newKey = request.param(PARAM_NEW_KEY);
    String url = request.mandatoryParam(PARAM_URL);
    String appId = request.mandatoryParam(PARAM_APP_ID);
    String clientId = request.mandatoryParam(PARAM_CLIENT_ID);
    String clientSecret = request.param(PARAM_CLIENT_SECRET);
    String privateKey = request.param(PARAM_PRIVATE_KEY);
    if (url.endsWith("/")) {
        url = url.substring(0, url.length() - 1);
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, key);
        if (isNotBlank(newKey) && !newKey.equals(key)) {
            almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
        }
        if (isNotBlank(privateKey)) {
            almSettingDto.setPrivateKey(privateKey);
        }
        if (isNotBlank(clientSecret)) {
            almSettingDto.setClientSecret(clientSecret);
        }
        dbClient.almSettingDao().update(dbSession, almSettingDto.setKey(isNotBlank(newKey) ? newKey : key).setUrl(url).setAppId(appId).setClientId(clientId), clientSecret != null || privateKey != null);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Example 27 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class UpdateAzureAction method doHandle.

private void doHandle(Request request) {
    String key = request.mandatoryParam(PARAM_KEY);
    String newKey = request.param(PARAM_NEW_KEY);
    String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN);
    String url = request.mandatoryParam(PARAM_URL);
    try (DbSession dbSession = dbClient.openSession(false)) {
        AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, key);
        if (isNotBlank(newKey) && !newKey.equals(key)) {
            almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
        }
        if (isNotBlank(pat)) {
            almSettingDto.setPersonalAccessToken(pat);
        }
        dbClient.almSettingDao().update(dbSession, almSettingDto.setKey(isNotBlank(newKey) ? newKey : key).setUrl(url), pat != null);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Example 28 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class UpdateBitbucketCloudAction method doHandle.

private void doHandle(Request request) {
    String key = request.mandatoryParam(PARAM_KEY);
    String newKey = request.param(PARAM_NEW_KEY);
    String workspace = request.mandatoryParam(PARAM_WORKSPACE);
    String clientId = request.mandatoryParam(PARAM_CLIENT_ID);
    String clientSecret = request.param(PARAM_CLIENT_SECRET);
    try (DbSession dbSession = dbClient.openSession(false)) {
        AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, key);
        if (isNotBlank(newKey) && !newKey.equals(key)) {
            almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
        }
        if (isNotBlank(clientSecret)) {
            almSettingDto.setClientSecret(clientSecret);
        }
        dbClient.almSettingDao().update(dbSession, almSettingDto.setKey(isNotBlank(newKey) ? newKey : key).setClientId(clientId).setAppId(workspace), clientSecret != null);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Example 29 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class UpdateGitlabAction method doHandle.

private void doHandle(Request request) {
    String key = request.mandatoryParam(PARAM_KEY);
    String newKey = request.param(PARAM_NEW_KEY);
    String url = StringUtils.trim(request.mandatoryParam(PARAM_URL));
    String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN);
    try (DbSession dbSession = dbClient.openSession(false)) {
        AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, key);
        if (isNotBlank(newKey) && !newKey.equals(key)) {
            almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
        }
        if (isNotBlank(pat)) {
            almSettingDto.setPersonalAccessToken(pat);
        }
        dbClient.almSettingDao().update(dbSession, almSettingDto.setKey(isNotBlank(newKey) ? newKey : key).setUrl(url), pat != null);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Example 30 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class AlmConfigurationSectionTest method null_url_are_ignored.

@Test
public void null_url_are_ignored() {
    AlmSettingDto azure = db.almSettings().insertAzureAlmSetting(a -> a.setUrl(null));
    ProtobufSystemInfo.Section section = underTest.toProtobuf();
    assertThat(section.getAttributesList()).hasSize(1);
    assertThat(section.getAttributesList()).extracting(Attribute::getKey, Attribute::getStringValue).containsExactlyInAnyOrder(tuple(azure.getKey(), String.format("Alm:%s", azure.getRawAlm())));
}
Also used : ProtobufSystemInfo(org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25