From b5a9f954758b791f399f02cfc001eb4d602f3e46 Mon Sep 17 00:00:00 2001 From: ting-lan-wang Date: Thu, 16 Jan 2025 14:57:01 -0500 Subject: [PATCH] Update AWS Example and make "s3://" optional --- .../AwsS3ConfigurationProvider.java | 9 ++++++++- .../aws/configuration/AwsS3Example.java | 19 ++++++++++++++++--- ...AwsSecretsManagerConfigurationExample.java | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) 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 29fcbc05..c0c6aabf 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 @@ -29,7 +29,7 @@ public InputStream getJson(String s3Url) throws SQLException { URI uri = null; try { - uri = new URI(s3Url); + uri = getURI(s3Url); } catch (URISyntaxException uriSyntaxException) { throw new SQLException(uriSyntaxException); } @@ -53,4 +53,11 @@ public InputStream getJson(String s3Url) throws SQLException { public String getType() { return "awss3"; } + + private URI getURI(String s3Url) throws URISyntaxException { + if (!s3Url.startsWith("s3://")) { + s3Url = "s3://" + s3Url; + } + return new URI(s3Url); + } } \ No newline at end of file diff --git a/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3Example.java b/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3Example.java index e361c294..6fa0e884 100644 --- a/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3Example.java +++ b/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsS3Example.java @@ -44,15 +44,28 @@ import java.sql.SQLException; import java.sql.Statement; +/** + * A standalone example that configures Oracle JDBC to be provided with the + * connection properties retrieved from AWS S3. + */ public class AwsS3Example { private static String url; + + /** + *

+ * A simple example to retrieve connection properties from AWS S3. + *

+ * For the default authentication, the only required local configuration is + * to have a valid AWS Config in ~/.aws/config and ~/.aws/credentials. + *

+ * @param args the command line arguments + * @throws SQLException if an error occurs during the database calls + */ public static void main(String[] args) throws SQLException { // Sample default URL if non present if (args.length == 0) { -// url = "jdbc:oracle:thin:@config-awss3://s3://{bucket-name}/{key-name}"; - url = "jdbc:oracle:thin:@config-awss3://s3://tinglwan-general-bucket/folder1/payload_ojdbc_adb_aws_secret.json"; -// url = "jdbc:oracle:thin:@config-file:///Users/tinglwang/Notes/ojdbc-plugins/ociobject/payload_ojdbc_wallet_location_base64_sso.json"; + url = "jdbc:oracle:thin:@config-awss3://{bucket-name}/{key-name}"; } else { url = args[0]; } diff --git a/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationExample.java b/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationExample.java index d5ba47e8..551ce448 100644 --- a/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationExample.java +++ b/ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationExample.java @@ -1,14 +1,30 @@ package oracle.jdbc.provider.aws.configuration; import oracle.jdbc.datasource.impl.OracleDataSource; +import oracle.jdbc.provider.oci.configuration.ObjectStorageExample; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +/** + * A standalone example that configures Oracle JDBC to be provided with the + * connection properties retrieved from AWS Secrets Manager. + */ public class AwsSecretsManagerConfigurationExample { private static String url; + + /** + *

+ * A simple example to retrieve connection properties from AWS Secrets Manager. + *

+ * For the default authentication, the only required local configuration is + * to have a valid AWS Config in ~/.aws/config and ~/.aws/credentials. + *

+ * @param args the command line arguments + * @throws SQLException if an error occurs during the database calls + */ public static void main(String[] args) throws SQLException { // Sample default URL if non present