Search in sources :

Example 31 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method return_project_settings_from_definitions_when_component_and_no_keys.

@Test
public void return_project_settings_from_definitions_when_component_and_no_keys() throws Exception {
    logInAsProjectAdmin();
    definitions.addComponents(asList(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(), PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build(), PropertyDefinition.builder("plugin.license.secured").onQualifiers(PROJECT).type(LICENSE).build()));
    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("one"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password"), newComponentPropertyDto(project).setKey("plugin.license.secured").setValue("ABCD"));
    ValuesWsResponse result = executeRequestForProjectProperties();
    assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured");
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Settings(org.sonarqube.ws.Settings) Test(org.junit.Test)

Example 32 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method does_not_returned_secured_and_license_settings_in_property_set_when_not_authenticated.

@Test
public void does_not_returned_secured_and_license_settings_in_property_set_when_not_authenticated() throws Exception {
    definitions.addComponent(PropertyDefinition.builder("foo").type(PropertyType.PROPERTY_SET).fields(asList(PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("plugin.license.secured").name("License").type(LICENSE).build(), PropertyFieldDefinition.build("secret.secured").name("Secured").build())).build());
    propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "plugin.license.secured", "ABCD", "secret.secured", "123456"));
    ValuesWsResponse result = executeRequestForGlobalProperties();
    assertFieldValues(result.getSettings(0), ImmutableMap.of("key", "key1"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Test(org.junit.Test)

Example 33 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method return_secured_and_license_settings_when_system_admin.

@Test
public void return_secured_and_license_settings_when_system_admin() throws Exception {
    logInAsAdmin();
    definitions.addComponents(asList(PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build(), PropertyDefinition.builder("plugin.license.secured").type(LICENSE).build()));
    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password"), newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321"));
    ValuesWsResponse result = executeRequestForGlobalProperties();
    assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured", "sonar.plugin.licenseHash.secured");
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Settings(org.sonarqube.ws.Settings) Test(org.junit.Test)

Example 34 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class DefaultSettingsLoader method load.

@Override
public Map<String, String> load(@Nullable String componentKey) {
    String url = "api/settings/values.protobuf";
    Profiler profiler = Profiler.create(LOG);
    if (componentKey != null) {
        url += "?component=" + ScannerUtils.encodeForUrl(componentKey);
        profiler.startInfo("Load settings for component '" + componentKey + "'");
    } else {
        profiler.startInfo("Load global settings");
    }
    try (InputStream is = wsClient.call(new GetRequest(url)).contentStream()) {
        ValuesWsResponse values = ValuesWsResponse.parseFrom(is);
        profiler.stopInfo();
        return toMap(values.getSettingsList());
    } catch (IOException e) {
        throw new IllegalStateException("Failed to load server settings", e);
    }
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Profiler(org.sonar.api.utils.log.Profiler) InputStream(java.io.InputStream) GetRequest(org.sonarqube.ws.client.GetRequest) IOException(java.io.IOException)

Aggregations

ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)34 Test (org.junit.Test)32 Settings (org.sonarqube.ws.Settings)19 ComponentDto (org.sonar.db.component.ComponentDto)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CheckForNull (javax.annotation.CheckForNull)1 Profiler (org.sonar.api.utils.log.Profiler)1 Setting (org.sonarqube.ws.Settings.Setting)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 LicenseItem (pageobjects.licenses.LicenseItem)1 LicensesPage (pageobjects.licenses.LicensesPage)1