Skip to content

Commit

Permalink
feat: add product name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Feb 19, 2024
1 parent e7f1e24 commit 2fb6c29
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
80 changes: 41 additions & 39 deletions src/main/helm/crds/permissions.onecx.tkit.org-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,46 @@ spec:
singular: permission
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
appId:
type: string
description:
type: string
name:
type: string
permissions:
additionalProperties:
- name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
appId:
type: string
description:
type: string
name:
type: string
permissions:
additionalProperties:
type: string
additionalProperties:
type: string
type: object
type: object
type: object
type: object
status:
properties:
appId:
type: string
message:
type: string
observedGeneration:
type: integer
response-code:
type: integer
status:
enum:
- ERROR
- UNDEFINED
- UPDATED
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
productName:
type: string
type: object
status:
properties:
appId:
type: string
message:
type: string
observedGeneration:
type: integer
response-code:
type: integer
status:
enum:
- ERROR
- UNDEFINED
- UPDATED
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class PermissionSpec {
@JsonProperty(value = "appId", required = true)
private String appId;

@JsonProperty(value = "productName", required = true)
private String productName;

@JsonProperty(value = "name", required = true)
private String name;

Expand All @@ -20,6 +23,14 @@ public class PermissionSpec {
@JsonProperty("permissions")
private Map<String, Map<String, String>> permissions;

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public String getAppId() {
return appId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PermissionService {
public int updatePermission(Permission permission) {
var spec = permission.getSpec();
var dto = mapper.map(spec);
try (var response = client.createOrUpdatePermission(spec.getAppId(), dto)) {
try (var response = client.createOrUpdatePermission(spec.getProductName(), spec.getAppId(), dto)) {
log.info("Update permission appId {} status {}", spec.getAppId(), response.getStatus());
return response.getStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void testWrongResponse() throws Exception {
p1.put("r1", Map.of("a2", "d1"));

var s = new PermissionSpec();
s.setProductName("test1");
s.setAppId("test-3");
s.setPermissions(p1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void productUpdateEmptySpecTest() {
p1.put("r1", Map.of("a2", "d1"));

var m = new PermissionSpec();
m.setProductName("test1");
m.setAppId("test-3");
m.setPermissions(p1);

Expand Down Expand Up @@ -135,6 +136,7 @@ void productUpdateNoDescriptionTest() {
p1.put("r1", a);

var m = new PermissionSpec();
m.setProductName("test1");
m.setAppId("test-3");
m.setName("test-3");
m.setDescription("description");
Expand All @@ -160,6 +162,7 @@ void productRestClientExceptionTest() {
p1.put("r1", Map.of("a2", "d1"));

var m = new PermissionSpec();
m.setProductName("test1");
m.setAppId("test-error-1");
m.setPermissions(p1);

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/mockserver/permission-mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "3",
"httpRequest": {
"method" : "PUT",
"path": "/operator/v1/update/test-3"
"path": "/operator/v1/test1/test-3"
},
"httpResponse": {
"statusCode": 200
Expand All @@ -13,7 +13,7 @@
"id": "4",
"httpRequest": {
"method" : "PUT",
"path": "/operator/v1/update/test-error-1"
"path": "/operator/v1/test1/test-error-1"
},
"httpResponse": {
"statusCode": 500
Expand Down

0 comments on commit 2fb6c29

Please sign in to comment.