Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTF-1795. Made some changes to allow the LakeFormationAwsClientFactor… #1

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public S3Client s3() {
.applyMutation(httpClientProperties()::applyHttpClientConfigurations)
.applyMutation(s3FileIOProperties()::applyEndpointConfigurations)
.applyMutation(s3FileIOProperties()::applyServiceConfigurations)
.credentialsProvider(
new LakeFormationCredentialsProvider(lakeFormation(), buildTableArn()))
.credentialsProvider(lakeFormationCredentialsProvider())
.region(Region.of(region()))
.build();
} else {
Expand All @@ -95,16 +94,15 @@ public KmsClient kms() {
if (isTableRegisteredWithLakeFormation()) {
return KmsClient.builder()
.applyMutation(httpClientProperties()::applyHttpClientConfigurations)
.credentialsProvider(
new LakeFormationCredentialsProvider(lakeFormation(), buildTableArn()))
.credentialsProvider(lakeFormationCredentialsProvider())
.region(Region.of(region()))
.build();
} else {
return super.kms();
}
}

private boolean isTableRegisteredWithLakeFormation() {
protected boolean isTableRegisteredWithLakeFormation() {
Preconditions.checkArgument(
dbName != null && !dbName.isEmpty(), "Database name can not be empty");
Preconditions.checkArgument(
Expand All @@ -118,10 +116,17 @@ private boolean isTableRegisteredWithLakeFormation() {
.databaseName(dbName)
.name(tableName)
.build());
return response.table().isRegisteredWithLakeFormation();
boolean isRegisteredWithLakeFormation = response.table().isRegisteredWithLakeFormation();
if (isRegisteredWithLakeFormation) {
// set the Glue account id, if not set
if (this.glueAccountId == null) {
this.glueAccountId = response.table().catalogId();
}
}
return isRegisteredWithLakeFormation;
}

private String buildTableArn() {
protected String buildTableArn() {
Preconditions.checkArgument(
glueAccountId != null && !glueAccountId.isEmpty(),
"%s can not be empty",
Expand All @@ -131,13 +136,17 @@ private String buildTableArn() {
"arn:%s:glue:%s:%s:table/%s/%s", partitionName, region(), glueAccountId, dbName, tableName);
}

private LakeFormationClient lakeFormation() {
protected LakeFormationClient lakeFormation() {
return LakeFormationClient.builder()
.applyMutation(this::applyAssumeRoleConfigurations)
.applyMutation(httpClientProperties()::applyHttpClientConfigurations)
.build();
}

protected AwsCredentialsProvider lakeFormationCredentialsProvider() {
return new LakeFormationCredentialsProvider(lakeFormation(), buildTableArn());
}

static class LakeFormationCredentialsProvider implements AwsCredentialsProvider {
private LakeFormationClient client;
private String tableArn;
Expand Down