|
49 | 49 | import org.apache.hadoop.fs.azurebfs.diagnostics.StringConfigurationBasicValidator; |
50 | 50 | import org.apache.hadoop.fs.azurebfs.enums.Trilean; |
51 | 51 | import org.apache.hadoop.fs.azurebfs.extensions.CustomTokenProviderAdaptee; |
| 52 | +import org.apache.hadoop.fs.azurebfs.extensions.EncryptionContextProvider; |
52 | 53 | import org.apache.hadoop.fs.azurebfs.extensions.SASTokenProvider; |
53 | 54 | import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider; |
54 | 55 | import org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider; |
@@ -337,6 +338,10 @@ public class AbfsConfiguration{ |
337 | 338 | FS_AZURE_ABFS_RENAME_RESILIENCE, DefaultValue = DEFAULT_ENABLE_ABFS_RENAME_RESILIENCE) |
338 | 339 | private boolean renameResilience; |
339 | 340 |
|
| 341 | + private String clientProvidedEncryptionKey; |
| 342 | + |
| 343 | + private String clientProvidedEncryptionKeySHA; |
| 344 | + |
340 | 345 | public AbfsConfiguration(final Configuration rawConfig, String accountName) |
341 | 346 | throws IllegalAccessException, InvalidConfigurationValueException, IOException { |
342 | 347 | this.rawConfig = ProviderUtils.excludeIncompatibleCredentialProviders( |
@@ -957,6 +962,32 @@ public SASTokenProvider getSASTokenProvider() throws AzureBlobFileSystemExceptio |
957 | 962 | } |
958 | 963 | } |
959 | 964 |
|
| 965 | + public EncryptionContextProvider createEncryptionContextProvider() { |
| 966 | + try { |
| 967 | + String configKey = FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE; |
| 968 | + if (get(configKey) == null) { |
| 969 | + return null; |
| 970 | + } |
| 971 | + Class<? extends EncryptionContextProvider> encryptionContextClass = |
| 972 | + getAccountSpecificClass(configKey, null, |
| 973 | + EncryptionContextProvider.class); |
| 974 | + Preconditions.checkArgument(encryptionContextClass != null, String.format( |
| 975 | + "The configuration value for %s is invalid, or config key is not account-specific", |
| 976 | + configKey)); |
| 977 | + |
| 978 | + EncryptionContextProvider encryptionContextProvider = |
| 979 | + ReflectionUtils.newInstance(encryptionContextClass, rawConfig); |
| 980 | + Preconditions.checkArgument(encryptionContextProvider != null, |
| 981 | + String.format("Failed to initialize %s", encryptionContextClass)); |
| 982 | + |
| 983 | + LOG.trace("{} init complete", encryptionContextClass.getName()); |
| 984 | + return encryptionContextProvider; |
| 985 | + } catch (Exception e) { |
| 986 | + throw new IllegalArgumentException( |
| 987 | + "Unable to load encryption context provider class: ", e); |
| 988 | + } |
| 989 | + } |
| 990 | + |
960 | 991 | public boolean isReadAheadEnabled() { |
961 | 992 | return this.enabledReadAhead; |
962 | 993 | } |
@@ -1068,9 +1099,22 @@ public boolean enableAbfsListIterator() { |
1068 | 1099 | return this.enableAbfsListIterator; |
1069 | 1100 | } |
1070 | 1101 |
|
1071 | | - public String getClientProvidedEncryptionKey() { |
1072 | | - String accSpecEncKey = accountConf(FS_AZURE_CLIENT_PROVIDED_ENCRYPTION_KEY); |
1073 | | - return rawConfig.get(accSpecEncKey, null); |
| 1102 | + public String getEncodedClientProvidedEncryptionKey() { |
| 1103 | + if (clientProvidedEncryptionKey == null) { |
| 1104 | + String accSpecEncKey = accountConf( |
| 1105 | + FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY); |
| 1106 | + clientProvidedEncryptionKey = rawConfig.get(accSpecEncKey, null); |
| 1107 | + } |
| 1108 | + return clientProvidedEncryptionKey; |
| 1109 | + } |
| 1110 | + |
| 1111 | + public String getEncodedClientProvidedEncryptionKeySHA() { |
| 1112 | + if (clientProvidedEncryptionKeySHA == null) { |
| 1113 | + String accSpecEncKey = accountConf( |
| 1114 | + FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA); |
| 1115 | + clientProvidedEncryptionKeySHA = rawConfig.get(accSpecEncKey, null); |
| 1116 | + } |
| 1117 | + return clientProvidedEncryptionKeySHA; |
1074 | 1118 | } |
1075 | 1119 |
|
1076 | 1120 | @VisibleForTesting |
|
0 commit comments