-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? Support Azure account key credential ### Why are the changes needed? Fix: #5894 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Unit Test IcebergRESTADLSAccountKeyIT at iceberg 1.6.0
- Loading branch information
Showing
12 changed files
with
374 additions
and
46 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
api/src/main/java/org/apache/gravitino/credential/AzureAccountKeyCredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** Azure account key credential. */ | ||
public class AzureAccountKeyCredential implements Credential { | ||
|
||
/** Azure account key credential type. */ | ||
public static final String AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE = "azure-account-key"; | ||
/** Azure storage account name */ | ||
public static final String GRAVITINO_AZURE_STORAGE_ACCOUNT_NAME = "azure-storage-account-name"; | ||
/** Azure storage account key */ | ||
public static final String GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY = "azure-storage-account-key"; | ||
|
||
private String accountName; | ||
private String accountKey; | ||
|
||
/** | ||
* Constructs an instance of {@link AzureAccountKeyCredential}. | ||
* | ||
* @param accountName The Azure account name. | ||
* @param accountKey The Azure account key. | ||
*/ | ||
public AzureAccountKeyCredential(String accountName, String accountKey) { | ||
validate(accountName, accountKey); | ||
this.accountName = accountName; | ||
this.accountKey = accountKey; | ||
} | ||
|
||
/** | ||
* This is the constructor that is used by credential factory to create an instance of credential | ||
* according to the credential information. | ||
*/ | ||
public AzureAccountKeyCredential() {} | ||
|
||
@Override | ||
public String credentialType() { | ||
return AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE; | ||
} | ||
|
||
@Override | ||
public long expireTimeInMs() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Map<String, String> credentialInfo() { | ||
return (new ImmutableMap.Builder<String, String>()) | ||
.put(GRAVITINO_AZURE_STORAGE_ACCOUNT_NAME, accountName) | ||
.put(GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY, accountKey) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void initialize(Map<String, String> credentialInfo, long expireTimeInMS) { | ||
String accountName = credentialInfo.get(GRAVITINO_AZURE_STORAGE_ACCOUNT_NAME); | ||
String accountKey = credentialInfo.get(GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY); | ||
validate(accountName, accountKey); | ||
this.accountName = accountName; | ||
this.accountKey = accountKey; | ||
} | ||
|
||
/** | ||
* Get Azure account name | ||
* | ||
* @return The Azure account name | ||
*/ | ||
public String accountName() { | ||
return accountName; | ||
} | ||
|
||
/** | ||
* Get Azure account key | ||
* | ||
* @return The Azure account key | ||
*/ | ||
public String accountKey() { | ||
return accountKey; | ||
} | ||
|
||
private void validate(String accountName, String accountKey) { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(accountName), "Azure account name should not be empty."); | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(accountKey), "Azure account key should not be empty."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ure-bundle/src/main/java/org/apache/gravitino/abs/credential/AzureAccountKeyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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 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; | ||
|
||
/** Generates Azure account key to access data. */ | ||
public class AzureAccountKeyProvider implements CredentialProvider { | ||
private String accountName; | ||
private String accountKey; | ||
|
||
@Override | ||
public void initialize(Map<String, String> properties) { | ||
AzureCredentialConfig azureCredentialConfig = new AzureCredentialConfig(properties); | ||
this.accountName = azureCredentialConfig.storageAccountName(); | ||
this.accountKey = azureCredentialConfig.storageAccountKey(); | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
|
||
@Override | ||
public String credentialType() { | ||
return CredentialConstants.AZURE_ACCOUNT_KEY_CREDENTIAL_PROVIDER_TYPE; | ||
} | ||
|
||
@Override | ||
public Credential getCredential(CredentialContext context) { | ||
return new AzureAccountKeyCredential(accountName, accountKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.