XJDKC commented on code in PR #2759:
URL: https://github.com/apache/polaris/pull/2759#discussion_r2408961539


##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/DefaultPolarisCredentialManager.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import jakarta.annotation.Nonnull;
+import jakarta.enterprise.inject.Any;
+import jakarta.enterprise.inject.Instance;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.service.credentials.connection.SupportsAuthType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link PolarisCredentialManager} responsible for 
retrieving credentials
+ * used by Polaris to access external systems such as remote catalogs or cloud 
storage.
+ *
+ * <p>This implementation delegates to {@link ConnectionCredentialVendor} 
implementations selected
+ * via CDI based on the authentication type. Each vendor handles the 
credential transformation logic
+ * for a specific authentication mechanism (e.g., SigV4, OAuth).
+ *
+ * <p>Flow:
+ *
+ * <ol>
+ *   <li>Selects the appropriate {@link ConnectionCredentialVendor} based on 
the authentication type
+ *   <li>Delegates to the vendor to generate the final connection credentials 
(the vendor will
+ *       resolve the service identity internally)
+ * </ol>
+ */
+public class DefaultPolarisCredentialManager implements 
PolarisCredentialManager {
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(DefaultPolarisCredentialManager.class);
+
+  private final Instance<ConnectionCredentialVendor> credentialVendors;
+
+  public DefaultPolarisCredentialManager(
+      @Any Instance<ConnectionCredentialVendor> credentialVendors) {
+    this.credentialVendors = credentialVendors;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Select the appropriate vendor based on authentication type
+    AuthenticationType authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+    Instance<ConnectionCredentialVendor> selectedVendor =
+        credentialVendors.select(SupportsAuthType.Literal.of(authType));

Review Comment:
   I think it makes sense to add `<X extends ConnectionConfigInfoDp>`, but I 
also want the `PolarisCredentialManager` to serve as a caching layer.
   
   It would still be ideal to have `PolarisCredentialManager` call 
`ConnectionCredentialVendor.connectionCredentials` internally and manage 
caching within the manager itself. This way, callers only need to interact with 
`PolarisCredentialManager`, they won’t need to care whether the credentials 
come from cache or are freshly fetched.
   
   The final state of PolarisCredentialManager would be:
   
   ```
   class DefaultPolarisCredentialManager implements PolarisCredentialManager {
     private AccessCredsCache accessCredsCache;
     private final Instance<ConnectionCredentialVendor> credentialVendors;
   
     @Override
     public @Nonnull ConnectionCredentials getConnectionCredentials(
         @Nonnull ConnectionConfigInfoDpo connectionConfig) {
       // 1. generate cache key
       // 2. check if there is a valid connection credential in the cache
       // 3. if yes, get the credential from cache and return it directly
       // 4. If not, select the credential vendor based on Auth Type
       // 5. Delegate to the connection credential vendor to fetch the 
connection credentials
       // 6. Store the connection credentials in the cache
       // 7. return the connection credentials
     }
   
     @Override
     public @Nonnull StorageAccessConfig getSubscopedStorageCreds(
        @Nonnull RealmConfig realmConfig,
         boolean allowListOperation,
         @Nonnull Set<String> allowedReadLocations,
         @Nonnull Set<String> allowedWriteLocations,
         Optional<String> refreshCredentialsEndpoint) {
       // 1. generate cache key
       // 2. check if there is a valid storage credential in the cache
       // 3. if yes, get the credential from cache and return it directly
       // 4. If not, select the credential vendor based on Storage Type
       // 5. Delegate to the storage credential vendor to fetch the storage 
credentials
       // 6. Store the storage credentials in the cache
       // 7. return the storage credentials
     }
   }
   ```
   



##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/DefaultPolarisCredentialManager.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import jakarta.annotation.Nonnull;
+import jakarta.enterprise.inject.Any;
+import jakarta.enterprise.inject.Instance;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.service.credentials.connection.SupportsAuthType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link PolarisCredentialManager} responsible for 
retrieving credentials
+ * used by Polaris to access external systems such as remote catalogs or cloud 
storage.
+ *
+ * <p>This implementation delegates to {@link ConnectionCredentialVendor} 
implementations selected
+ * via CDI based on the authentication type. Each vendor handles the 
credential transformation logic
+ * for a specific authentication mechanism (e.g., SigV4, OAuth).
+ *
+ * <p>Flow:
+ *
+ * <ol>
+ *   <li>Selects the appropriate {@link ConnectionCredentialVendor} based on 
the authentication type
+ *   <li>Delegates to the vendor to generate the final connection credentials 
(the vendor will
+ *       resolve the service identity internally)
+ * </ol>
+ */
+public class DefaultPolarisCredentialManager implements 
PolarisCredentialManager {
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(DefaultPolarisCredentialManager.class);
+
+  private final Instance<ConnectionCredentialVendor> credentialVendors;
+
+  public DefaultPolarisCredentialManager(
+      @Any Instance<ConnectionCredentialVendor> credentialVendors) {
+    this.credentialVendors = credentialVendors;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Select the appropriate vendor based on authentication type
+    AuthenticationType authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+    Instance<ConnectionCredentialVendor> selectedVendor =
+        credentialVendors.select(SupportsAuthType.Literal.of(authType));

Review Comment:
   I think it makes sense to add `<X extends ConnectionConfigInfoDp>`, but I 
also want the `PolarisCredentialManager` to serve as a caching layer.
   
   It would still be ideal to have `PolarisCredentialManager` call 
`ConnectionCredentialVendor.connectionCredentials` internally and manage 
caching within the manager itself. This way, callers only need to interact with 
`PolarisCredentialManager`, they won’t need to care whether the credentials 
come from cache or are freshly fetched.
   
   The final state of PolarisCredentialManager would be:
   
   ```java
   class DefaultPolarisCredentialManager implements PolarisCredentialManager {
     private AccessCredsCache accessCredsCache;
     private final Instance<ConnectionCredentialVendor> credentialVendors;
   
     @Override
     public @Nonnull ConnectionCredentials getConnectionCredentials(
         @Nonnull ConnectionConfigInfoDpo connectionConfig) {
       // 1. generate cache key
       // 2. check if there is a valid connection credential in the cache
       // 3. if yes, get the credential from cache and return it directly
       // 4. If not, select the credential vendor based on Auth Type
       // 5. Delegate to the connection credential vendor to fetch the 
connection credentials
       // 6. Store the connection credentials in the cache
       // 7. return the connection credentials
     }
   
     @Override
     public @Nonnull StorageAccessConfig getSubscopedStorageCreds(
        @Nonnull RealmConfig realmConfig,
         boolean allowListOperation,
         @Nonnull Set<String> allowedReadLocations,
         @Nonnull Set<String> allowedWriteLocations,
         Optional<String> refreshCredentialsEndpoint) {
       // 1. generate cache key
       // 2. check if there is a valid storage credential in the cache
       // 3. if yes, get the credential from cache and return it directly
       // 4. If not, select the credential vendor based on Storage Type
       // 5. Delegate to the storage credential vendor to fetch the storage 
credentials
       // 6. Store the storage credentials in the cache
       // 7. return the storage credentials
     }
   }
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to