2121import com .amazonaws .ClientConfiguration ;
2222import com .amazonaws .Protocol ;
2323import com .amazonaws .auth .AWSCredentialsProvider ;
24- import com .amazonaws .auth .EnvironmentVariableCredentialsProvider ;
2524
2625import org .apache .commons .lang3 .StringUtils ;
2726import org .apache .commons .lang3 .tuple .Pair ;
5049import org .slf4j .LoggerFactory ;
5150
5251import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
52+ import software .amazon .awssdk .auth .credentials .EnvironmentVariableCredentialsProvider ;
5353import software .amazon .awssdk .awscore .exception .AwsServiceException ;
5454import software .amazon .awssdk .core .exception .AbortedException ;
5555import software .amazon .awssdk .core .exception .SdkException ;
7676import java .util .Collection ;
7777import java .util .Collections ;
7878import java .util .Date ;
79+ import java .util .HashMap ;
7980import java .util .HashSet ;
8081import java .util .List ;
8182import java .util .Map ;
@@ -621,6 +622,22 @@ public static List<Class<?>> loadAWSProviderClasses(Configuration conf,
621622 }
622623 }
623624
625+ /**
626+ * Maps V1 credential providers to either their equivalent SDK V2 class or hadoop provider.
627+ */
628+ private static Map <String , Class > initCredentialProvidersMap () {
629+ Map <String , Class > v1v2CredentialProviderMap = new HashMap <>();
630+
631+ v1v2CredentialProviderMap .put ("EnvironmentVariableCredentialsProvider" ,
632+ EnvironmentVariableCredentialsProvider .class );
633+ v1v2CredentialProviderMap .put ("EC2ContainerCredentialsProviderWrapper" ,
634+ IAMInstanceCredentialsProvider .class );
635+ v1v2CredentialProviderMap .put ("InstanceProfileCredentialsProvider" ,
636+ IAMInstanceCredentialsProvider .class );
637+
638+ return v1v2CredentialProviderMap ;
639+ }
640+
624641 /**
625642 * Load list of AWS credential provider/credential provider factory classes;
626643 * support a forbidden list to prevent loops, mandate full secrets, etc.
@@ -643,6 +660,8 @@ public static AWSCredentialProviderList buildAWSProviderList(
643660 List <Class <?>> awsClasses = loadAWSProviderClasses (conf ,
644661 key ,
645662 defaultValues .toArray (new Class [defaultValues .size ()]));
663+
664+ Map <String , Class > v1v2CredentialProviderMap = initCredentialProvidersMap ();
646665 // and if the list is empty, switch back to the defaults.
647666 // this is to address the issue that configuration.getClasses()
648667 // doesn't return the default if the config value is just whitespace.
@@ -659,11 +678,11 @@ public static AWSCredentialProviderList buildAWSProviderList(
659678 + " in option " + key + ": " + aClass );
660679 }
661680
662- // TODO: Not sure what to do here yet.
663- // There were some V1 providers for which we suppressed warnings, how do we map those?
664- if ( aClass . getName (). contains ( AWS_AUTH_CLASS_PREFIX )) {
665- // V2Migration.v1ProviderReferenced (aClass.getName( ));
666-
681+ if ( v1v2CredentialProviderMap . containsKey ( aClass . getSimpleName ()) &&
682+ aClass . getName (). contains ( AWS_AUTH_CLASS_PREFIX )){
683+ providers . add ( createAWSV2CredentialProvider ( conf ,
684+ v1v2CredentialProviderMap . get (aClass .getSimpleName ()), binding ));
685+ } else if ( AWSCredentialsProvider . class . isAssignableFrom ( aClass )) {
667686 providers .add (createAWSV1CredentialProvider (conf ,
668687 aClass , binding ));
669688 } else {
@@ -823,7 +842,7 @@ private static AwsCredentialsProvider createAWSV2CredentialProvider(
823842
824843 // X.getInstance()
825844 Method factory = getFactoryMethod (credClass , AwsCredentialsProvider .class ,
826- "getInstance " );
845+ "create " );
827846 if (factory != null ) {
828847 credentials = (AwsCredentialsProvider )factory .invoke (null );
829848 return credentials ;
@@ -840,7 +859,7 @@ private static AwsCredentialsProvider createAWSV2CredentialProvider(
840859 throw new IOException (String .format ("%s " + CONSTRUCTOR_EXCEPTION
841860 + ". A class specified in %s must provide a public constructor "
842861 + "of a supported signature, or a public factory method named "
843- + "getInstance that accepts no arguments." ,
862+ + "create that accepts no arguments." ,
844863 className , AWS_CREDENTIALS_PROVIDER ));
845864 } catch (InvocationTargetException e ) {
846865 // TODO: Can probably be moved to a common method, but before doing this, check if we still
0 commit comments