]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19530 acted upon warnings about missing response examples in webapi
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Mon, 24 Jun 2024 08:01:47 +0000 (10:01 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 26 Jun 2024 20:03:32 +0000 (20:03 +0000)
21 files changed:
gradle.properties
server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java
server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java
server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/SamlValidationRedirectionFilter.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ElasticSearchMetricTaskTest.java
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/sonarlint/SonarLintPushAction.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/CheckActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/CheckAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/monitoring/MetricsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessActionSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/DownloadAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/saml/ws/ValidationInitAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/scannercache/ws/GetAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/dismissmessage/ws/check-example.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/monitoring-metrics.txt [new file with mode: 0644]

index e57fce9dd1d3e5bdc480a28bfc4dea9b4fbb3e7b..c267f21d4d88ad83de13e46ab13c2e6ce21a9879 100644 (file)
@@ -7,7 +7,7 @@ version=10.7
 # No change required for patch versions
 versionEOL=2025-03-01
 
-pluginApiVersion=10.7.0.2191
+pluginApiVersion=10.8.0.2326
 description=Open source platform for continuous inspection of code quality
 projectTitle=SonarQube
 org.gradle.jvmargs=-Xmx2048m
index ab6485bb9037bc339f37a435e263aadb22dba554..80c9bd0ae91afe6a92207e04483ecf760237d6bd 100644 (file)
@@ -43,8 +43,8 @@ import org.sonar.api.server.ServerSide;
 import org.sonarqube.ws.client.OkHttpClientBuilder;
 
 import static java.util.stream.Collectors.joining;
-import static org.sonar.api.internal.apachecommons.lang.StringUtils.isBlank;
-import static org.sonar.api.internal.apachecommons.lang.StringUtils.substringBeforeLast;
+import static org.apache.commons.lang3.StringUtils.isBlank;
+import static org.apache.commons.lang3.StringUtils.substringBeforeLast;
 
 @ServerSide
 public class AzureDevOpsHttpClient {
index 79a99dccb1ba22d7d282ea2786f714e1327823f8..b11983d0a123a331485868bc452907c46572e3bb 100644 (file)
@@ -42,7 +42,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.server.exceptions.NotFoundException;
 
-import static org.sonar.api.internal.apachecommons.lang.StringUtils.removeEnd;
+import static org.apache.commons.lang3.StringUtils.removeEnd;
 
 @ServerSide
 public class BitbucketCloudRestClient {
index 4dcad40fb56418700d78e7b74a3444c8c0499288..e0ab68da9ce19bb82388dd12818b999dd6e1db84 100644 (file)
@@ -47,7 +47,7 @@ import static java.lang.String.format;
 import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
 import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
 import static java.util.Locale.ENGLISH;
-import static org.sonar.api.internal.apachecommons.lang.StringUtils.removeEnd;
+import static org.apache.commons.lang3.StringUtils.removeEnd;
 
 @ServerSide
 public class BitbucketServerRestClient {
index 63220e429614d33f307324c5b691a9b9d185f3c3..9cc631bdda34bb610be4bbab8467575afbff81e2 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.alm.client.ApplicationHttpClient.GetResponse;
 import org.sonar.alm.client.github.security.AppToken;
 import org.sonar.alm.client.github.security.GithubAppSecurity;
 import org.sonar.alm.client.gitlab.GsonApp;
-import org.sonar.api.internal.apachecommons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.sonar.auth.github.AppInstallationToken;
 import org.sonar.auth.github.GitHubSettings;
 import org.sonar.auth.github.GithubAppConfiguration;
index d8ef581bd13626b4c07260d118dcaa3cb85c197b..f602608a42a601bf324e4ce99ab832f88dd1498d 100644 (file)
@@ -26,7 +26,7 @@ import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import javax.annotation.Nullable;
 import org.apache.commons.lang3.StringUtils;
-import org.sonar.api.internal.apachecommons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.sonar.api.platform.Server;
 import org.sonar.api.server.http.HttpRequest;
 import org.sonar.api.server.http.HttpResponse;
@@ -78,7 +78,7 @@ public class SamlValidationRedirectionFilter extends HttpFilter {
       URI redirectionEndpointUrl = URI.create(server.getContextPath() + "/")
         .resolve(SAML_VALIDATION_CONTROLLER_CONTEXT + "/")
         .resolve(SAML_VALIDATION_KEY);
-      String samlResponse = StringEscapeUtils.escapeHtml(request.getParameter(SAML_RESPONSE_PARAMETER));
+      String samlResponse = StringEscapeUtils.escapeHtml3(request.getParameter(SAML_RESPONSE_PARAMETER));
       String csrfToken = getCsrfTokenFromRelayState(relayState);
 
       String nonce = SamlValidationCspHeaders.addCspHeadersWithNonceToResponse(response);
@@ -103,7 +103,7 @@ public class SamlValidationRedirectionFilter extends HttpFilter {
 
   private static String getCsrfTokenFromRelayState(@Nullable String relayState) {
     if (relayState != null && relayState.contains("/")) {
-      return StringEscapeUtils.escapeHtml(relayState.split("/")[1]);
+      return StringEscapeUtils.escapeHtml3(relayState.split("/")[1]);
     }
     return "";
   }
index 40593143feeacc06c54cf9b731c25d352ac2dc9b..728300033c985fcf311514ae0120902915dabf5f 100644 (file)
@@ -72,7 +72,7 @@ import static java.util.Arrays.asList;
 import static java.util.Optional.ofNullable;
 import static java.util.stream.Collectors.groupingBy;
 import static java.util.stream.Collectors.toMap;
-import static org.sonar.api.internal.apachecommons.lang.StringUtils.startsWithIgnoreCase;
+import static org.apache.commons.lang3.StringUtils.startsWithIgnoreCase;
 import static org.sonar.api.measures.CoreMetrics.BUGS_KEY;
 import static org.sonar.api.measures.CoreMetrics.DEVELOPMENT_COST_KEY;
 import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
index 60fc17a201e0469b4c7a93643f24f1e172a592cf..d4273b6ab51910a7180dcce16e3f5883e23782f9 100644 (file)
@@ -36,7 +36,7 @@ import org.slf4j.event.Level;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.internal.apachecommons.io.IOUtils;
-import org.sonar.api.internal.apachecommons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.sonar.api.testfixtures.log.LogTester;
 import org.sonar.server.es.EsClient;
 import org.sonar.server.es.response.NodeStatsResponse;
index 1b7c64e1319c1913faaf8f1e731fdf833e9806b7..8b9bb4545a7a7ab0c79adccecaedc737ab42227c 100644 (file)
@@ -62,6 +62,7 @@ public class SonarLintPushAction extends ServerPushAction {
       .setInternal(true)
       .setDescription("Endpoint for listening to server side events. Currently it notifies listener about change to activation of a rule")
       .setSince("9.4")
+      .setContentType(Response.ContentType.NO_CONTENT)
       .setHandler(this);
 
     action
index d6f343e32517264c5ae61420a4c01d3e051d0f98..d17e0382ec8272dc41c2c217d754823691316c2c 100644 (file)
@@ -59,6 +59,7 @@ public class CheckActionIT {
     assertThat(def.params()).extracting(WebService.Param::key, WebService.Param::isRequired).containsOnly(
       tuple("projectKey", false),
       tuple("messageType", true));
+    assertThat(def.responseExampleAsString()).isNotEmpty();
   }
 
   @Test
index 5c4545ea558b648add9ab1ed812f3fee2afded35..1648f8c64e2e39383083c4c1c9ccb318f7ebf12d 100644 (file)
@@ -51,6 +51,11 @@ public class SafeModeMonitoringMetricActionIT {
   private final SafeModeMonitoringMetricAction safeModeMonitoringMetricAction = new SafeModeMonitoringMetricAction(systemPasscode, bearerPasscode);
   private final WsActionTester ws = new WsActionTester(safeModeMonitoringMetricAction);
 
+  @Test
+  public void define_containsResponseExample() {
+    assertThat(ws.getDef().responseExampleAsString()).isNotEmpty();
+  }
+
   @Test
   public void no_authentication_throw_insufficient_privileges_error() {
     TestRequest request = ws.newRequest();
index 08c587a3b0c00f946462d6bfeb27d004bf3cdf72..6a792535f1901b6387405c97dc68a83b2b5891b0 100644 (file)
@@ -74,6 +74,7 @@ public class CheckPatAction implements AlmIntegrationsWsAction {
       .setInternal(true)
       .setSince("8.2")
       .setHandler(this)
+      .setContentType(Response.ContentType.NO_CONTENT)
       .setChangelog(new Change("9.0", "Bitbucket Cloud support was added"));
 
     action.createParam(PARAM_ALM_SETTING)
index 8d527b2f01f960cb699e68825fc594fa5153267d..dabbbaf1bf2f8632b8b367bfcaf2737f36d07831 100644 (file)
@@ -56,6 +56,7 @@ public class CheckAction implements DismissMessageWsAction {
     WebService.NewAction action = context.createAction("check")
       .setDescription("Check if a message has been dismissed.")
       .setSince("10.2")
+      .setResponseExample(getClass().getResource("check-example.json"))
       .setInternal(true)
       .setHandler(this);
 
index 6f5e731b00f9c2caeea4b3b52860f4261759d03d..26e28f064306d6f7e7c6f48b8a695360acb21c02 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.monitoring;
 
-import org.sonar.api.server.ws.WebService;
 import org.sonar.server.platform.ws.SafeModeMonitoringMetricAction;
 import org.sonar.server.user.BearerPasscode;
 import org.sonar.server.user.SystemPasscode;
@@ -34,20 +33,6 @@ public class MetricsAction extends SafeModeMonitoringMetricAction {
     this.userSession = userSession;
   }
 
-  @Override
-  public void define(WebService.NewController context) {
-    context.createAction("metrics")
-      .setSince("9.3")
-      .setDescription("""
-        Return monitoring metrics in Prometheus format.\s
-        Support content type 'text/plain' (default) and 'application/openmetrics-text'.
-        this endpoint can be access using a Bearer token, that needs to be defined in sonar.properties with the 'sonar.web.systemPasscode' key.""")
-      .setResponseExample(getClass().getResource("monitoring-metrics.txt"))
-      .setHandler(this);
-
-    isWebUpGauge.set(1D);
-  }
-
   @Override
   public boolean isSystemAdmin() {
     return userSession.isSystemAdministrator();
index f0ac87b12b24f9d4554fad45d0306a28be34157f..e92c75b914f6baa9d91f5aeb8e9e332241cebe50 100644 (file)
@@ -46,6 +46,7 @@ public class LivenessActionSupport {
         "</p>")
       .setSince("9.1")
       .setInternal(true)
+      .setContentType(Response.ContentType.NO_CONTENT)
       .setHandler(handler);
   }
 
index 8a33cb0ebbb97693ec2bdef527f0939495e51a10..e9948472929a2d6d1c724762acd400333aae36fe 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform.ws;
 
+import com.google.common.io.Resources;
 import com.google.common.net.HttpHeaders;
 import io.prometheus.client.CollectorRegistry;
 import io.prometheus.client.Gauge;
@@ -50,7 +51,14 @@ public class SafeModeMonitoringMetricAction implements MonitoringWsAction {
 
   @Override
   public void define(WebService.NewController context) {
-    context.createAction("metrics").setHandler(this);
+    context.createAction("metrics")
+      .setSince("9.3")
+      .setDescription("""
+        Return monitoring metrics in Prometheus format.\s
+        Support content type 'text/plain' (default) and 'application/openmetrics-text'.
+        this endpoint can be access using a Bearer token, that needs to be defined in sonar.properties with the 'sonar.web.systemPasscode' key.""")
+      .setResponseExample(Resources.getResource(this.getClass(), "monitoring-metrics.txt"))
+      .setHandler(this);
     isWebUpGauge.set(1D);
   }
 
index f1962812e4dc879eb6817d556c4daf8173b8864d..dd7605516b5caf6b4c4ca7f7ba034d2a83a85a65 100644 (file)
@@ -47,7 +47,7 @@ public class DownloadAction implements PluginsWsAction {
       .setSince("7.2")
       .setDescription("Download plugin JAR, for usage by scanner engine")
       .setInternal(true)
-      .setResponseExample(getClass().getResource("example-download.json"))
+      .setContentType(Response.ContentType.BINARY)
       .setHandler(this);
 
     action.createParam(PLUGIN_PARAM)
index ded626c07a5572eb10b0eeea668dcb4f9a82b439..d7257c6221ac2a5e479f90e73b159895c0a8ef26 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.saml.ws;
 import java.io.IOException;
 import org.sonar.api.server.http.HttpRequest;
 import org.sonar.api.server.http.HttpResponse;
+import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.web.FilterChain;
 import org.sonar.api.web.HttpFilter;
@@ -67,6 +68,7 @@ public class ValidationInitAction extends HttpFilter implements SamlAction {
       .setPost(false)
       .setHandler(ServletFilterHandler.INSTANCE)
       .setDescription("Initiate a SAML request to the identity Provider for configuration validation purpose.")
+      .setContentType(Response.ContentType.NO_CONTENT)
       .setSince("9.7");
   }
 
index 73eee09e09863b993782d25ef4596aef3d01bee2..dcabfcb71c817b545609c301a2c942b223b5f95a 100644 (file)
@@ -67,6 +67,7 @@ public class GetAction implements AnalysisCacheWsAction {
         + "Data is returned gzipped if the corresponding 'Accept-Encoding' header is set in the request.")
       .setChangelog(new Change("9.9", "The web service is no longer internal"))
       .setSince("9.4")
+      .setContentType(Response.ContentType.BINARY)
       .setHandler(this);
 
     action.createParam(PROJECT)
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/dismissmessage/ws/check-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/dismissmessage/ws/check-example.json
new file mode 100644 (file)
index 0000000..e283786
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  "dismissed":true
+}
\ No newline at end of file
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/monitoring-metrics.txt b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/monitoring-metrics.txt
new file mode 100644 (file)
index 0000000..48b4b24
--- /dev/null
@@ -0,0 +1,44 @@
+# HELP sonarqube_compute_engine_tasks_running_duration_seconds Compute engine task running time in seconds
+# TYPE sonarqube_compute_engine_tasks_running_duration_seconds summary
+# HELP sonarqube_health_web_status Tells whether Web process is up or down. 1 for up, 0 for down
+# TYPE sonarqube_health_web_status gauge
+sonarqube_health_web_status 1.0
+# HELP sonarqube_license_days_before_expiration_total Days until the SonarQube license will expire.
+# TYPE sonarqube_license_days_before_expiration_total gauge
+sonarqube_license_days_before_expiration_total 28.0
+# HELP sonarqube_license_number_of_lines_remaining_total Number of lines remaining until the limit for the current license is hit.
+# TYPE sonarqube_license_number_of_lines_remaining_total gauge
+sonarqube_license_number_of_lines_remaining_total 5000000.0
+# HELP sonarqube_health_compute_engine_status Tells whether Compute Engine is up (healthy, ready to take tasks) or down. 1 for up, 0 for down
+# TYPE sonarqube_health_compute_engine_status gauge
+sonarqube_health_compute_engine_status 1.0
+# HELP sonarqube_license_number_of_lines_analyzed_total Number of lines analyzed.
+# TYPE sonarqube_license_number_of_lines_analyzed_total gauge
+sonarqube_license_number_of_lines_analyzed_total 0.0
+# HELP sonarqube_web_uptime_minutes Number of minutes for how long the SonarQube instance is running
+# TYPE sonarqube_web_uptime_minutes gauge
+sonarqube_web_uptime_minutes 13.0
+# HELP sonarqube_health_integration_azuredevops_status Tells whether SonarQube instance has configured Azure integration and its status is green. 1 for green, 0 otherwise .
+# TYPE sonarqube_health_integration_azuredevops_status gauge
+sonarqube_health_integration_azuredevops_status 0.0
+# HELP sonarqube_health_elasticsearch_status Tells whether Elasticsearch is up or down. 1 for Up, 0 for down
+# TYPE sonarqube_health_elasticsearch_status gauge
+sonarqube_health_elasticsearch_status 1.0
+# HELP sonarqube_health_integration_gitlab_status Tells whether SonarQube instance has configured GitLab integration and its status is green. 1 for green, 0 otherwise .
+# TYPE sonarqube_health_integration_gitlab_status gauge
+sonarqube_health_integration_gitlab_status 0.0
+# HELP sonarqube_health_integration_github_status Tells whether SonarQube instance has configured GitHub integration and its status is green. 1 for green, 0 otherwise .
+# TYPE sonarqube_health_integration_github_status gauge
+sonarqube_health_integration_github_status 0.0
+# HELP sonarqube_health_integration_bitbucket_status Tells whether SonarQube instance has configured BitBucket integration and its status is green. 1 for green, 0 otherwise .
+# TYPE sonarqube_health_integration_bitbucket_status gauge
+sonarqube_health_integration_bitbucket_status 0.0
+# HELP sonarqube_elasticsearch_disk_space_total_bytes Total disk space on the device
+# TYPE sonarqube_elasticsearch_disk_space_total_bytes gauge
+sonarqube_elasticsearch_disk_space_total_bytes{node_name="sonarqube",} 9.9466258432E11
+# HELP sonarqube_elasticsearch_disk_space_free_bytes Space left on device
+# TYPE sonarqube_elasticsearch_disk_space_free_bytes gauge
+sonarqube_elasticsearch_disk_space_free_bytes{node_name="sonarqube",} 9.00287975424E11
+# HELP sonarqube_compute_engine_pending_tasks_total Number of tasks at given point of time that were pending in the Compute Engine queue [SHARED, same value for every SonarQube instance]
+# TYPE sonarqube_compute_engine_pending_tasks_total gauge
+sonarqube_compute_engine_pending_tasks_total 0.0
\ No newline at end of file