@@ -82,8 +82,7 @@ public S3Client s3() {
8282 .applyMutation (s3FileIOProperties ()::applyEndpointConfigurations )
8383 .applyMutation (s3FileIOProperties ()::applyServiceConfigurations )
8484 .applyMutation (s3FileIOProperties ()::applyRetryConfigurations )
85- .credentialsProvider (
86- new LakeFormationCredentialsProvider (lakeFormation (), buildTableArn ()))
85+ .credentialsProvider (lakeFormationCredentialsProvider ())
8786 .region (Region .of (region ()))
8887 .build ();
8988 } else {
@@ -97,16 +96,15 @@ public KmsClient kms() {
9796 return KmsClient .builder ()
9897 .applyMutation (httpClientProperties ()::applyHttpClientConfigurations )
9998 .applyMutation (awsClientProperties ()::applyRetryConfigurations )
100- .credentialsProvider (
101- new LakeFormationCredentialsProvider (lakeFormation (), buildTableArn ()))
99+ .credentialsProvider (lakeFormationCredentialsProvider ())
102100 .region (Region .of (region ()))
103101 .build ();
104102 } else {
105103 return super .kms ();
106104 }
107105 }
108106
109- private boolean isTableRegisteredWithLakeFormation () {
107+ protected boolean isTableRegisteredWithLakeFormation () {
110108 Preconditions .checkArgument (
111109 dbName != null && !dbName .isEmpty (), "Database name can not be empty" );
112110 Preconditions .checkArgument (
@@ -120,10 +118,17 @@ private boolean isTableRegisteredWithLakeFormation() {
120118 .databaseName (dbName )
121119 .name (tableName )
122120 .build ());
123- return response .table ().isRegisteredWithLakeFormation ();
121+ boolean isRegisteredWithLakeFormation = response .table ().isRegisteredWithLakeFormation ();
122+ if (isRegisteredWithLakeFormation ) {
123+ // set the Glue account id, if not set
124+ if (this .glueAccountId == null ) {
125+ this .glueAccountId = response .table ().catalogId ();
126+ }
127+ }
128+ return isRegisteredWithLakeFormation ;
124129 }
125130
126- private String buildTableArn () {
131+ protected String buildTableArn () {
127132 Preconditions .checkArgument (
128133 glueAccountId != null && !glueAccountId .isEmpty (),
129134 "%s can not be empty" ,
@@ -133,13 +138,17 @@ private String buildTableArn() {
133138 "arn:%s:glue:%s:%s:table/%s/%s" , partitionName , region (), glueAccountId , dbName , tableName );
134139 }
135140
136- private LakeFormationClient lakeFormation () {
141+ protected LakeFormationClient lakeFormation () {
137142 return LakeFormationClient .builder ()
138143 .applyMutation (this ::applyAssumeRoleConfigurations )
139144 .applyMutation (httpClientProperties ()::applyHttpClientConfigurations )
140145 .build ();
141146 }
142147
148+ protected AwsCredentialsProvider lakeFormationCredentialsProvider () {
149+ return new LakeFormationCredentialsProvider (lakeFormation (), buildTableArn ());
150+ }
151+
143152 static class LakeFormationCredentialsProvider implements AwsCredentialsProvider {
144153 private final LakeFormationClient client ;
145154 private final String tableArn ;
0 commit comments