Skip to content

Commit 06cc84e

Browse files
committed
Apply suggestions
1 parent ae6b8a3 commit 06cc84e

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

.github/workflows/permission-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ jobs:
115115
uses: actions/upload-artifact@v4
116116
with:
117117
name: dynamo_permission_integration_test_reports
118-
path: core/build/reports/tests/integrationTestDynamoPermission
118+
path: core/build/reports/tests/integrationTestDynamoPermission

core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ dependencies {
140140
implementation platform("software.amazon.awssdk:bom:${awssdkVersion}")
141141
implementation 'software.amazon.awssdk:applicationautoscaling'
142142
implementation 'software.amazon.awssdk:dynamodb'
143-
implementation 'software.amazon.awssdk:iam'
144-
implementation 'software.amazon.awssdk:iam-policy-builder'
143+
testImplementation 'software.amazon.awssdk:iam'
144+
testImplementation 'software.amazon.awssdk:iam-policy-builder'
145145
implementation "org.apache.commons:commons-dbcp2:${commonsDbcp2Version}"
146146
implementation "com.mysql:mysql-connector-j:${mysqlDriverVersion}"
147147
implementation "org.postgresql:postgresql:${postgresqlDriverVersion}"

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoPermissionTestUtils.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Properties;
77
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
88
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
9+
import software.amazon.awssdk.core.exception.SdkException;
910
import software.amazon.awssdk.policybuilder.iam.IamEffect;
1011
import software.amazon.awssdk.policybuilder.iam.IamPolicy;
1112
import software.amazon.awssdk.policybuilder.iam.IamResource;
@@ -79,18 +80,34 @@ public void grantRequiredPermission(String userName) {
7980
User user = client.getUser().user();
8081
Optional<String> attachedPolicyArn = getAttachedPolicyArn(user.userName());
8182
if (attachedPolicyArn.isPresent()) {
82-
deleteStalePolicyVersions(attachedPolicyArn.get());
83-
createNewPolicyVersion(attachedPolicyArn.get());
83+
String policyArn = attachedPolicyArn.get();
84+
try {
85+
deleteStalePolicyVersions(policyArn);
86+
createNewPolicyVersion(policyArn);
87+
} catch (SdkException e) {
88+
throw new RuntimeException(
89+
String.format(
90+
"Failed to update policy for user: %s, policyArn: %s", userName, policyArn),
91+
e);
92+
}
8493
} else {
8594
String policyArn = createNewPolicy();
86-
client.attachUserPolicy(
87-
AttachUserPolicyRequest.builder()
88-
.userName(user.userName())
89-
.policyArn(policyArn)
90-
.build());
95+
try {
96+
client.attachUserPolicy(
97+
AttachUserPolicyRequest.builder()
98+
.userName(user.userName())
99+
.policyArn(policyArn)
100+
.build());
101+
} catch (SdkException e) {
102+
throw new RuntimeException(
103+
String.format(
104+
"Failed to attach new policy for user: %s, policyArn: %s", userName, policyArn),
105+
e);
106+
}
91107
}
92-
} catch (Exception e) {
93-
throw new RuntimeException("Failed to grant required permissions", e);
108+
} catch (SdkException e) {
109+
throw new RuntimeException(
110+
String.format("Failed to grant required permissions for user: %s", userName), e);
94111
}
95112
}
96113

0 commit comments

Comments
 (0)