Skip to content

Commit 68fc237

Browse files
narinder-kaurNarinder
and
Narinder
authoredApr 4, 2022
feat(IAM Access Groups): add support for dynamic membership (#143)
Co-authored-by: Narinder <narinde.kaur1@ibm.com>
1 parent 2451ad8 commit 68fc237

File tree

13 files changed

+614
-655
lines changed

13 files changed

+614
-655
lines changed
 

‎modules/examples/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/IamAccessGroupsExamples.java

+32-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
// IAM_ACCESS_GROUPS_APIKEY=<your iam apikey>
6464
// IAM_ACCESS_GROUPS_AUTH_URL=<IAM token service URL - omit this if using the production environment>
6565
// IAM_ACCESS_GROUPS_TEST_ACCOUNT_ID=<id of an account used for testing>
66+
// IAM_ACCESS_GROUPS_TEST_PROFILE_ID=<id of an profile used for testing>
6667
//
6768
// These configuration properties can be exported as environment variables, or stored
6869
// in a configuration file and then:
@@ -73,13 +74,14 @@ public class IamAccessGroupsExamples {
7374
protected IamAccessGroupsExamples() { }
7475

7576
private static String testAccountId = null;
77+
private static String testProfileId = null;
7678
private static String testGroupId = null;
7779
private static String testGroupETag = null;
7880
private static String testClaimRuleId = null;
7981
private static String testClaimRuleETag = null;
8082

8183
static {
82-
System.setProperty("IBM_CREDENTIALS_FILE", "../../iam_access_groups.env");
84+
System.setProperty("IBM_CREDENTIALS_FILE", "../../iam_access_groups_v2.env");
8385
}
8486

8587
public static void main(String[] args) throws Exception {
@@ -88,6 +90,7 @@ public static void main(String[] args) throws Exception {
8890
// Load up our test-specific config properties.
8991
Map<String, String> config = CredentialUtils.getServiceProperties(IamAccessGroups.DEFAULT_SERVICE_NAME);
9092
testAccountId = config.get("TEST_ACCOUNT_ID");
93+
testProfileId = config.get("TEST_PROFILE_ID");
9194

9295
try {
9396
System.out.println("createAccessGroup() result:");
@@ -193,10 +196,15 @@ public static void main(String[] args) throws Exception {
193196
.iamId("iam-ServiceId-123")
194197
.type("service")
195198
.build();
199+
AddGroupMembersRequestMembersItem member3 = new AddGroupMembersRequestMembersItem.Builder()
200+
.iamId(testProfileId)
201+
.type("profile")
202+
.build();
196203
AddMembersToAccessGroupOptions addMembersToAccessGroupOptions = new AddMembersToAccessGroupOptions.Builder()
197204
.accessGroupId(testGroupId)
198205
.addMembers(member1)
199206
.addMembers(member2)
207+
.addMembers(member3)
200208
.build();
201209
Response<AddGroupMembersResponse> response = service.addMembersToAccessGroup(addMembersToAccessGroupOptions).execute();
202210
AddGroupMembersResponse addGroupMembersResponse = response.getResult();
@@ -291,6 +299,28 @@ public static void main(String[] args) throws Exception {
291299
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
292300
}
293301

302+
try {
303+
System.out.println("removeMembersFromAccessGroup() result:");
304+
305+
// begin-remove_members_from_access_group
306+
307+
RemoveMembersFromAccessGroupOptions removeMembersFromAccessGroupOptions = new RemoveMembersFromAccessGroupOptions.Builder()
308+
.accessGroupId(testGroupId)
309+
.addMembers(testProfileId)
310+
.build();
311+
312+
Response<DeleteGroupBulkMembersResponse> response = service.removeMembersFromAccessGroup(removeMembersFromAccessGroupOptions).execute();
313+
// DeleteGroupBulkMembersResponse deleteGroupBulkMembersResponse = response.getResult();
314+
315+
// System.out.println(deleteGroupBulkMembersResponse);
316+
317+
// end-remove_members_from_access_group
318+
319+
} catch (ServiceResponseException e) {
320+
logger.error(String.format("Profile returned status code %s: %s\nError details: %s",
321+
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
322+
}
323+
294324
try {
295325
System.out.println("addMemberToMultipleAccessGroups() result:");
296326

@@ -351,7 +381,7 @@ public static void main(String[] args) throws Exception {
351381
.accessGroupId(testGroupId)
352382
.name("Manager group rule")
353383
.expiration(12)
354-
.realmName("https://idp.example.org/SAML2")
384+
.realmName("https://idp.example.org/SAML5")
355385
.addConditions(ruleConditionsModel)
356386
.build();
357387

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/IamAccessGroups.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
/*
15-
* IBM OpenAPI SDK Code Generator Version: 3.43.4-432d779b-20220119-173927
15+
* IBM OpenAPI SDK Code Generator Version: 3.46.1-a5569134-20220316-164819
1616
*/
1717

1818
package com.ibm.cloud.platform_services.iam_access_groups.v2;
@@ -169,6 +169,9 @@ public ServiceCall<GroupsList> listAccessGroups(ListAccessGroupsOptions listAcce
169169
if (listAccessGroupsOptions.iamId() != null) {
170170
builder.query("iam_id", String.valueOf(listAccessGroupsOptions.iamId()));
171171
}
172+
if (listAccessGroupsOptions.membershipType() != null) {
173+
builder.query("membership_type", String.valueOf(listAccessGroupsOptions.membershipType()));
174+
}
172175
if (listAccessGroupsOptions.limit() != null) {
173176
builder.query("limit", String.valueOf(listAccessGroupsOptions.limit()));
174177
}
@@ -291,9 +294,9 @@ public ServiceCall<Void> deleteAccessGroup(DeleteAccessGroupOptions deleteAccess
291294
/**
292295
* Check membership in an access group.
293296
*
294-
* This HEAD operation determines if a given `iam_id` is present in a group. No response body is returned with this
295-
* request. If the membership exists, a `204 - No Content` status code is returned. If the membership or the group
296-
* does not exist, a `404 - Not Found` status code is returned.
297+
* This HEAD operation determines if a given `iam_id` is present in a group either explicitly or via dynamic rules. No
298+
* response body is returned with this request. If the membership exists, a `204 - No Content` status code is
299+
* returned. If the membership or the group does not exist, a `404 - Not Found` status code is returned.
297300
*
298301
* @param isMemberOfAccessGroupOptions the {@link IsMemberOfAccessGroupOptions} containing the options for the call
299302
* @return a {@link ServiceCall} with a void result
@@ -377,6 +380,9 @@ public ServiceCall<GroupMembersList> listAccessGroupMembers(ListAccessGroupMembe
377380
if (listAccessGroupMembersOptions.transactionId() != null) {
378381
builder.header("Transaction-Id", listAccessGroupMembersOptions.transactionId());
379382
}
383+
if (listAccessGroupMembersOptions.membershipType() != null) {
384+
builder.query("membership_type", String.valueOf(listAccessGroupMembersOptions.membershipType()));
385+
}
380386
if (listAccessGroupMembersOptions.limit() != null) {
381387
builder.query("limit", String.valueOf(listAccessGroupMembersOptions.limit()));
382388
}
@@ -401,7 +407,8 @@ public ServiceCall<GroupMembersList> listAccessGroupMembers(ListAccessGroupMembe
401407
* Delete member from an access group.
402408
*
403409
* Remove one member from a group using this API. If the operation is successful, only a `204 - No Content` response
404-
* with no body is returned. However, if any error occurs, the standard error format will be returned.
410+
* with no body is returned. However, if any error occurs, the standard error format will be returned. Dynamic member
411+
* cannot be deleted using this API. Dynamic rules needs to be adjusted to delete dynamic members.
405412
*
406413
* @param removeMemberFromAccessGroupOptions the {@link RemoveMemberFromAccessGroupOptions} containing the options for the call
407414
* @return a {@link ServiceCall} with a void result
@@ -429,7 +436,8 @@ public ServiceCall<Void> removeMemberFromAccessGroup(RemoveMemberFromAccessGroup
429436
*
430437
* Remove multiple members from a group using this API. On a successful call, this API will always return 207. It is
431438
* the caller's responsibility to iterate across the body to determine successful deletion of each member. This API
432-
* request payload can delete up to 50 members per call.
439+
* request payload can delete up to 50 members per call. This API doesnt delete dynamic members accessing the access
440+
* group via dynamic rules.
433441
*
434442
* @param removeMembersFromAccessGroupOptions the {@link RemoveMembersFromAccessGroupOptions} containing the options for the call
435443
* @return a {@link ServiceCall} with a result of type {@link DeleteGroupBulkMembersResponse}

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/AddGroupMembersRequestMembersItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public Builder newBuilder() {
106106
/**
107107
* Gets the iamId.
108108
*
109-
* The IBMid, Service Id or Profile Id of the member.
109+
* The IBMid, service ID or trusted profile ID of the member.
110110
*
111111
* @return the iamId
112112
*/

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/Group.java

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Group extends GenericModel {
3838
protected String href;
3939
@SerializedName("is_federated")
4040
protected Boolean isFederated;
41+
@SerializedName("membership_type")
42+
protected String membershipType;
4143

4244
/**
4345
* Gets the id.
@@ -148,5 +150,16 @@ public String getHref() {
148150
public Boolean isIsFederated() {
149151
return isFederated;
150152
}
153+
154+
/**
155+
* Gets the membershipType.
156+
*
157+
* Type of the membership. `static` or `dynamic`.
158+
*
159+
* @return the membershipType
160+
*/
161+
public String getMembershipType() {
162+
return membershipType;
163+
}
151164
}
152165

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListAccessGroupMembersOptions.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ListAccessGroupMembersOptions extends GenericModel {
2121

2222
protected String accessGroupId;
2323
protected String transactionId;
24+
protected String membershipType;
2425
protected Long limit;
2526
protected Long offset;
2627
protected String type;
@@ -33,6 +34,7 @@ public class ListAccessGroupMembersOptions extends GenericModel {
3334
public static class Builder {
3435
private String accessGroupId;
3536
private String transactionId;
37+
private String membershipType;
3638
private Long limit;
3739
private Long offset;
3840
private String type;
@@ -42,6 +44,7 @@ public static class Builder {
4244
private Builder(ListAccessGroupMembersOptions listAccessGroupMembersOptions) {
4345
this.accessGroupId = listAccessGroupMembersOptions.accessGroupId;
4446
this.transactionId = listAccessGroupMembersOptions.transactionId;
47+
this.membershipType = listAccessGroupMembersOptions.membershipType;
4548
this.limit = listAccessGroupMembersOptions.limit;
4649
this.offset = listAccessGroupMembersOptions.offset;
4750
this.type = listAccessGroupMembersOptions.type;
@@ -95,6 +98,17 @@ public Builder transactionId(String transactionId) {
9598
return this;
9699
}
97100

101+
/**
102+
* Set the membershipType.
103+
*
104+
* @param membershipType the membershipType
105+
* @return the ListAccessGroupMembersOptions builder
106+
*/
107+
public Builder membershipType(String membershipType) {
108+
this.membershipType = membershipType;
109+
return this;
110+
}
111+
98112
/**
99113
* Set the limit.
100114
*
@@ -156,6 +170,7 @@ protected ListAccessGroupMembersOptions(Builder builder) {
156170
"accessGroupId cannot be empty");
157171
accessGroupId = builder.accessGroupId;
158172
transactionId = builder.transactionId;
173+
membershipType = builder.membershipType;
159174
limit = builder.limit;
160175
offset = builder.offset;
161176
type = builder.type;
@@ -196,6 +211,19 @@ public String transactionId() {
196211
return transactionId;
197212
}
198213

214+
/**
215+
* Gets the membershipType.
216+
*
217+
* Filters members by membership type. Membership type can be either `static`, `dynamic` or `all`. `static` lists
218+
* those members explicitly added to the access group, `dynamic` lists those members part of access group via dynamic
219+
* rules at the moment. `all` lists both static and dynamic members.
220+
*
221+
* @return the membershipType
222+
*/
223+
public String membershipType() {
224+
return membershipType;
225+
}
226+
199227
/**
200228
* Gets the limit.
201229
*
@@ -232,7 +260,7 @@ public String type() {
232260
/**
233261
* Gets the verbose.
234262
*
235-
* Return user's email and name for each user id or the name for each service id or trusted profile.
263+
* Return user's email and name for each user ID or the name for each service ID or trusted profile.
236264
*
237265
* @return the verbose
238266
*/

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListAccessGroupsOptions.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ListAccessGroupsOptions extends GenericModel {
2222
protected String accountId;
2323
protected String transactionId;
2424
protected String iamId;
25+
protected String membershipType;
2526
protected Long limit;
2627
protected Long offset;
2728
protected String sort;
@@ -35,6 +36,7 @@ public static class Builder {
3536
private String accountId;
3637
private String transactionId;
3738
private String iamId;
39+
private String membershipType;
3840
private Long limit;
3941
private Long offset;
4042
private String sort;
@@ -45,6 +47,7 @@ private Builder(ListAccessGroupsOptions listAccessGroupsOptions) {
4547
this.accountId = listAccessGroupsOptions.accountId;
4648
this.transactionId = listAccessGroupsOptions.transactionId;
4749
this.iamId = listAccessGroupsOptions.iamId;
50+
this.membershipType = listAccessGroupsOptions.membershipType;
4851
this.limit = listAccessGroupsOptions.limit;
4952
this.offset = listAccessGroupsOptions.offset;
5053
this.sort = listAccessGroupsOptions.sort;
@@ -109,6 +112,17 @@ public Builder iamId(String iamId) {
109112
return this;
110113
}
111114

115+
/**
116+
* Set the membershipType.
117+
*
118+
* @param membershipType the membershipType
119+
* @return the ListAccessGroupsOptions builder
120+
*/
121+
public Builder membershipType(String membershipType) {
122+
this.membershipType = membershipType;
123+
return this;
124+
}
125+
112126
/**
113127
* Set the limit.
114128
*
@@ -171,6 +185,7 @@ protected ListAccessGroupsOptions(Builder builder) {
171185
accountId = builder.accountId;
172186
transactionId = builder.transactionId;
173187
iamId = builder.iamId;
188+
membershipType = builder.membershipType;
174189
limit = builder.limit;
175190
offset = builder.offset;
176191
sort = builder.sort;
@@ -216,14 +231,28 @@ public String transactionId() {
216231
/**
217232
* Gets the iamId.
218233
*
219-
* Return groups for member id (IBMid, Service Id or Profile Id).
234+
* Return groups for member ID (IBMid, service ID or trusted profile ID).
220235
*
221236
* @return the iamId
222237
*/
223238
public String iamId() {
224239
return iamId;
225240
}
226241

242+
/**
243+
* Gets the membershipType.
244+
*
245+
* Membership type need to be specified along with iam_id and must be either `static`, `dynamic` or `all`. If
246+
* membership type is `static`, members explicitly added to the group will be shown. If membership type is `dynamic`,
247+
* members accessing the access group at the moment via dynamic rules will be shown. If membership type is `all`, both
248+
* static and dynamic members will be shown.
249+
*
250+
* @return the membershipType
251+
*/
252+
public String membershipType() {
253+
return membershipType;
254+
}
255+
227256
/**
228257
* Gets the limit.
229258
*

‎modules/iam-access-groups/src/main/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListGroupMembersResponseMember.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class ListGroupMembersResponseMember extends GenericModel {
2525
@SerializedName("iam_id")
2626
protected String iamId;
2727
protected String type;
28+
@SerializedName("membership_type")
29+
protected String membershipType;
2830
protected String name;
2931
protected String email;
3032
protected String description;
@@ -48,14 +50,25 @@ public String getIamId() {
4850
/**
4951
* Gets the type.
5052
*
51-
* The member type - either `user` or `service`.
53+
* The member type - either `user`, `service` or `profile`.
5254
*
5355
* @return the type
5456
*/
5557
public String getType() {
5658
return type;
5759
}
5860

61+
/**
62+
* Gets the membershipType.
63+
*
64+
* The membership type - either `static` or `dynamic`.
65+
*
66+
* @return the membershipType
67+
*/
68+
public String getMembershipType() {
69+
return membershipType;
70+
}
71+
5972
/**
6073
* Gets the name.
6174
*

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/IamAccessGroupsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class IamAccessGroupsIT extends SdkIntegrationTestBase {
8787

8888
@Override
8989
public String getConfigFilename() {
90-
return "../../iam_access_groups.env";
90+
return "../../iam_access_groups_v2.env";
9191
}
9292

9393
@Override

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/IamAccessGroupsTest.java

+474-642
Large diffs are not rendered by default.

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/GroupTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ public void testGroup() throws Throwable {
3838
assertNull(groupModel.getAccountId());
3939
assertNull(groupModel.getHref());
4040
assertNull(groupModel.isIsFederated());
41+
assertNull(groupModel.getMembershipType());
4142
}
4243
}

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListAccessGroupMembersOptionsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void testListAccessGroupMembersOptions() throws Throwable {
3434
ListAccessGroupMembersOptions listAccessGroupMembersOptionsModel = new ListAccessGroupMembersOptions.Builder()
3535
.accessGroupId("testString")
3636
.transactionId("testString")
37+
.membershipType("static")
3738
.limit(Long.valueOf("26"))
3839
.offset(Long.valueOf("26"))
3940
.type("testString")
@@ -42,6 +43,7 @@ public void testListAccessGroupMembersOptions() throws Throwable {
4243
.build();
4344
assertEquals(listAccessGroupMembersOptionsModel.accessGroupId(), "testString");
4445
assertEquals(listAccessGroupMembersOptionsModel.transactionId(), "testString");
46+
assertEquals(listAccessGroupMembersOptionsModel.membershipType(), "static");
4547
assertEquals(listAccessGroupMembersOptionsModel.limit(), Long.valueOf("26"));
4648
assertEquals(listAccessGroupMembersOptionsModel.offset(), Long.valueOf("26"));
4749
assertEquals(listAccessGroupMembersOptionsModel.type(), "testString");

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListAccessGroupsOptionsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void testListAccessGroupsOptions() throws Throwable {
3535
.accountId("testString")
3636
.transactionId("testString")
3737
.iamId("testString")
38+
.membershipType("static")
3839
.limit(Long.valueOf("26"))
3940
.offset(Long.valueOf("26"))
4041
.sort("name")
@@ -44,6 +45,7 @@ public void testListAccessGroupsOptions() throws Throwable {
4445
assertEquals(listAccessGroupsOptionsModel.accountId(), "testString");
4546
assertEquals(listAccessGroupsOptionsModel.transactionId(), "testString");
4647
assertEquals(listAccessGroupsOptionsModel.iamId(), "testString");
48+
assertEquals(listAccessGroupsOptionsModel.membershipType(), "static");
4749
assertEquals(listAccessGroupsOptionsModel.limit(), Long.valueOf("26"));
4850
assertEquals(listAccessGroupsOptionsModel.offset(), Long.valueOf("26"));
4951
assertEquals(listAccessGroupsOptionsModel.sort(), "name");

‎modules/iam-access-groups/src/test/java/com/ibm/cloud/platform_services/iam_access_groups/v2/model/ListGroupMembersResponseMemberTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void testListGroupMembersResponseMember() throws Throwable {
3434
ListGroupMembersResponseMember listGroupMembersResponseMemberModel = new ListGroupMembersResponseMember();
3535
assertNull(listGroupMembersResponseMemberModel.getIamId());
3636
assertNull(listGroupMembersResponseMemberModel.getType());
37+
assertNull(listGroupMembersResponseMemberModel.getMembershipType());
3738
assertNull(listGroupMembersResponseMemberModel.getName());
3839
assertNull(listGroupMembersResponseMemberModel.getEmail());
3940
assertNull(listGroupMembersResponseMemberModel.getDescription());

0 commit comments

Comments
 (0)
Please sign in to comment.