aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-alm-client
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2021-06-02 09:29:46 +0200
committersonartech <sonartech@sonarsource.com>2021-06-10 20:03:27 +0000
commit1417465dc1947354f332dbd0faa58ac95802edbb (patch)
treebdee3dc711b2fdbde3b5a71d5049449da0271999 /server/sonar-alm-client
parent296678c4afb79db4a40cf6576d1ae2b6cd9040e8 (diff)
downloadsonarqube-1417465dc1947354f332dbd0faa58ac95802edbb.tar.gz
sonarqube-1417465dc1947354f332dbd0faa58ac95802edbb.zip
SONAR-14871 Add Azure Devops project binding validation
Diffstat (limited to 'server/sonar-alm-client')
-rw-r--r--server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java11
-rw-r--r--server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevopsServerException.java33
2 files changed, 42 insertions, 2 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
index 082e8247e72..07d79a7b5e7 100644
--- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
+++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
@@ -74,6 +74,13 @@ public class AzureDevOpsHttpClient {
return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureProjectList.class));
}
+ public GsonAzureProject getProject(String serverUrl, String token, String projectName) {
+ String url = String.format("%s/_apis/projects/%s?%s", getTrimmedUrl(serverUrl), projectName, API_VERSION_3);
+ LOG.debug(String.format("get project : [%s]", url));
+ return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureProject.class));
+
+ }
+
public GsonAzureRepoList getRepos(String serverUrl, String token, @Nullable String projectName) {
String url;
if (projectName != null && !projectName.isEmpty()) {
@@ -132,13 +139,13 @@ public class AzureDevOpsHttpClient {
if (!response.isSuccessful()) {
LOG.debug(UNABLE_TO_CONTACT_AZURE_SERVER + ": {} {}", response.request().url().toString(), response.code());
if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
- throw new IllegalArgumentException("Invalid personal access token");
+ throw new AzureDevopsServerException(response.code(), "Invalid personal access token");
}
ResponseBody responseBody = response.body();
String body = responseBody == null ? "" : responseBody.string();
String errorMessage = generateErrorMessage(body, UNABLE_TO_CONTACT_AZURE_SERVER);
LOG.info(String.format("Azure API call to [%s] failed with %s http code. Azure response content : [%s]", response.request().url().toString(), response.code(), body));
- throw new IllegalArgumentException(errorMessage);
+ throw new AzureDevopsServerException(response.code(), errorMessage);
}
}
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevopsServerException.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevopsServerException.java
new file mode 100644
index 00000000000..7a298423278
--- /dev/null
+++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevopsServerException.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.alm.client.azure;
+
+public class AzureDevopsServerException extends IllegalArgumentException {
+ private final int httpCode;
+
+ public AzureDevopsServerException(int httpCode, String clientErrorMessage) {
+ super(clientErrorMessage);
+ this.httpCode = httpCode;
+ }
+
+ public int getHttpCode() {
+ return httpCode;
+ }
+}