From 6e099f1b0c612b6aaa19e34594e74b6e33ed29ec Mon Sep 17 00:00:00 2001 From: ting-lan-wang Date: Fri, 6 Dec 2024 17:39:19 -0500 Subject: [PATCH] Update JavaDoc --- .../authentication/AwsCredentialsFactory.java | 58 ++----------------- .../AwsJsonSecretsManagerProvider.java | 21 +++++++ .../AwsS3ConfigurationProvider.java | 13 +++++ ...wsSecretsManagerConfigurationProvider.java | 18 +++++- 4 files changed, 56 insertions(+), 54 deletions(-) diff --git a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/authentication/AwsCredentialsFactory.java b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/authentication/AwsCredentialsFactory.java index 4a4d38bf..2ef7a242 100644 --- a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/authentication/AwsCredentialsFactory.java +++ b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/authentication/AwsCredentialsFactory.java @@ -67,22 +67,18 @@ public final class AwsCredentialsFactory implements ResourceFactory { - /** Method of authentication supported by the Azure SDK */ + /** Method of authentication supported by the AWS SDK */ public static final Parameter AUTHENTICATION_METHOD = Parameter.create(REQUIRED); - public static final Parameter ACCESS_KEY_ID = Parameter.create(REQUIRED); - - public static final Parameter SECRET_ACCESS_KEY = Parameter.create(SENSITIVE, REQUIRED); - private static final AwsCredentialsFactory INSTANCE = new AwsCredentialsFactory(); private AwsCredentialsFactory() { } /** - * Returns a singleton of {@code TokenCredentialFactory}. - * @return a singleton of {@code TokenCredentialFactory} + * Returns a singleton of {@code AwsCredentialsFactory}. + * @return a singleton of {@code AwsCredentialsFactory} */ public static AwsCredentialsFactory getInstance() { return INSTANCE; @@ -98,7 +94,7 @@ public Resource request(ParameterSet parameterSet) { /** * Returns credentials for requesting an access token. The type of credentials - * used are configured by the parameters of the given {@code parameters}. + * used are configured by the parameters of the given {@code parameterSet}. * Supported parameters are defined by the class variables in * {@link AwsCredentialsFactory}. * @param parameterSet parameters that configure credentials. Not null. @@ -111,7 +107,7 @@ private static AwsCredentials getCredential(ParameterSet parameterSet) { switch (authenticationMethod) { case DEFAULT: - return defaultCredentials(parameterSet); + return defaultCredentials(); default : throw new IllegalArgumentException( "Unrecognized authentication method: " + authenticationMethod); @@ -120,53 +116,11 @@ private static AwsCredentials getCredential(ParameterSet parameterSet) { /** * Returns credentials resolved by {@link AppConfigDataClient}. - * @param parameterSet * @return */ - private static AwsCredentials defaultCredentials(ParameterSet parameterSet) { + private static AwsCredentials defaultCredentials() { return DefaultCredentialsProvider .builder() .build().resolveCredentials(); } - - /** - * Returns the value of a required parameter that may be configured by a - * provider or an SDK environment variable. - * @param parameters Parameters provided by the provider. Not null - * @param parameter Parameter that may be configured by the provider. Not null - * @param sdkName Name of the SDK environment variable, or null if there is - * none. - * @return The configured value of the parameter. Not null. - * @throws IllegalStateException If the parameter is not configured by the - * provider or the SDK. - */ - private static String requireParameter( - ParameterSet parameters, Parameter parameter, String sdkName) { - try { - return parameters.getRequired(parameter); - } - catch (IllegalStateException parameterNotConfigured) { - throw new IllegalArgumentException(format( - "No value is configured for parameter \"%s\"," + - " or SDK variable \"%s\"", - parameters.getName(parameter), sdkName), parameterNotConfigured); - } - } - - /** - * Returns the value of an optional parameter which may be configured by a - * provider or an SDK environment variable. - * @param parameters Parameters provided by the provider. Not null - * @param parameter Parameter that may be configured by the provider. Not null - * @param sdkName Name of the SDK environment variable, or null if there is - * none. - * @return The configured value of the parameter, or null if not configured. - */ - private static String optionalParameter( - ParameterSet parameters, Parameter parameter, String sdkName) { - String value = parameters.getOptional(parameter); - - return value != null ? value : null; - } - } diff --git a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java index ff38cbca..fe749c9e 100644 --- a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java +++ b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java @@ -12,6 +12,27 @@ public class AwsJsonSecretsManagerProvider implements OracleConfigurationJsonSecretProvider { + /** + * {@inheritDoc} + *

+ * Returns the password of the Secret that is retrieved from AWS Secrets + * Manager secret. + *

+ *

+ * The {@code jsonObject} has the following form: + *

+ * + *
{@code
+   *   "password": {
+   *       "type": "awssecretsmanager",
+   *       "value": ""
+   *   }
+   * }
+ * + * @param jsonObject json object to be parsed + * @return encoded char array in base64 format that represents the retrieved + * Secret. + */ @Override public char[] getSecret(OracleJsonObject jsonObject) { ParameterSet parameterSet = diff --git a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3ConfigurationProvider.java b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3ConfigurationProvider.java index 7c41f14f..29fcbc05 100644 --- a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3ConfigurationProvider.java +++ b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3ConfigurationProvider.java @@ -9,8 +9,21 @@ import java.net.URISyntaxException; import java.sql.SQLException; +/** + * A provider for JSON payload which contains configuration from AWS S3. + * See {@link #getJson(String)} for the spec of the JSON payload. + **/ public class AwsS3ConfigurationProvider extends OracleConfigurationJsonProvider { + /** + * {@inheritDoc} + *

+ * Returns the JSON payload stored in AWS S3. + *

+ * + * @param s3Url URI of the object stored in AWS S3 + * @return JSON payload + */ @Override public InputStream getJson(String s3Url) throws SQLException { diff --git a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationProvider.java b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationProvider.java index dee11197..4bd2c296 100644 --- a/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationProvider.java +++ b/ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationProvider.java @@ -10,6 +10,11 @@ import java.util.HashMap; import java.util.Map; +/** + * A provider for JSON payload which contains configuration from AWS Secrets + * Manager. + * See {@link #getJson(String)} for the spec of the JSON payload. + **/ public class AwsSecretsManagerConfigurationProvider extends OracleConfigurationJsonProvider { /** @@ -24,11 +29,20 @@ public class AwsSecretsManagerConfigurationProvider extends OracleConfigurationJ .addParameter("key_name", SecretsManagerFactory.KEY_NAME)) .build(); + /** + * {@inheritDoc} + *

+ * Returns the JSON payload stored in AWS Secrets Manager secret. + *

+ * + * @param secretName name of the secret + * @return JSON payload + */ @Override - public InputStream getJson(String secretId) { + public InputStream getJson(String secretName) { final String valueFieldName = "value"; Map optionsWithSecret = new HashMap<>(options); - optionsWithSecret.put(valueFieldName, secretId); + optionsWithSecret.put(valueFieldName, secretName); ParameterSet parameters = PARAMETER_SET_PARSER.parseNamedValues(optionsWithSecret);