FANNG1 commented on code in PR #5040:
URL: https://github.com/apache/gravitino/pull/5040#discussion_r1804688199


##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/GravitinoDriverPlugin.java:
##########
@@ -155,4 +165,57 @@ private void registerSqlExtensions(SparkConf conf) {
       conf.set(StaticSQLConf.SPARK_SESSION_EXTENSIONS().key(), 
extensionString);
     }
   }
+
+  private static GravitinoClient createGravitinoClient(
+      String uri, String metalake, SparkConf sparkConf, String sparkUser) {
+    ClientBuilder builder = 
GravitinoClient.builder(uri).withMetalake(metalake);
+    String authType =
+        sparkConf.get(GravitinoSparkConfig.GRAVITINO_AUTH_TYPE, 
AuthProperties.SIMPLE_AUTH_TYPE);
+    if (AuthProperties.isSimple(authType)) {
+      Preconditions.checkArgument(
+          !UserGroupInformation.isSecurityEnabled(),
+          "Spark simple auth mode doesn't support setting kerberos 
configurations");
+      builder.withSimpleAuth(sparkUser);
+    } else if (AuthProperties.isOAuth2(authType)) {
+      String oAuthUri = getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_OAUTH2_URI);
+      String credential =
+          getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_OAUTH2_CREDENTIAL);
+      String path = getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_OAUTH2_PATH);
+      String scope = getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_OAUTH2_SCOPE);
+      DefaultOAuth2TokenProvider oAuth2TokenProvider =
+          DefaultOAuth2TokenProvider.builder()
+              .withUri(oAuthUri)
+              .withCredential(credential)
+              .withPath(path)
+              .withScope(scope)
+              .build();
+      builder.withOAuth(oAuth2TokenProvider);
+    } else if (AuthProperties.isKerberos(authType)) {
+      String principal =
+          getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_KERBEROS_PRINCIPAL);
+      String keyTabFile =
+          getRequiredConfig(sparkConf, 
GravitinoSparkConfig.GRAVITINO_KERBEROS_KEYTAB_FILE_PATH);
+      KerberosTokenProvider kerberosTokenProvider =
+          KerberosTokenProvider.builder()
+              .withClientPrincipal(principal)
+              .withKeyTabFile(new File(keyTabFile))
+              .build();
+      builder.withKerberosAuth(kerberosTokenProvider);
+    } else {
+      throw new UnsupportedOperationException("Unsupported auth type: " + 
authType);
+    }
+    return builder.build();
+  }
+
+  private static String getRequiredConfig(SparkConf sparkConf, String 
configKey) {
+    String configValue = sparkConf.get(configKey, null);
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(configValue), configKey + " should not empty");

Review Comment:
   updated



-- 
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