aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-23 09:04:16 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-23 17:26:29 +0100
commit7fb14c3d55ba19b85e7361577a92ee5a0f8ccefc (patch)
tree5cfe848ea35b532f0804b7db4fcc0b9c1e0be66e /sonar-ws
parentfac2525b1ba5448bbfd2efdb672d708d889e993d (diff)
downloadsonarqube-7fb14c3d55ba19b85e7361577a92ee5a0f8ccefc.tar.gz
sonarqube-7fb14c3d55ba19b85e7361577a92ee5a0f8ccefc.zip
SONAR-7039 Generate user tokens
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java7
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/GenerateWsRequest.java44
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsClient.java51
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsParameters.java33
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/package-info.java25
-rw-r--r--sonar-ws/src/main/protobuf/ws-user_tokens.proto32
6 files changed, 192 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
index b9822ee9872..39886b57a61 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
@@ -27,6 +27,7 @@ import org.sonarqube.ws.client.component.ComponentsWsClient;
import org.sonarqube.ws.client.issue.IssuesWsClient;
import org.sonarqube.ws.client.permission.PermissionsWsClient;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesWsClient;
+import org.sonarqube.ws.client.usertoken.UserTokensWsClient;
import static org.sonarqube.ws.client.WsRequest.MediaType.PROTOBUF;
@@ -48,6 +49,7 @@ public class WsClient {
private final ComponentsWsClient componentsWsClient;
private final QualityProfilesWsClient qualityProfilesWsClient;
private final IssuesWsClient issuesWsClient;
+ private final UserTokensWsClient userTokensWsClient;
public WsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
@@ -55,6 +57,7 @@ public class WsClient {
this.componentsWsClient = new ComponentsWsClient(this);
this.qualityProfilesWsClient = new QualityProfilesWsClient(this);
this.issuesWsClient = new IssuesWsClient(this);
+ userTokensWsClient = new UserTokensWsClient(this);
}
public String execute(WsRequest wsRequest) {
@@ -80,4 +83,8 @@ public class WsClient {
public IssuesWsClient issuesWsClient() {
return issuesWsClient;
}
+
+ public UserTokensWsClient userTokensWsClient() {
+ return userTokensWsClient;
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/GenerateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/GenerateWsRequest.java
new file mode 100644
index 00000000000..c5072110cad
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/GenerateWsRequest.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.sonarqube.ws.client.usertoken;
+
+public class GenerateWsRequest {
+ private String login;
+ private String name;
+
+ public String getLogin() {
+ return login;
+ }
+
+ public GenerateWsRequest setLogin(String login) {
+ this.login = login;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public GenerateWsRequest setName(String name) {
+ this.name = name;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsClient.java
new file mode 100644
index 00000000000..21e076f3594
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsClient.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.sonarqube.ws.client.usertoken;
+
+import org.sonarqube.ws.WsUserTokens.GenerateWsResponse;
+import org.sonarqube.ws.client.WsClient;
+
+import static org.sonarqube.ws.client.WsRequest.newPostRequest;
+import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_GENERATE;
+import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.USER_TOKENS_ENDPOINT;
+import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_LOGIN;
+import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_NAME;
+
+public class UserTokensWsClient {
+ private static final String SLASH = "/";
+ private final WsClient wsClient;
+
+ public UserTokensWsClient(WsClient wsClient) {
+ this.wsClient = wsClient;
+ }
+
+ public GenerateWsResponse generate(GenerateWsRequest request) {
+ return wsClient.execute(
+ newPostRequest(action(ACTION_GENERATE))
+ .setParam(PARAM_LOGIN, request.getLogin())
+ .setParam(PARAM_NAME, request.getName()),
+ GenerateWsResponse.parser());
+ }
+
+ private static String action(String action) {
+ return USER_TOKENS_ENDPOINT + SLASH + action;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsParameters.java
new file mode 100644
index 00000000000..856fd6cdffd
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensWsParameters.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.sonarqube.ws.client.usertoken;
+
+public class UserTokensWsParameters {
+ public static final String USER_TOKENS_ENDPOINT = "api/user_tokens";
+ public static final String ACTION_GENERATE = "generate";
+
+ public static final String PARAM_LOGIN = "login";
+ public static final String PARAM_NAME = "name";
+
+ private UserTokensWsParameters() {
+ // constants only
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/package-info.java
new file mode 100644
index 00000000000..b3b9a3e7648
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.usertoken;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/main/protobuf/ws-user_tokens.proto b/sonar-ws/src/main/protobuf/ws-user_tokens.proto
new file mode 100644
index 00000000000..8ba07bbf483
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-user_tokens.proto
@@ -0,0 +1,32 @@
+// SonarQube, open source software quality management tool.
+// Copyright (C) 2008-2015 SonarSource
+// mailto:contact AT sonarsource DOT com
+//
+// SonarQube 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.
+//
+// SonarQube 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.
+
+syntax = "proto2";
+
+package sonarqube.ws.usertoken;
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "WsUserTokens";
+option optimize_for = SPEED;
+
+// WS api/user_tokens/generate
+message GenerateWsResponse {
+ optional string login = 1;
+ optional string name = 2;
+ optional string token = 3;
+}