You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/10/21 14:07:31 UTC

[GitHub] [beam] mosche commented on a diff in pull request #23553: Support usage of custom profileName with AWS ProfileCredentialsProvider

mosche commented on code in PR #23553:
URL: https://github.com/apache/beam/pull/23553#discussion_r1001834204


##########
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/options/AwsModule.java:
##########
@@ -228,6 +232,22 @@ public void serializeWithType(
           jsonGenerator.writeStringField(ACCESS_KEY_ID, credentials.accessKeyId());
           jsonGenerator.writeStringField(SECRET_ACCESS_KEY, credentials.secretAccessKey());
         }
+      } else if (providerClass.equals(ProfileCredentialsProvider.class)) {
+        String profileName = (String) readField(credentialsProvider, PROFILE_NAME);
+        String envProfileName = ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
+        if (profileName != null && !profileName.equals(envProfileName)) {
+          jsonGenerator.writeStringField(PROFILE_NAME, profileName);
+        }
+        try {
+          Exception exception = (Exception) readField(credentialsProvider, "loadException");
+          if (exception != null) {
+            LoggerFactory.getLogger(AwsModule.class)
+                .warn("Serialized ProfileCredentialsProvider in faulty state.", exception);
+          }
+        } catch (RuntimeException e) {
+          // can be ignored

Review Comment:
   The `ProfileCredentialsProvider` eagerly tries to load the profile when it is initialized. Any related error is stored in `loadException` and thrown later by the provider when attempting to get the credentials. This exception, if it exists, is logged for information purpose to give the user some hint in case the credentials provider behaves in a strange way: 
   
   As shown in tests, the provider might silently omit the provided profileName when it doesn't exist. On the other hand, despite any `loadException`, getting credentials might also just work fine on workers if an appropriate profile exists there. 
   
   
   Last, `loadException` is a private field of the provider and extracting it might fail, e.g. if renamed in a different SDK version used at runtime. But logging it is not critical in any way...
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org