Skip to content

Commit cf9a113

Browse files
committed
Resolved more comments
1 parent 613a2fa commit cf9a113

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public static CatalogEntity fromCatalog(RealmConfig realmConfig, Catalog catalog
109109
return builder.build();
110110
}
111111

112+
public Catalog asCatalog() {
113+
return this.asCatalog(null);
114+
}
115+
112116
public Catalog asCatalog(ServiceIdentityRegistry serviceIdentityRegistry) {
113117
Map<String, String> internalProperties = getInternalPropertiesAsMap();
114118
Catalog.TypeEnum catalogType =
@@ -120,6 +124,12 @@ public Catalog asCatalog(ServiceIdentityRegistry serviceIdentityRegistry) {
120124
CatalogProperties.builder(propertiesMap.get(DEFAULT_BASE_LOCATION_KEY))
121125
.putAll(propertiesMap)
122126
.build();
127+
128+
// Right now, only external catalog may use ServiceIdentityRegistry to resolve identity
129+
Preconditions.checkState(
130+
catalogType != Catalog.TypeEnum.EXTERNAL || serviceIdentityRegistry != null,
131+
"catalog needs ServiceIdentityRegistry to resolve service identities",
132+
Catalog.TypeEnum.EXTERNAL);
123133
return catalogType == Catalog.TypeEnum.EXTERNAL
124134
? ExternalCatalog.builder()
125135
.setType(Catalog.TypeEnum.EXTERNAL)

polaris-core/src/main/java/org/apache/polaris/core/identity/resolved/ResolvedAwsIamServiceIdentity.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.apache.polaris.core.identity.resolved;
2020

21-
import com.google.common.base.Supplier;
22-
import com.google.common.base.Suppliers;
2321
import jakarta.annotation.Nonnull;
2422
import jakarta.annotation.Nullable;
2523
import org.apache.polaris.core.admin.model.AwsIamServiceIdentityInfo;
@@ -31,7 +29,6 @@
3129
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
3230
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
3331
import software.amazon.awssdk.services.sts.StsClient;
34-
import software.amazon.awssdk.services.sts.StsClientBuilder;
3532

3633
/**
3734
* Represents a fully resolved AWS IAM service identity, including the associated IAM ARN and
@@ -93,14 +90,4 @@ public ResolvedAwsIamServiceIdentity(
9390
.setIamArn(getIamArn())
9491
.build();
9592
}
96-
97-
/** Returns a memoized supplier for creating an STS client using the resolved credentials. */
98-
public @Nonnull Supplier<StsClient> stsClientSupplier() {
99-
return Suppliers.memoize(
100-
() -> {
101-
StsClientBuilder stsClientBuilder =
102-
StsClient.builder().credentialsProvider(getAwsCredentialsProvider());
103-
return stsClientBuilder.build();
104-
});
105-
}
10693
}

runtime/service/src/main/java/org/apache/polaris/service/identity/AwsIamServiceIdentityConfiguration.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Optional;
2424
import org.apache.polaris.core.identity.ServiceIdentityType;
2525
import org.apache.polaris.core.identity.resolved.ResolvedAwsIamServiceIdentity;
26-
import org.apache.polaris.service.identity.registry.DefaultServiceIdentityRegistry;
26+
import org.apache.polaris.core.secrets.ServiceSecretReference;
2727
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
2828
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
2929
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
@@ -60,23 +60,32 @@ public interface AwsIamServiceIdentityConfiguration extends ResolvableServiceIde
6060
*/
6161
Optional<String> sessionToken();
6262

63+
/**
64+
* Returns the type of service identity represented by this configuration, which is always {@link
65+
* ServiceIdentityType#AWS_IAM}.
66+
*
67+
* @return the AWS IAM service identity type
68+
*/
69+
@Override
70+
default ServiceIdentityType getType() {
71+
return ServiceIdentityType.AWS_IAM;
72+
}
73+
6374
/**
6475
* Resolves this configuration into a {@link ResolvedAwsIamServiceIdentity} if the IAM ARN is
6576
* present.
6677
*
6778
* @return the resolved identity, or an empty optional if the ARN is missing
6879
*/
6980
@Override
70-
default Optional<ResolvedAwsIamServiceIdentity> resolve(@Nonnull String realmIdentifier) {
81+
default Optional<ResolvedAwsIamServiceIdentity> resolve(
82+
@Nonnull ServiceSecretReference serviceIdentityReference) {
7183
if (iamArn() == null) {
7284
return Optional.empty();
7385
} else {
7486
return Optional.of(
7587
new ResolvedAwsIamServiceIdentity(
76-
DefaultServiceIdentityRegistry.buildIdentityInfoReference(
77-
realmIdentifier, ServiceIdentityType.AWS_IAM),
78-
iamArn(),
79-
awsCredentialsProvider()));
88+
serviceIdentityReference, iamArn(), awsCredentialsProvider()));
8089
}
8190
}
8291

runtime/service/src/main/java/org/apache/polaris/service/identity/ResolvableServiceIdentityConfiguration.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
import jakarta.annotation.Nonnull;
2323
import java.util.Optional;
24+
import org.apache.polaris.core.identity.ServiceIdentityType;
2425
import org.apache.polaris.core.identity.resolved.ResolvedServiceIdentity;
26+
import org.apache.polaris.core.secrets.ServiceSecretReference;
2527

2628
/**
2729
* Represents a service identity configuration that can be resolved into a fully initialized {@link
@@ -32,13 +34,23 @@
3234
* Polaris-managed service identity.
3335
*/
3436
public interface ResolvableServiceIdentityConfiguration {
37+
/**
38+
* Returns the type of service identity represented by this configuration.
39+
*
40+
* @return the service identity type, or {@link ServiceIdentityType#NULL_TYPE} if not specified
41+
*/
42+
default ServiceIdentityType getType() {
43+
return ServiceIdentityType.NULL_TYPE;
44+
}
45+
3546
/**
3647
* Attempts to resolve this configuration into a {@link ResolvedServiceIdentity}.
3748
*
3849
* @return an optional resolved service identity, or empty if resolution fails or is not
3950
* configured
4051
*/
41-
default Optional<? extends ResolvedServiceIdentity> resolve(@Nonnull String realmIdentifier) {
52+
default Optional<? extends ResolvedServiceIdentity> resolve(
53+
@Nonnull ServiceSecretReference serviceIdentityReference) {
4254
return Optional.empty();
4355
}
4456
}

runtime/service/src/main/java/org/apache/polaris/service/identity/ServiceIdentityConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Optional;
2929
import org.apache.polaris.core.context.RealmContext;
3030
import org.apache.polaris.core.identity.resolved.ResolvedServiceIdentity;
31+
import org.apache.polaris.service.identity.registry.DefaultServiceIdentityRegistry;
3132

3233
/**
3334
* Represents the service identity configuration for one or more realms.
@@ -84,7 +85,9 @@ default List<? extends ResolvedServiceIdentity> resolveServiceIdentities(
8485
return entry.config().serviceIdentityConfigurations().stream()
8586
.map(
8687
resolvableServiceIdentityConfiguration ->
87-
resolvableServiceIdentityConfiguration.resolve(entry.realm()))
88+
resolvableServiceIdentityConfiguration.resolve(
89+
DefaultServiceIdentityRegistry.buildIdentityInfoReference(
90+
entry.realm(), resolvableServiceIdentityConfiguration.getType())))
8891
.flatMap(Optional::stream)
8992
.toList();
9093
}

0 commit comments

Comments
 (0)