@@ -65,5 +65,6 @@ public class ProjectBadgeTokenDao implements Dao { | |||
@CheckForNull | |||
public ProjectBadgeTokenDto selectTokenByProject(DbSession session, ProjectDto projectDto) { | |||
return mapper(session).selectTokenByProjectUuid(projectDto.getUuid()); | |||
} | |||
} |
@@ -40,6 +40,7 @@ public class ProjectBadgesSupport { | |||
private static final String PARAM_PROJECT = "project"; | |||
private static final String PARAM_BRANCH = "branch"; | |||
private static final String PARAM_TOKEN = "token"; | |||
public static final String PROJECT_HAS_NOT_BEEN_FOUND = "Project has not been found"; | |||
private final ComponentFinder componentFinder; | |||
private final DbClient dbClient; | |||
@@ -83,7 +84,7 @@ public class ProjectBadgesSupport { | |||
return branch; | |||
} catch (NotFoundException e) { | |||
throw new NotFoundException("Project has not been found"); | |||
throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND); | |||
} | |||
} | |||
@@ -98,11 +99,11 @@ public class ProjectBadgesSupport { | |||
try { | |||
projectDto = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey); | |||
} catch (NotFoundException e) { | |||
throw new NotFoundException("Project has not been found"); | |||
throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND); | |||
} | |||
String token = request.param(PARAM_TOKEN); | |||
if (projectDto.isPrivate() && !isTokenValid(dbSession, projectDto, token)) { | |||
throw generateInvalidProjectException(); | |||
throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND); | |||
} | |||
} | |||
} |
@@ -329,7 +329,7 @@ public class MeasureActionTest { | |||
.setParam("metric", metric.getKey()) | |||
.execute(); | |||
checkError(response, "Project is invalid"); | |||
checkError(response, "Project has not been found"); | |||
} | |||
@Test |
@@ -197,7 +197,7 @@ public class QualityGateActionTest { | |||
.setParam("project", project.getKey()) | |||
.execute(); | |||
checkError(response, "Project is invalid"); | |||
checkError(response, "Project has not been found"); | |||
} | |||
@Test |
@@ -33,6 +33,7 @@ public class MeasureRequest { | |||
private String branch; | |||
private String metric; | |||
private String project; | |||
private String token; | |||
/** | |||
* Example value: "feature/my_branch" | |||
@@ -84,4 +85,16 @@ public class MeasureRequest { | |||
public String getProject() { | |||
return project; | |||
} | |||
/** | |||
* Tthis an optional parameter. | |||
*/ | |||
public MeasureRequest setToken(String token) { | |||
this.token = token; | |||
return this; | |||
} | |||
public String getToken() { | |||
return token; | |||
} | |||
} |
@@ -21,9 +21,12 @@ package org.sonarqube.ws.client.projectbadges; | |||
import javax.annotation.Generated; | |||
import org.sonarqube.ws.MediaTypes; | |||
import org.sonarqube.ws.ProjectBadgeToken.TokenWsResponse; | |||
import org.sonarqube.ws.client.BaseService; | |||
import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.PostRequest; | |||
import org.sonarqube.ws.client.WsConnector; | |||
import org.sonarqube.ws.client.WsResponse; | |||
/** | |||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges">Further information about this web service online</a> | |||
@@ -48,6 +51,7 @@ public class ProjectBadgesService extends BaseService { | |||
.setParam("branch", request.getBranch()) | |||
.setParam("metric", request.getMetric()) | |||
.setParam("project", request.getProject()) | |||
.setParam("token", request.getToken()) | |||
.setMediaType(MediaTypes.JSON) | |||
).content(); | |||
} | |||
@@ -64,7 +68,35 @@ public class ProjectBadgesService extends BaseService { | |||
new GetRequest(path("quality_gate")) | |||
.setParam("branch", request.getBranch()) | |||
.setParam("project", request.getProject()) | |||
.setParam("token", request.getToken()) | |||
.setMediaType(MediaTypes.JSON) | |||
).content(); | |||
} | |||
/** | |||
* | |||
* This is part of the internal API. | |||
* This is a GET request. | |||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/token">Further information about this action online (including a response example)</a> | |||
* @since 9.2 | |||
* @return | |||
*/ | |||
public TokenWsResponse token(TokenRequest request) { | |||
return call( | |||
new GetRequest(path("token")) | |||
.setParam("project", request.getProject()) | |||
.setMediaType(MediaTypes.JSON), | |||
TokenWsResponse.parser() | |||
); | |||
} | |||
public WsResponse renewToken(RenewTokenRequest request) { | |||
return call( | |||
new PostRequest(path("renew_token")) | |||
.setParam("project", request.getProject()) | |||
.setMediaType(MediaTypes.JSON) | |||
); | |||
} | |||
} |
@@ -32,6 +32,7 @@ public class QualityGateRequest { | |||
private String branch; | |||
private String project; | |||
private String token; | |||
/** | |||
* Example value: "feature/my_branch" | |||
@@ -57,4 +58,16 @@ public class QualityGateRequest { | |||
public String getProject() { | |||
return project; | |||
} | |||
/** | |||
* This is aan optional parameter. | |||
*/ | |||
public QualityGateRequest setToken(String token) { | |||
this.token = token; | |||
return this; | |||
} | |||
public String getToken() { | |||
return token; | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
/* | |||
* 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.sonarqube.ws.client.projectbadges; | |||
import javax.annotation.Generated; | |||
/** | |||
* This is part of the internal API. | |||
* This is a POST request. | |||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/renew_token">Further information about this action online (including a response example)</a> | |||
* @since 9.2 | |||
*/ | |||
@Generated("sonar-ws-generator") | |||
public class RenewTokenRequest { | |||
private String project; | |||
/** | |||
* This is a mandatory parameter. | |||
* Example value: "my_project" | |||
*/ | |||
public RenewTokenRequest setProject(String project) { | |||
this.project = project; | |||
return this; | |||
} | |||
public String getProject() { | |||
return project; | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
/* | |||
* 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.sonarqube.ws.client.projectbadges; | |||
import javax.annotation.Generated; | |||
/** | |||
* This is part of the internal API. | |||
* This is a GET request. | |||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/token">Further information about this action online (including a response example)</a> | |||
* @since 9.2 | |||
*/ | |||
@Generated("sonar-ws-generator") | |||
public class TokenRequest { | |||
private String project; | |||
/** | |||
* This is a mandatory parameter. | |||
* Example value: "my_project" | |||
*/ | |||
public TokenRequest setProject(String project) { | |||
this.project = project; | |||
return this; | |||
} | |||
public String getProject() { | |||
return project; | |||
} | |||
} |