org.apache.gravitino.credential.CredentialPropertyUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Gravitino is a high-performance, geo-distributed and federated metadata lake.
The newest version!
/*
* 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.gravitino.credential;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.Map;
/**
* Helper class to generate specific credential properties for different table format and engine.
*/
public class CredentialPropertyUtils {
@VisibleForTesting static final String ICEBERG_S3_ACCESS_KEY_ID = "s3.access-key-id";
@VisibleForTesting static final String ICEBERG_S3_SECRET_ACCESS_KEY = "s3.secret-access-key";
@VisibleForTesting static final String ICEBERG_S3_TOKEN = "s3.session-token";
@VisibleForTesting static final String ICEBERG_GCS_TOKEN = "gcs.oauth2.token";
private static Map icebergCredentialPropertyMap =
ImmutableMap.of(
GCSTokenCredential.GCS_TOKEN_NAME,
ICEBERG_GCS_TOKEN,
S3SecretKeyCredential.GRAVITINO_S3_STATIC_ACCESS_KEY_ID,
ICEBERG_S3_ACCESS_KEY_ID,
S3SecretKeyCredential.GRAVITINO_S3_STATIC_SECRET_ACCESS_KEY,
ICEBERG_S3_SECRET_ACCESS_KEY,
S3TokenCredential.GRAVITINO_S3_TOKEN,
ICEBERG_S3_TOKEN);
/**
* Transforms a specific credential into a map of Iceberg properties.
*
* @param credential the credential to be transformed into Iceberg properties
* @return a map of Iceberg properties derived from the credential
*/
public static Map toIcebergProperties(Credential credential) {
if (credential instanceof GCSTokenCredential) {
Map icebergGCSCredentialProperties =
transformProperties(credential.credentialInfo(), icebergCredentialPropertyMap);
icebergGCSCredentialProperties.put(
"gcs.oauth2.token-expires-at", String.valueOf(credential.expireTimeInMs()));
return icebergGCSCredentialProperties;
}
if (credential instanceof S3TokenCredential || credential instanceof S3SecretKeyCredential) {
return transformProperties(credential.credentialInfo(), icebergCredentialPropertyMap);
}
return credential.toProperties();
}
private static Map transformProperties(
Map originProperties, Map transformMap) {
HashMap properties = new HashMap();
originProperties.forEach(
(k, v) -> {
if (transformMap.containsKey(k)) {
properties.put(transformMap.get(k), v);
}
});
return properties;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy