Skip to content

Commit 0493d65

Browse files
fix: abstracted-out
1 parent 6e693cc commit 0493d65

3 files changed

Lines changed: 34 additions & 33 deletions

File tree

amoro-ams/src/main/java/org/apache/amoro/server/terminal/TerminalManager.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import org.apache.amoro.utils.CatalogUtil;
4343
import org.apache.hadoop.conf.Configuration;
4444
import org.apache.iceberg.CatalogProperties;
45-
import org.apache.iceberg.aws.AwsClientProperties;
46-
import org.apache.iceberg.aws.s3.S3FileIOProperties;
4745
import org.slf4j.Logger;
4846
import org.slf4j.LoggerFactory;
4947

@@ -410,18 +408,11 @@ private void applyClientProperties(CatalogMeta catalogMeta) {
410408
// Glue client receives the same credentials that were provided for S3.
411409
if (CatalogMetaProperties.CATALOG_TYPE_GLUE.equalsIgnoreCase(catalogType)) {
412410
Map<String, String> props = catalogMeta.getCatalogProperties();
413-
String accessKey = props.get(S3FileIOProperties.ACCESS_KEY_ID);
414-
String secretKey = props.get(S3FileIOProperties.SECRET_ACCESS_KEY);
415-
if (accessKey != null && secretKey != null) {
416-
catalogMeta.putToCatalogProperties(
417-
AwsClientProperties.CLIENT_CREDENTIALS_PROVIDER,
418-
StaticAwsCredentialsProvider.class.getName());
419-
catalogMeta.putToCatalogProperties(
420-
"client.credentials-provider." + StaticAwsCredentialsProvider.ACCESS_KEY_ID,
421-
accessKey);
422-
catalogMeta.putToCatalogProperties(
423-
"client.credentials-provider." + StaticAwsCredentialsProvider.SECRET_ACCESS_KEY,
424-
secretKey);
411+
Map<String, String> enriched = StaticAwsCredentialsProvider.applyGlueCredentials(props);
412+
// Only merge when a new map was produced: same instance means nothing to add, and merging
413+
// would re-iterate the live CatalogMeta map while mutating it.
414+
if (enriched != null && enriched != props) {
415+
enriched.forEach(catalogMeta::putToCatalogProperties);
425416
}
426417
}
427418
} else if (formats.contains(TableFormat.PAIMON) && "hive".equals(catalogType)) {

amoro-format-iceberg/src/main/java/org/apache/amoro/aws/StaticAwsCredentialsProvider.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
package org.apache.amoro.aws;
2222

23+
import org.apache.iceberg.aws.AwsClientProperties;
24+
import org.apache.iceberg.aws.s3.S3FileIOProperties;
2325
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
2426
import software.amazon.awssdk.auth.credentials.AwsCredentials;
2527
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
2628

29+
import java.util.HashMap;
2730
import java.util.Map;
2831

2932
/**
@@ -53,6 +56,31 @@ public static AwsCredentialsProvider create(Map<String, String> properties) {
5356
return new StaticAwsCredentialsProvider(accessKeyId, secretAccessKey);
5457
}
5558

59+
/**
60+
* Returns a copy of {@code properties} enriched with {@link
61+
* AwsClientProperties#CLIENT_CREDENTIALS_PROVIDER} pointing at this class, so that Glue (and any
62+
* other AWS client) uses the S3 AK/SK instead of the default credential chain. If {@code
63+
* properties} is null, returns null. If either S3 key is absent, returns {@code properties}
64+
* unchanged (same instance).
65+
*/
66+
public static Map<String, String> applyGlueCredentials(Map<String, String> properties) {
67+
if (properties == null) {
68+
return null;
69+
}
70+
String accessKey = properties.get(S3FileIOProperties.ACCESS_KEY_ID);
71+
String secretKey = properties.get(S3FileIOProperties.SECRET_ACCESS_KEY);
72+
if (accessKey == null || secretKey == null) {
73+
return properties;
74+
}
75+
Map<String, String> newProperties = new HashMap<>(properties);
76+
newProperties.put(
77+
AwsClientProperties.CLIENT_CREDENTIALS_PROVIDER,
78+
StaticAwsCredentialsProvider.class.getName());
79+
newProperties.put("client.credentials-provider." + ACCESS_KEY_ID, accessKey);
80+
newProperties.put("client.credentials-provider." + SECRET_ACCESS_KEY, secretKey);
81+
return newProperties;
82+
}
83+
5684
@Override
5785
public AwsCredentials resolveCredentials() {
5886
return credentials;

amoro-format-iceberg/src/main/java/org/apache/amoro/formats/iceberg/IcebergCatalogFactory.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626
import org.apache.amoro.aws.StaticAwsCredentialsProvider;
2727
import org.apache.amoro.properties.CatalogMetaProperties;
2828
import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
29-
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
3029
import org.apache.amoro.table.TableMetaStore;
3130
import org.apache.amoro.utils.MixedFormatCatalogUtil;
3231
import org.apache.commons.lang3.StringUtils;
3332
import org.apache.iceberg.CatalogUtil;
34-
import org.apache.iceberg.aws.AwsClientProperties;
35-
import org.apache.iceberg.aws.s3.S3FileIOProperties;
3633
import org.apache.iceberg.catalog.Catalog;
3734

3835
import java.util.Map;
@@ -47,23 +44,8 @@ public FormatCatalog create(
4744
MixedFormatCatalogUtil.withIcebergCatalogInitializeProperties(
4845
name, metastoreType, properties);
4946

50-
// Setting the StaticAwsCredentialsProvider for Glue catalog to read the S3 credentials
5147
if (CatalogMetaProperties.CATALOG_TYPE_GLUE.equalsIgnoreCase(metastoreType)) {
52-
Map<String, String> newProperties = Maps.newHashMap(properties);
53-
String accessKey = newProperties.get(S3FileIOProperties.ACCESS_KEY_ID);
54-
String secretKey = newProperties.get(S3FileIOProperties.SECRET_ACCESS_KEY);
55-
56-
if (accessKey != null && secretKey != null) {
57-
newProperties.put(
58-
AwsClientProperties.CLIENT_CREDENTIALS_PROVIDER,
59-
StaticAwsCredentialsProvider.class.getName());
60-
newProperties.put(
61-
"client.credentials-provider." + StaticAwsCredentialsProvider.ACCESS_KEY_ID, accessKey);
62-
newProperties.put(
63-
"client.credentials-provider." + StaticAwsCredentialsProvider.SECRET_ACCESS_KEY,
64-
secretKey);
65-
properties = newProperties;
66-
}
48+
properties = StaticAwsCredentialsProvider.applyGlueCredentials(properties);
6749
}
6850

6951
Catalog icebergCatalog =

0 commit comments

Comments
 (0)