Skip to content

Commit efe2c23

Browse files
authored
Add more option to acceess key create/update (#238)
* Add more option to acceess key create/update fixes #236 * Style fix
1 parent f129101 commit efe2c23

File tree

7 files changed

+64
-14
lines changed

7 files changed

+64
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.descope</groupId>
66
<artifactId>java-sdk</artifactId>
77
<modelVersion>4.0.0</modelVersion>
8-
<version>1.0.51</version>
8+
<version>1.0.52</version>
99
<name>${project.groupId}:${project.artifactId}</name>
1010
<description>Java library used to integrate with Descope.</description>
1111
<url>https://github.com/descope/descope-java</url>

src/main/java/com/descope/model/mgmt/AccessKeyRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
@Builder
1010
public class AccessKeyRequest {
1111
private String name;
12+
private String description;
1213
private long expireTime;
1314
private List<String> roleNames;
1415
private List<Map<String, Object>> keyTenants;
1516
private String userId;
1617
private Map<String, Object> customClaims;
18+
private List<String> permittedIps;
1719
}

src/main/java/com/descope/model/mgmt/AccessKeyResponseDetails.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class AccessKeyResponseDetails {
1515
private String id;
1616
private String name;
17+
private String description;
1718
private List<String> roleNames;
1819
private List<AssociatedTenant> keyTenants;
1920
private String status;
@@ -22,4 +23,5 @@ public class AccessKeyResponseDetails {
2223
private String createdBy;
2324
private String clientId;
2425
private String userId;
26+
private List<String> permittedIps;
2527
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.descope.model.mgmt;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
8+
9+
@Data
10+
@Builder
11+
public class AccessKeyUpdateRequest {
12+
private String id;
13+
private String name;
14+
private String description;
15+
private List<String> roleNames;
16+
private List<Map<String, Object>> keyTenants;
17+
private Map<String, Object> customClaims;
18+
private List<String> permittedIps;
19+
}

src/main/java/com/descope/sdk/mgmt/AccessKeyService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.descope.exception.DescopeException;
44
import com.descope.model.auth.AssociatedTenant;
5+
import com.descope.model.mgmt.AccessKeyRequest;
56
import com.descope.model.mgmt.AccessKeyResponse;
67
import com.descope.model.mgmt.AccessKeyResponseList;
8+
import com.descope.model.mgmt.AccessKeyUpdateRequest;
79
import java.util.List;
810
import java.util.Map;
911

@@ -21,12 +23,16 @@ AccessKeyResponse create(String name, int expireTime, List<String> roleNames, Li
2123
AccessKeyResponse create(String name, int expireTime, List<String> roleNames, List<AssociatedTenant> keyTenants,
2224
String userId, Map<String, Object> customClaims) throws DescopeException;
2325

26+
AccessKeyResponse create(AccessKeyRequest req) throws DescopeException;
27+
2428
AccessKeyResponse load(String id) throws DescopeException;
2529

2630
AccessKeyResponseList searchAll(List<String> tenantIDs) throws DescopeException;
2731

2832
AccessKeyResponse update(String id, String name) throws DescopeException;
2933

34+
AccessKeyResponse update(AccessKeyUpdateRequest req) throws DescopeException;
35+
3036
AccessKeyResponse deactivate(String id) throws DescopeException;
3137

3238
AccessKeyResponse activate(String id) throws DescopeException;

src/main/java/com/descope/sdk/mgmt/impl/AccessKeyServiceImpl.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.descope.model.mgmt.AccessKeyRequest;
1717
import com.descope.model.mgmt.AccessKeyResponse;
1818
import com.descope.model.mgmt.AccessKeyResponseList;
19+
import com.descope.model.mgmt.AccessKeyUpdateRequest;
1920
import com.descope.proxy.ApiProxy;
2021
import com.descope.sdk.mgmt.AccessKeyService;
2122
import com.descope.utils.MgmtUtils;
@@ -57,12 +58,21 @@ public AccessKeyResponse create(
5758
public AccessKeyResponse create(
5859
String name, int expireTime, List<String> roleNames, List<AssociatedTenant> keyTenants, String userId,
5960
Map<String, Object> customClaims) throws DescopeException {
60-
if (StringUtils.isBlank(name)) {
61-
throw ServerCommonException.invalidArgument("Name");
61+
AccessKeyRequest req = createAccessKeyBody(name, expireTime, roleNames, keyTenants, userId, customClaims);
62+
return create(req);
63+
}
64+
65+
@Override
66+
public AccessKeyResponse create(
67+
AccessKeyRequest req) throws DescopeException {
68+
if (req == null) {
69+
throw ServerCommonException.invalidArgument("req");
70+
}
71+
if (StringUtils.isBlank(req.getName())) {
72+
throw ServerCommonException.invalidArgument("req.Name");
6273
}
63-
AccessKeyRequest body = createAccessKeyBody(name, expireTime, roleNames, keyTenants, userId, customClaims);
6474
ApiProxy apiProxy = getApiProxy();
65-
return apiProxy.post(getUri(MANAGEMENT_ACCESS_KEY_CREATE_LINK), body, AccessKeyResponse.class);
75+
return apiProxy.post(getUri(MANAGEMENT_ACCESS_KEY_CREATE_LINK), req, AccessKeyResponse.class);
6676
}
6777

6878
@Override
@@ -87,17 +97,28 @@ public AccessKeyResponseList searchAll(List<String> tenantIDs) throws DescopeExc
8797

8898
@Override
8999
public AccessKeyResponse update(String id, String name) throws DescopeException {
90-
if (StringUtils.isBlank(id)) {
91-
throw ServerCommonException.invalidArgument("Id");
100+
AccessKeyUpdateRequest req = AccessKeyUpdateRequest.builder()
101+
.name(name)
102+
.id(id)
103+
.build();
104+
return update(req);
105+
}
106+
107+
@Override
108+
public AccessKeyResponse update(AccessKeyUpdateRequest req) throws DescopeException {
109+
if (req == null) {
110+
throw ServerCommonException.invalidArgument("req");
111+
}
112+
if (StringUtils.isBlank(req.getId())) {
113+
throw ServerCommonException.invalidArgument("req.Id");
92114
}
93-
if (StringUtils.isBlank(name)) {
94-
throw ServerCommonException.invalidArgument("Name");
115+
if (StringUtils.isBlank(req.getName())) {
116+
throw ServerCommonException.invalidArgument("req.Name");
95117
}
96118

97-
Map<String, String> request = mapOf("id", id, "name", name);
98119
ApiProxy apiProxy = getApiProxy();
99120
return apiProxy.post(
100-
getUri(MANAGEMENT_ACCESS_KEY_UPDATE_LINK), request, AccessKeyResponse.class);
121+
getUri(MANAGEMENT_ACCESS_KEY_UPDATE_LINK), req, AccessKeyResponse.class);
101122
}
102123

103124
@Override

src/test/java/com/descope/sdk/mgmt/impl/AccessKeyServiceImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void testCreateForEmptyName() {
6060
ServerCommonException.class,
6161
() -> accessKeyService.create("", 10, mockRoles, mockKeyTenants));
6262
assertNotNull(thrown);
63-
assertEquals("The Name argument is invalid", thrown.getMessage());
63+
assertEquals("The req.Name argument is invalid", thrown.getMessage());
6464
}
6565

6666
@Test
@@ -100,7 +100,7 @@ void testUpdateForEmptyName() {
100100
ServerCommonException thrown =
101101
assertThrows(ServerCommonException.class, () -> accessKeyService.update("Id", ""));
102102
assertNotNull(thrown);
103-
assertEquals("The Name argument is invalid", thrown.getMessage());
103+
assertEquals("The req.Name argument is invalid", thrown.getMessage());
104104
}
105105

106106
@Test
@@ -120,7 +120,7 @@ void testUpdateForEmptyId() {
120120
ServerCommonException thrown =
121121
assertThrows(ServerCommonException.class, () -> accessKeyService.update("", "Krishna"));
122122
assertNotNull(thrown);
123-
assertEquals("The Id argument is invalid", thrown.getMessage());
123+
assertEquals("The req.Id argument is invalid", thrown.getMessage());
124124
}
125125

126126
@Test

0 commit comments

Comments
 (0)