Skip to content

Commit

Permalink
[#5989] The credential type of ADLSTokenCredentialProvider is not equ…
Browse files Browse the repository at this point in the history
…al to the credential type of ADLSTokenCredential (#5990)

### What changes were proposed in this pull request?

ADLSTokenCredentialProvider use the credential type from
ADLSTokenCredential

### Why are the changes needed?


Fix: #5989 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
add test
  • Loading branch information
FANNG1 authored Dec 28, 2024
1 parent 07cdcba commit 486c042
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
/** ADLS SAS token credential. */
public class ADLSTokenCredential implements Credential {

/** ADLS SAS token credential type. */
public static final String ADLS_SAS_TOKEN_CREDENTIAL_TYPE = "adls-sas-token";
/** ADLS token credential type. */
public static final String ADLS_TOKEN_CREDENTIAL_TYPE = "adls-token";
/** ADLS base domain */
public static final String ADLS_DOMAIN = "dfs.core.windows.net";
/** ADLS storage account name */
Expand Down Expand Up @@ -62,7 +62,7 @@ public ADLSTokenCredential() {}

@Override
public String credentialType() {
return ADLS_SAS_TOKEN_CREDENTIAL_TYPE;
return ADLS_TOKEN_CREDENTIAL_TYPE;
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions bundles/aliyun/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ dependencies {
// Aliyun oss SDK depends on this package, and JDK >= 9 requires manual add
// https://www.alibabacloud.com/help/en/oss/developer-reference/java-installation?spm=a2c63.p38356.0.i1
implementation(libs.sun.activation)

testImplementation(project(":api"))
testImplementation(project(":core"))
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType(ShadowJar::class.java) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.oss.credential;

import org.apache.gravitino.credential.OSSSecretKeyCredential;
import org.apache.gravitino.credential.OSSTokenCredential;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestCredentialProvider {

@Test
void testCredentialProviderType() {
OSSTokenProvider ossTokenProvider = new OSSTokenProvider();
Assertions.assertEquals(
OSSTokenCredential.OSS_TOKEN_CREDENTIAL_TYPE, ossTokenProvider.credentialType());

OSSSecretKeyProvider ossSecretKeyProvider = new OSSSecretKeyProvider();
Assertions.assertEquals(
OSSSecretKeyCredential.OSS_SECRET_KEY_CREDENTIAL_TYPE,
ossSecretKeyProvider.credentialType());
}
}
6 changes: 6 additions & 0 deletions bundles/aws/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ dependencies {
implementation(libs.commons.lang3)
implementation(libs.hadoop3.aws)
implementation(libs.guava)

testImplementation(project(":api"))
testImplementation(project(":core"))
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType(ShadowJar::class.java) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.s3.credential;

import org.apache.gravitino.credential.S3SecretKeyCredential;
import org.apache.gravitino.credential.S3TokenCredential;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestCredentialProvider {

@Test
void testCredentialProviderType() {
S3TokenProvider s3TokenProvider = new S3TokenProvider();
Assertions.assertEquals(
S3TokenCredential.S3_TOKEN_CREDENTIAL_TYPE, s3TokenProvider.credentialType());

S3SecretKeyProvider s3SecretKeyProvider = new S3SecretKeyProvider();
Assertions.assertEquals(
S3SecretKeyCredential.S3_SECRET_KEY_CREDENTIAL_TYPE, s3SecretKeyProvider.credentialType());
}
}
6 changes: 6 additions & 0 deletions bundles/azure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ dependencies {
// runtime used
implementation(libs.commons.logging)
implementation(libs.guava)

testImplementation(project(":api"))
testImplementation(project(":core"))
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType(ShadowJar::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.Set;
import org.apache.gravitino.credential.ADLSTokenCredential;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.credential.CredentialContext;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.PathBasedCredentialContext;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void close() {}

@Override
public String credentialType() {
return CredentialConstants.ADLS_TOKEN_CREDENTIAL_PROVIDER_TYPE;
return ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Map;
import org.apache.gravitino.credential.AzureAccountKeyCredential;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.credential.CredentialContext;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.config.AzureCredentialConfig;
Expand All @@ -44,7 +43,7 @@ public void close() {}

@Override
public String credentialType() {
return CredentialConstants.AZURE_ACCOUNT_KEY_CREDENTIAL_PROVIDER_TYPE;
return AzureAccountKeyCredential.AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.abs.credential;

import org.apache.gravitino.credential.ADLSTokenCredential;
import org.apache.gravitino.credential.AzureAccountKeyCredential;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestCredentialProvider {

@Test
void testCredentialProviderType() {
ADLSTokenProvider adlsTokenProvider = new ADLSTokenProvider();
Assertions.assertEquals(
ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE, adlsTokenProvider.credentialType());

AzureAccountKeyProvider azureAccountKeyProvider = new AzureAccountKeyProvider();
Assertions.assertEquals(
AzureAccountKeyCredential.AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE,
azureAccountKeyProvider.credentialType());
}
}
6 changes: 6 additions & 0 deletions bundles/gcp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ dependencies {
implementation(libs.commons.logging)
implementation(libs.google.auth.credentials)
implementation(libs.google.auth.http)

testImplementation(project(":api"))
testImplementation(project(":core"))
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType(ShadowJar::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.credential.CredentialContext;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.GCSTokenCredential;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void close() {}

@Override
public String credentialType() {
return CredentialConstants.GCS_TOKEN_CREDENTIAL_PROVIDER_TYPE;
return GCSTokenCredential.GCS_TOKEN_CREDENTIAL_TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.gcs.credential;

import org.apache.gravitino.credential.GCSTokenCredential;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestCredentialProvider {

@Test
void testCredentialProviderType() {
GCSTokenProvider gcsTokenProvider = new GCSTokenProvider();
Assertions.assertEquals(
GCSTokenCredential.GCS_TOKEN_CREDENTIAL_TYPE, gcsTokenProvider.credentialType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@ public class CredentialConstants {
public static final String CREDENTIAL_PROVIDERS = "credential-providers";
public static final String CREDENTIAL_CACHE_EXPIRE_RATIO = "credential-cache-expire-ratio";
public static final String CREDENTIAL_CACHE_MAX_SIZE = "credential-cache-max-size";
public static final String S3_TOKEN_CREDENTIAL_PROVIDER = "s3-token";
public static final String S3_TOKEN_EXPIRE_IN_SECS = "s3-token-expire-in-secs";

public static final String GCS_TOKEN_CREDENTIAL_PROVIDER_TYPE = "gcs-token";

public static final String OSS_TOKEN_CREDENTIAL_PROVIDER = "oss-token";
public static final String OSS_TOKEN_EXPIRE_IN_SECS = "oss-token-expire-in-secs";

public static final String ADLS_TOKEN_CREDENTIAL_PROVIDER_TYPE = "adls-token";
public static final String ADLS_TOKEN_EXPIRE_IN_SECS = "adls-token-expire-in-secs";

public static final String AZURE_ACCOUNT_KEY_CREDENTIAL_PROVIDER_TYPE = "azure-account-key";

private CredentialConstants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ADLSTokenCredential(Credential, ABC):
"""Represents ADLS token credential."""

ADLS_SAS_TOKEN_CREDENTIAL_TYPE: str = "adls-sas-token"
ADLS_TOKEN_CREDENTIAL_TYPE: str = "adls-token"
ADLS_DOMAIN: str = "dfs.core.windows.net"
_STORAGE_ACCOUNT_NAME: str = "azure-storage-account-name"
_SAS_TOKEN: str = "adls-sas-token"
Expand All @@ -51,7 +51,7 @@ def credential_type(self) -> str:
Returns:
the type of the credential.
"""
return self.ADLS_SAS_TOKEN_CREDENTIAL_TYPE
return self.ADLS_TOKEN_CREDENTIAL_TYPE

def expire_time_in_ms(self) -> int:
"""Returns the expiration time of the credential in milliseconds since
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create(
credential = OSSTokenCredential(credential_info, expire_time_in_ms)
elif credential_type == OSSSecretKeyCredential.OSS_SECRET_KEY_CREDENTIAL_TYPE:
credential = OSSSecretKeyCredential(credential_info, expire_time_in_ms)
elif credential_type == ADLSTokenCredential.ADLS_SAS_TOKEN_CREDENTIAL_TYPE:
elif credential_type == ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE:
credential = ADLSTokenCredential(credential_info, expire_time_in_ms)
elif (
credential_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_adls_token_credential(self):
adls_credential.credential_type(), credential_info, expire_time
)
self.assertEqual(
ADLSTokenCredential.ADLS_SAS_TOKEN_CREDENTIAL_TYPE,
ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE,
check_credential.credential_type(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ void testADLSTokenCredential() {
long expireTime = 100;
Credential credential =
CredentialFactory.create(
ADLSTokenCredential.ADLS_SAS_TOKEN_CREDENTIAL_TYPE,
adlsTokenCredentialInfo,
expireTime);
ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE, adlsTokenCredentialInfo, expireTime);
Assertions.assertEquals(
ADLSTokenCredential.ADLS_SAS_TOKEN_CREDENTIAL_TYPE, credential.credentialType());
ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE, credential.credentialType());
Assertions.assertInstanceOf(ADLSTokenCredential.class, credential);

ADLSTokenCredential adlsTokenCredential = (ADLSTokenCredential) credential;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import org.apache.gravitino.abs.credential.ADLSLocationUtils;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.credential.ADLSTokenCredential;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.util.BaseIT;
Expand Down Expand Up @@ -92,7 +93,7 @@ private Map<String, String> getADLSConfig() {

configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX + CredentialConstants.CREDENTIAL_PROVIDER_TYPE,
CredentialConstants.ADLS_TOKEN_CREDENTIAL_PROVIDER_TYPE);
ADLSTokenCredential.ADLS_TOKEN_CREDENTIAL_TYPE);
configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX + AzureProperties.GRAVITINO_AZURE_STORAGE_ACCOUNT_NAME,
storageAccountName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.credential.AzureAccountKeyCredential;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.util.BaseIT;
Expand Down Expand Up @@ -82,7 +83,7 @@ private Map<String, String> getADLSConfig() {

configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX + CredentialConstants.CREDENTIAL_PROVIDER_TYPE,
CredentialConstants.AZURE_ACCOUNT_KEY_CREDENTIAL_PROVIDER_TYPE);
AzureAccountKeyCredential.AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE);
configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX + AzureProperties.GRAVITINO_AZURE_STORAGE_ACCOUNT_NAME,
storageAccountName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.credential.GCSTokenCredential;
import org.apache.gravitino.credential.config.GCSCredentialConfig;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.util.BaseIT;
Expand Down Expand Up @@ -73,7 +74,7 @@ private Map<String, String> getGCSConfig() {

configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX + CredentialConstants.CREDENTIAL_PROVIDER_TYPE,
CredentialConstants.GCS_TOKEN_CREDENTIAL_PROVIDER_TYPE);
GCSTokenCredential.GCS_TOKEN_CREDENTIAL_TYPE);
configMap.put(
IcebergConfig.ICEBERG_CONFIG_PREFIX
+ GCSCredentialConfig.GRAVITINO_GCS_CREDENTIAL_FILE_PATH,
Expand Down
Loading

0 comments on commit 486c042

Please sign in to comment.