Skip to content

Commit

Permalink
Remove CallContext
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Jan 8, 2025
1 parent 1ba9fd8 commit facd3fd
Show file tree
Hide file tree
Showing 56 changed files with 1,639 additions and 1,822 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl;
Expand Down Expand Up @@ -100,11 +101,13 @@ static void deleteConfFiles() throws IOException {
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices);
RealmContext realmContext = () -> "realm";
PolarisMetaStoreSession session =
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), () -> "realm", null, "polaris", RANDOM_SECRETS, diagServices);
store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS, diagServices);
return new PolarisTestMetaStoreManager(
new PolarisMetaStoreManagerImpl(
realmContext,
diagServices,
new PolarisConfigurationStore() {},
timeSource.withZone(ZoneId.systemDefault())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.CatalogEntity;

/**
Expand All @@ -33,26 +34,29 @@ public interface PolarisConfigurationStore {
/**
* Retrieve the current value for a configuration key. May be null if not set.
*
* @param <T> the type of the configuration value
* @param realmContext the realm context to check for overrides; may be null.
* @param configName the name of the configuration key to check
* @return the current value set for the configuration key or null if not set
* @param <T> the type of the configuration value
*/
default <T> @Nullable T getConfiguration(String configName) {
default <T> @Nullable T getConfiguration(@Nullable RealmContext realmContext, String configName) {
return null;
}

/**
* Retrieve the current value for a configuration key. If not set, return the non-null default
* value.
*
* @param <T> the type of the configuration value
* @param realmContext the realm context to check for overrides; may be null.
* @param configName the name of the configuration key to check
* @param defaultValue the default value if the configuration key has no value
* @return the current value or the supplied default value
* @param <T> the type of the configuration value
*/
default <T> @Nonnull T getConfiguration(String configName, @Nonnull T defaultValue) {
default <T> @Nonnull T getConfiguration(
@Nullable RealmContext realmContext, String configName, @Nonnull T defaultValue) {
Preconditions.checkNotNull(defaultValue, "Cannot pass null as a default value");
T configValue = getConfiguration(configName);
T configValue = getConfiguration(realmContext, configName);
return configValue != null ? configValue : defaultValue;
}

Expand Down Expand Up @@ -83,31 +87,36 @@ public interface PolarisConfigurationStore {
/**
* Retrieve the current value for a configuration.
*
* @param <T> the type of the configuration value
* @param realmContext the realm context to check for overrides; may be null.
* @param config the configuration to load
* @return the current value set for the configuration key or null if not set
* @param <T> the type of the configuration value
*/
default <T> @Nonnull T getConfiguration(PolarisConfiguration<T> config) {
T result = getConfiguration(config.key, config.defaultValue);
default <T> @Nonnull T getConfiguration(
@Nullable RealmContext realmContext, PolarisConfiguration<T> config) {
T result = getConfiguration(realmContext, config.key, config.defaultValue);
return tryCast(config, result);
}

/**
* Retrieve the current value for a configuration, overriding with a catalog config if it is
* present.
*
* @param <T> the type of the configuration value
* @param realmContext the realm context to check for overrides; may be null.
* @param catalogEntity the catalog to check for an override
* @param config the configuration to load
* @return the current value set for the configuration key or null if not set
* @param <T> the type of the configuration value
*/
default <T> @Nonnull T getConfiguration(
@Nonnull CatalogEntity catalogEntity, PolarisConfiguration<T> config) {
@Nullable RealmContext realmContext,
@Nonnull CatalogEntity catalogEntity,
PolarisConfiguration<T> config) {
if (config.hasCatalogConfig()
&& catalogEntity.getPropertiesAsMap().containsKey(config.catalogConfig())) {
return tryCast(config, catalogEntity.getPropertiesAsMap().get(config.catalogConfig()));
} else {
return getConfiguration(config);
return getConfiguration(realmContext, config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Set;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;

/** Interface for invoking authorization checks. */
public interface PolarisAuthorizer {

void authorizeOrThrow(
@Nonnull RealmContext realmContext,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable PolarisResolvedPathWrapper target,
@Nullable PolarisResolvedPathWrapper secondary);

void authorizeOrThrow(
@Nonnull RealmContext realmContext,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.polaris.core.PolarisConfiguration;
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisEntityCore;
Expand Down Expand Up @@ -486,12 +487,14 @@ public boolean matchesOrIsSubsumedBy(

@Override
public void authorizeOrThrow(
@Nonnull RealmContext realmContext,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable PolarisResolvedPathWrapper target,
@Nullable PolarisResolvedPathWrapper secondary) {
authorizeOrThrow(
realmContext,
authenticatedPrincipal,
activatedEntities,
authzOp,
Expand All @@ -501,13 +504,15 @@ public void authorizeOrThrow(

@Override
public void authorizeOrThrow(
@Nonnull RealmContext realmContext,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable List<PolarisResolvedPathWrapper> targets,
@Nullable List<PolarisResolvedPathWrapper> secondaries) {
boolean enforceCredentialRotationRequiredState =
featureConfig.getConfiguration(
realmContext,
PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
if (enforceCredentialRotationRequiredState
&& authenticatedPrincipal
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
* prod), and/or account.
*/
public interface RealmContext {

static RealmContext copyOf(RealmContext original) {
String realmIdentifier = original.getRealmIdentifier();
return () -> realmIdentifier;
}

String getRealmIdentifier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
Expand Down Expand Up @@ -90,7 +89,7 @@ private void initializeForRealm(RealmContext realmContext) {
() -> createMetaStoreSession(backingStore, realmContext, diagnostics));

PolarisMetaStoreManager metaStoreManager =
new PolarisMetaStoreManagerImpl(diagnostics, configurationStore, clock);
new PolarisMetaStoreManagerImpl(realmContext, diagnostics, configurationStore, clock);
metaStoreManagerMap.put(realmContext.getRealmIdentifier(), metaStoreManager);
}

Expand Down Expand Up @@ -190,7 +189,6 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
// CallContext hasn't even been resolved yet.
PolarisMetaStoreSession metaStoreSession =
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
CallContext.setCurrentContext(CallContext.of(realmContext));

PolarisMetaStoreManager.EntityResult preliminaryRootPrincipalLookup =
metaStoreManager.readEntityByName(
Expand Down Expand Up @@ -246,7 +244,6 @@ private void checkPolarisServiceBootstrappedForRealm(

PolarisMetaStoreSession metaStoreSession =
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
CallContext.setCurrentContext(CallContext.of(realmContext));

PolarisMetaStoreManager.EntityResult rootPrincipalLookup =
metaStoreManager.readEntityByName(
Expand Down
Loading

0 comments on commit facd3fd

Please sign in to comment.