Skip to content

Commit eccf478

Browse files
committed
Removing default values for version
1 parent ee5b72d commit eccf478

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

iam/iam-client/src/main/java/com/salesforce/multicloudj/iam/client/IamClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* // Create policy
3131
* PolicyDocument policy = PolicyDocument.builder()
32-
* .version("2024-01-01")
32+
* .version("2012-10-17") // Use provider-specific version (AWS example)
3333
* .statement("StorageAccess")
3434
* .effect("Allow")
3535
* .addAction("storage:GetObject")

iam/iam-client/src/main/java/com/salesforce/multicloudj/iam/model/PolicyDocument.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <p>Usage example:
1818
* <pre>
1919
* PolicyDocument policy = PolicyDocument.builder()
20-
* .version("2024-01-01")
20+
* .version("2012-10-17") // Use provider-specific version (AWS example)
2121
* .statement("StorageAccess")
2222
* .effect("Allow")
2323
* .addAction("storage:GetObject")
@@ -76,7 +76,7 @@ public String toString() {
7676
* Builder class for PolicyDocument.
7777
*/
7878
public static class Builder {
79-
private String version = "2024-01-01";
79+
private String version;
8080
private final List<Statement> statements = new ArrayList<>();
8181
private Statement.Builder currentStatementBuilder;
8282

@@ -86,7 +86,7 @@ private Builder() {
8686
/**
8787
* Sets the policy version.
8888
*
89-
* @param version the policy version (default: "2024-01-01")
89+
* @param version the policy version (required)
9090
* @return this Builder instance
9191
*/
9292
public Builder version(String version) {
@@ -232,10 +232,13 @@ public Builder addStatement(Statement statement) {
232232
* Builds and returns a PolicyDocument instance.
233233
*
234234
* @return a new PolicyDocument instance
235-
* @throws InvalidArgumentException if no statements are defined
235+
* @throws InvalidArgumentException if version or statements are missing
236236
*/
237237
public PolicyDocument build() {
238238
finalizeCurrentStatement();
239+
if (version == null || version.trim().isEmpty()) {
240+
throw new InvalidArgumentException("version is required");
241+
}
239242
if (statements.isEmpty()) {
240243
throw new InvalidArgumentException("at least one statement is required");
241244
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
public class PolicyDocumentTest {
1717

18+
private static final String TEST_VERSION = "TEST_VERSION";
19+
1820
@Test
1921
public void testPolicyDocumentBuilder() {
2022
PolicyDocument policy = PolicyDocument.builder()
@@ -46,6 +48,7 @@ public void testPolicyDocumentBuilder() {
4648
@Test
4749
public void testMultipleStatements() {
4850
PolicyDocument policy = PolicyDocument.builder()
51+
.version(TEST_VERSION)
4952
.statement("ReadAccess")
5053
.effect("Allow")
5154
.addAction("storage:GetObject")
@@ -73,6 +76,7 @@ public void testAddCompleteStatement() {
7376
.build();
7477

7578
PolicyDocument policy = PolicyDocument.builder()
79+
.version(TEST_VERSION)
7680
.addStatement(statement)
7781
.build();
7882

@@ -87,10 +91,24 @@ public void testEmptyPolicyThrowsException() {
8791
});
8892
}
8993

94+
@Test
95+
public void testMissingVersionThrowsException() {
96+
assertThrows(InvalidArgumentException.class, () -> {
97+
PolicyDocument.builder()
98+
.statement("TestStatement")
99+
.effect("Allow")
100+
.addAction("storage:GetObject")
101+
.addResource("storage://test-bucket/*")
102+
.endStatement()
103+
.build();
104+
});
105+
}
106+
90107
@Test
91108
public void testStatementWithoutEffectThrowsException() {
92109
assertThrows(InvalidArgumentException.class, () -> {
93110
PolicyDocument.builder()
111+
.version(TEST_VERSION)
94112
.statement("TestStatement")
95113
.addAction("storage:GetObject")
96114
.endStatement()
@@ -102,6 +120,7 @@ public void testStatementWithoutEffectThrowsException() {
102120
public void testStatementWithoutActionsThrowsException() {
103121
assertThrows(InvalidArgumentException.class, () -> {
104122
PolicyDocument.builder()
123+
.version(TEST_VERSION)
105124
.statement("TestStatement")
106125
.effect("Allow")
107126
.endStatement()
@@ -125,19 +144,21 @@ public void testVersionHandling() {
125144

126145
// Test default version
127146
PolicyDocument defaultVersionPolicy = PolicyDocument.builder()
147+
.version(TEST_VERSION)
128148
.statement("TestStatement")
129149
.effect("Allow")
130150
.addAction("storage:GetObject")
131151
.addResource("storage://test-bucket/*")
132152
.endStatement()
133153
.build();
134154

135-
assertEquals("2024-01-01", defaultVersionPolicy.getVersion());
155+
assertEquals(TEST_VERSION, defaultVersionPolicy.getVersion());
136156
}
137157

138158
@Test
139159
public void testBuilderMethodsWithMultipleValues() {
140160
PolicyDocument policy = PolicyDocument.builder()
161+
.version(TEST_VERSION)
141162
.statement("TestStatement")
142163
.effect("Allow")
143164
.addAction("storage:GetObject")
@@ -213,6 +234,7 @@ public void testBuilderStateValidation() {
213234
@Test
214235
public void testAddNullStatement() {
215236
PolicyDocument policy = PolicyDocument.builder()
237+
.version(TEST_VERSION)
216238
.addStatement(null)
217239
.statement("ValidStatement")
218240
.effect("Allow")
@@ -235,6 +257,7 @@ public void testMixingAddStatementAndBuilder() {
235257
.build();
236258

237259
PolicyDocument policy = PolicyDocument.builder()
260+
.version(TEST_VERSION)
238261
.addStatement(preBuiltStatement)
239262
.statement("BuiltInline")
240263
.effect("Allow")
@@ -311,6 +334,7 @@ public void testPolicyDocumentToString() {
311334
public void testEndStatementWithoutCurrentStatement() {
312335
// endStatement() should be safe to call even when no statement is being built
313336
PolicyDocument policy = PolicyDocument.builder()
337+
.version(TEST_VERSION)
314338
.endStatement() // This should do nothing
315339
.statement("TestStatement")
316340
.effect("Allow")

0 commit comments

Comments
 (0)