Skip to content

Commit 422fc1b

Browse files
committed
Path signature '/api/config/datastore/{}' MUST be unique
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
1 parent 0c45d58 commit 422fc1b

6 files changed

Lines changed: 33 additions & 31 deletions

File tree

docs/site/content/en/openapi/openapi.yaml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ tags:
3030
x-smallrye-profile-external: ""
3131
paths:
3232
/api/config/datastore:
33+
get:
34+
tags:
35+
- Config
36+
description: Obtain list of configured datastores for particular team
37+
operationId: getDatastoresByTeam
38+
parameters:
39+
- name: team
40+
in: query
41+
description: name of the team to search for defined datastores
42+
schema:
43+
type: string
44+
example: perf-team
45+
responses:
46+
"200":
47+
description: OK
48+
content:
49+
application/json:
50+
schema:
51+
type: array
52+
items:
53+
$ref: "#/components/schemas/Datastore"
3354
put:
3455
tags:
3556
- Config
@@ -117,29 +138,6 @@ paths:
117138
application/json:
118139
schema:
119140
$ref: "#/components/schemas/DatastoreTestResponse"
120-
/api/config/datastore/{team}:
121-
get:
122-
tags:
123-
- Config
124-
description: Obtain list of configured datastores for particular team
125-
operationId: datastores
126-
parameters:
127-
- name: team
128-
in: path
129-
description: name of the team to search for defined datastores
130-
required: true
131-
schema:
132-
type: string
133-
example: perf-team
134-
responses:
135-
"200":
136-
description: OK
137-
content:
138-
application/json:
139-
schema:
140-
type: array
141-
items:
142-
$ref: "#/components/schemas/Datastore"
143141
/api/config/keycloak:
144142
get:
145143
tags:

horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/services/ConfigService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public interface ConfigService {
4343
VersionInfo version();
4444

4545
@GET
46-
@Path("datastore/{team}")
46+
@Path("datastore")
4747
@Operation(description = "Obtain list of configured datastores for particular team")
4848
@Parameters(value = {
4949
@Parameter(name = "team", description = "name of the team to search for defined datastores", example = "perf-team")
5050
})
51-
List<Datastore> datastores(@PathParam("team") String team);
51+
List<Datastore> getDatastoresByTeam(@QueryParam("team") String team);
5252

5353
@GET
5454
@Path("datastore/types")

horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ConfigServiceImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,19 @@ public VersionInfo version() {
6767
@Override
6868
@PermitAll
6969
@Transactional
70-
public List<Datastore> datastores(String team) {
70+
public List<Datastore> getDatastoresByTeam(String team) {
71+
if (team == null || team.isBlank()) {
72+
throw ServiceException.badRequest("Team cannot be null or blank");
73+
}
74+
7175
String queryWhere = "where access = 0";
7276
Set<String> roles = identity.getRoles();
7377
long rolesCount = roles.stream().filter(role -> role.endsWith("-team")).count();
7478
if (rolesCount != 0) { //user has access to team, retrieve the team datastore as well
7579
queryWhere = queryWhere.concat(" or owner in ('" + team + "')");
7680
}
7781
List<DatastoreConfigDAO> backends = DatastoreConfigDAO.list(queryWhere);
78-
if (backends.size() != 0) {
82+
if (!backends.isEmpty()) {
7983
return backends.stream().map(DatasourceMapper::from).collect(Collectors.toList());
8084
} else {
8185
return Collections.emptyList();

horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/DatasourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ DatastoreConfigDAO.<DatastoreConfigDAO> list("owner = ?1 and type = ?2", TESTER_
216216
DatastoreConfigDAO newDatastore = DatastoreConfigDAO.findById(testConfig.datastore.id);
217217
assertNotNull(newDatastore);
218218

219-
List<Object> datastores = unauthenticatedJsonRequest().get("/api/config/datastore/".concat(TESTER_ROLES[0]))
219+
List<Object> datastores = unauthenticatedJsonRequest().get("/api/config/datastore?team=".concat(TESTER_ROLES[0]))
220220
.then().statusCode(200).extract().body().as(List.class);
221221

222222
assertNotNull(datastores);
223223
assertSame(1, datastores.size());
224224

225-
datastores = jsonRequest().get("/api/config/datastore/".concat(TESTER_ROLES[0]))
225+
datastores = jsonRequest().get("/api/config/datastore?team=".concat(TESTER_ROLES[0]))
226226
.then().statusCode(200).extract().body().as(List.class);
227227

228228
assertNotNull(datastores);

horreum-web/src/domain/admin/Datastores.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default function Datastores() {
164164
};
165165

166166
const fetchDataStores = (): Promise<void> => {
167-
return apiCall(configApi.datastores(curTeam.key), alerting, "FETCH_DATASTORES", "Cannot fetch datastores")
167+
return apiCall(configApi.getDatastoresByTeam(curTeam.key), alerting, "FETCH_DATASTORES", "Cannot fetch datastores")
168168
.then(setDatastores)
169169
}
170170

horreum-web/src/domain/tests/TestSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function TestSettings({ test, onTestIdChange, onModified, funcsRe
6464
const [access, setAccess] = useState<Access>(test?.access || Access.Public)
6565

6666
useEffect( () => {
67-
apiCall(configApi.datastores(owner), alerting, "DATASTORE", "Error occurred fetching datastores")
67+
apiCall(configApi.getDatastoresByTeam(owner), alerting, "DATASTORE", "Error occurred fetching datastores")
6868
.then(ds => setDatastores(ds))
6969
}, [test, owner])
7070

0 commit comments

Comments
 (0)