Skip to content

Commit be140af

Browse files
committed
Using lombok builder and control policy
1 parent 1bb588e commit be140af

File tree

2 files changed

+9
-77
lines changed

2 files changed

+9
-77
lines changed
Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.salesforce.multicloudj.iam.model;
22

3+
import lombok.Builder;
34
import lombok.Getter;
45

56
import java.util.Objects;
@@ -13,7 +14,7 @@
1314
* <p>Permission boundary identifiers are provider-specific and translated internally:
1415
* - AWS: IAM Policy ARN format (arn:aws:iam::account:policy/name)
1516
* - GCP: Organization Policy constraint name or IAM Condition expression
16-
* - AliCloud: Not supported (AliCloud RAM does not have permission boundaries)
17+
* - AliCloud: Control Policy name or ID (Resource Directory Control Policies)
1718
*
1819
* <p>Usage examples by provider:
1920
* <pre>
@@ -31,35 +32,21 @@
3132
* .permissionBoundary("constraints/compute.restrictLoadBalancerCreationForTypes")
3233
* .build();
3334
*
34-
* // AliCloud Example (permission boundaries not supported)
35+
* // AliCloud Example (using Control Policy)
3536
* CreateOptions aliOptions = CreateOptions.builder()
3637
* .path("/foo/")
3738
* .maxSessionDuration(7200) // 2 hours
38-
* // .permissionBoundary() - Not supported in AliCloud RAM
39+
* .permissionBoundary("cp-bp1example") // Control Policy ID
3940
* .build();
4041
* </pre>
4142
*/
4243
@Getter
44+
@Builder
4345
public class CreateOptions {
4446
private final String path;
4547
private final Integer maxSessionDuration;
4648
private final String permissionBoundary;
4749

48-
private CreateOptions(Builder builder) {
49-
this.path = builder.path;
50-
this.maxSessionDuration = builder.maxSessionDuration;
51-
this.permissionBoundary = builder.permissionBoundary;
52-
}
53-
54-
/**
55-
* Creates a new builder for CreateOptions.
56-
*
57-
* @return a new Builder instance
58-
*/
59-
public static Builder builder() {
60-
return new Builder();
61-
}
62-
6350

6451
@Override
6552
public boolean equals(Object o) {
@@ -84,59 +71,4 @@ public String toString() {
8471
", permissionBoundary='" + permissionBoundary + '\'' +
8572
'}';
8673
}
87-
88-
/**
89-
* Builder class for CreateOptions.
90-
*/
91-
public static class Builder {
92-
private String path;
93-
private Integer maxSessionDuration;
94-
private String permissionBoundary;
95-
96-
private Builder() {
97-
}
98-
99-
/**
100-
* Sets the path for the identity.
101-
*
102-
* @param path the path (e.g., "/foo/") for organizing identities
103-
* @return this Builder instance
104-
*/
105-
public Builder path(String path) {
106-
this.path = path;
107-
return this;
108-
}
109-
110-
/**
111-
* Sets the maximum session duration in seconds.
112-
*
113-
* @param maxSessionDuration the maximum session duration (typically up to 12 hours = 43200 seconds)
114-
* @return this Builder instance
115-
*/
116-
public Builder maxSessionDuration(Integer maxSessionDuration) {
117-
this.maxSessionDuration = maxSessionDuration;
118-
return this;
119-
}
120-
121-
/**
122-
* Sets the permission boundary policy identifier.
123-
*
124-
* @param permissionBoundary the cloud-native identifier of the policy that acts as a permission boundary
125-
* (AWS: policy ARN, GCP: constraint name, AliCloud: not supported)
126-
* @return this Builder instance
127-
*/
128-
public Builder permissionBoundary(String permissionBoundary) {
129-
this.permissionBoundary = permissionBoundary;
130-
return this;
131-
}
132-
133-
/**
134-
* Builds and returns a CreateOptions instance.
135-
*
136-
* @return a new CreateOptions instance
137-
*/
138-
public CreateOptions build() {
139-
return new CreateOptions(this);
140-
}
141-
}
14274
}

iam/iam-client/src/test/java/com/salesforce/multicloudj/iam/model/CreateOptionsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void testCreateOptionsToString() {
182182

183183
@Test
184184
public void testCreateOptionsBuilderMethodChaining() {
185-
CreateOptions.Builder builder = CreateOptions.builder();
185+
CreateOptions.CreateOptionsBuilder builder = CreateOptions.builder();
186186

187187
// Test that each method returns the same builder instance
188188
assertSame(builder, builder.path("/test/"));
@@ -244,15 +244,15 @@ public void testCreateOptionsBuilderProviderSpecificExamples() {
244244
assertEquals(Integer.valueOf(3600), gcpOptions.getMaxSessionDuration());
245245
assertEquals("constraints/compute.restrictLoadBalancerCreationForTypes", gcpOptions.getPermissionBoundary());
246246

247-
// AliCloud Example (permission boundaries not supported)
247+
// AliCloud Example (using Control Policy)
248248
CreateOptions aliOptions = CreateOptions.builder()
249249
.path("/foo/")
250250
.maxSessionDuration(7200) // 2 hours
251-
// Permission boundaries not supported in AliCloud RAM
251+
.permissionBoundary("cp-bp1example") // Control Policy ID
252252
.build();
253253

254254
assertEquals("/foo/", aliOptions.getPath());
255255
assertEquals(Integer.valueOf(7200), aliOptions.getMaxSessionDuration());
256-
assertNull(aliOptions.getPermissionBoundary()); // AliCloud doesn't support permission boundaries
256+
assertEquals("cp-bp1example", aliOptions.getPermissionBoundary()); // AliCloud Control Policy
257257
}
258258
}

0 commit comments

Comments
 (0)