Skip to content

Commit 7f8f6be

Browse files
Merge branch 'main' into aws-parameter-store-centralized-config-provider
2 parents eac2c02 + ded8946 commit 7f8f6be

68 files changed

Lines changed: 4299 additions & 161 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-tests.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ jobs:
3333

3434
- name: Install dependencies
3535
run: mvn install -DskipTests
36+
37+
- name: Set GCP environment variables
38+
run : |
39+
echo "GOOGLE_APPLICATION_CREDENTIALS=$HOME/.gcp/config.json" >> $GITHUB_ENV
3640
3741
- name: Prepare certificate and properties files
3842
run: |
3943
mkdir -p $HOME/.azure
4044
mkdir -p $HOME/.oci
45+
mkdir -p $HOME/.gcp
4146
4247
# Prepare certificate
4348
echo "${{ secrets.TEST_AZURE_CERTIFICATE }}" > $HOME/.azure/ojdbc-plugin-test-app.pem
@@ -62,6 +67,8 @@ jobs:
6267
AZURE_TOKEN_SCOPE=${{ secrets.TEST_AZURE_TOKEN_SCOPE }}\n
6368
AZURE_APP_CONFIG_NAME=${{ secrets.TEST_AZURE_APP_CONFIG_NAME }}\n
6469
AZURE_APP_CONFIG_KEY=${{ secrets.TEST_AZURE_APP_CONFIG_KEY }}\n
70+
AZURE_APP_CONFIG_KEY_INVALID_PROPERTIES=${{ vars.TEST_AZURE_APP_CONFIG_KEY_INVALID_PROPERTIES }}\n
71+
AZURE_APP_CONFIG_KEY_NON_WHITELISTED_PROPERTIES=${{ vars.TEST_AZURE_APP_CONFIG_KEY_NON_WHITELISTED_PROPERTIES }}\n
6572
AZURE_APP_CONFIG_LABEL=${{ secrets.TEST_AZURE_APP_CONFIG_LABEL }}\n
6673
AZURE_KEY_VAULT_URL=${{ secrets.TEST_AZURE_KEY_VAULT_URL }}\n
6774
AZURE_KEY_VAULT_SECRET_NAME=${{ secrets.TEST_AZURE_KEY_VAULT_SECRET_NAME }}\n
@@ -131,6 +138,9 @@ jobs:
131138
AWS_SECRETS_MANAGER_URL=${{ secrets.TEST_AWS_SECRETS_MANAGER_URL }}\n
132139
" >> ojdbc-provider-aws/test.properties
133140
141+
# Generate GCP config
142+
echo "${{ secrets.TEST_GCP_CONFIG }}" > $HOME/.gcp/config.json
143+
echo "${{ secrets.GCP_TEST_PROPERTIES }}" > ojdbc-provider-gcp/test.properties
134144
135145
# Generate ojdbc-provider-hashicorp/test.properties
136146
echo -e "VAULT_ADDR=${{ secrets.TEST_VAULT_ADDR }}\n
@@ -165,6 +175,9 @@ jobs:
165175
rm ojdbc-provider-azure/ojdbc-provider-test-app.pfx
166176
rm ojdbc-provider-azure/test.properties
167177
178+
rm $HOME/.gcp/config.json
179+
rm ojdbc-provider-gcp/test.properties
180+
168181
rm ojdbc-provider-jackson-oson/test.properties
169182
170183
rm ojdbc-provider-aws/test.properties

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Each module of this project contains a set of providers.
1313
<dd>Providers for integration with Oracle Cloud Infrastructure (OCI).</dd>
1414
<dt><a href="ojdbc-provider-azure/README.md">Oracle JDBC Azure Providers</a></dt>
1515
<dd>Providers for integration with Microsoft Azure</dd>
16+
<dt><a href="ojdbc-provider-gcp/README.md">Oracle JDBC GCP Providers</a></dt>
17+
<dd>Providers for integration with Google Cloud Platform</dd>
1618
<dt><a href="ojdbc-provider-hashicorp/README.md">Oracle JDBC HashiCorp Providers</a></dt>
1719
<dd>Providers for integration with Hashicorp</dd>
1820
</dl>
@@ -130,6 +132,8 @@ this project:
130132

131133
[ojdbc-provider-azure](ojdbc-provider-azure/README.md#installation)
132134

135+
[ojdbc-provider-gcp](ojdbc-provider-gcp/README.md#installation)
136+
133137
[ojdbc-provider-opentelemetry](ojdbc-provider-opentelemetry/README.md#installation)
134138

135139
[ojdbc-provider-jackson-oson](ojdbc-provider-jackson-oson/README.md#installation)

ojdbc-provider-aws/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ JDK versions. The coordinates for the latest release are:
3333
<dependency>
3434
<groupId>com.oracle.database.jdbc</groupId>
3535
<artifactId>ojdbc-provider-aws</artifactId>
36-
<version>1.0.4</version>
36+
<version>1.0.5</version>
3737
</dependency>
3838
```
3939

@@ -76,7 +76,8 @@ And the JSON Payload for the file **payload_ojdbc_objectstorage.json** in **mybu
7676
"user": "scott",
7777
"password": {
7878
"type": "awssecretsmanager",
79-
"value": "test-secret"
79+
"value": "test-secret",
80+
"field_name": "<field-name>" // Optional: Only needed when the secret is structured and contains multiple key-value pairs.
8081
},
8182
"jdbc": {
8283
"oracle.jdbc.ReadTimeout": 1000,
@@ -118,6 +119,12 @@ For the JSON type of provider (AWS S3, AWS Secrets Manager, AWS Parameter Store,
118119
- Base64 Encoded password (if base64)
119120
- AWS Secret name (if awssecretsmanager)
120121
- AWS Parameter name (if awsparameterstore)
122+
- field_name
123+
- Optional
124+
- Description: Specifies the key within the secret JSON object from which to extract the password value.
125+
If the secret JSON contains multiple key-value pairs, field_name must be provided to unambiguously select the desired secret value.
126+
If the secret contains only a single key-value pair and field_name is not provided, that sole value will be used.
127+
If the secret is provided as plain text (i.e., not structured as a JSON object), no field_name is required.
121128
- authentication
122129
- Optional
123130
- Possible Values

ojdbc-provider-aws/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>com.oracle.database.jdbc</groupId>
1212
<artifactId>ojdbc-extensions</artifactId>
13-
<version>1.0.4</version>
13+
<version>1.0.5</version>
1414
</parent>
1515

1616
<dependencyManagement>

ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsConfigurationParameters.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ private AwsConfigurationParameters() {}
5959
*/
6060
public static final Parameter<String> KEY = Parameter.create();
6161

62+
/**
63+
* The field name for extracting a specific value from the JSON.
64+
*/
65+
public static final Parameter<String> FIELD_NAME = Parameter.create();
66+
6267
/**
6368
* Configures a {@code builder} to build a parser that recognizes the common
6469
* set of parameters accepted by {@link AwsS3ConfigurationProvider} and

ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,23 @@
4040
import oracle.jdbc.provider.aws.secrets.SecretsManagerFactory;
4141
import oracle.jdbc.provider.parameter.ParameterSet;
4242
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
43+
import oracle.sql.json.OracleJsonException;
44+
import oracle.sql.json.OracleJsonFactory;
4345
import oracle.sql.json.OracleJsonObject;
4446

47+
import java.io.ByteArrayInputStream;
48+
import java.nio.charset.StandardCharsets;
4549
import java.util.Base64;
4650
import java.util.Map;
4751

52+
import static oracle.jdbc.provider.aws.configuration.AwsConfigurationParameters.FIELD_NAME;
4853
import static oracle.jdbc.provider.aws.configuration.AwsSecretsManagerConfigurationProvider.PARAMETER_SET_PARSER;
4954

5055
public class AwsJsonSecretsManagerProvider
5156
implements OracleConfigurationSecretProvider {
57+
58+
private static final OracleJsonFactory JSON_FACTORY = new OracleJsonFactory();
59+
5260
/**
5361
* {@inheritDoc}
5462
* <p>
@@ -62,24 +70,59 @@ public class AwsJsonSecretsManagerProvider
6270
* <pre>{@code
6371
* "password": {
6472
* "type": "awssecretsmanager",
65-
* "value": "<secret-name>"
73+
* "value": "<secret-name>",
74+
* "field_name": "<field-name>"
6675
* }
6776
* }</pre>
6877
*
78+
* <p>
79+
* The {@code field_name} parameter indicates the key whose value should
80+
* be extracted as the secret. When there are multiple key-value pairs
81+
* present, specifying this parameter is mandatory in order to
82+
* unambiguously select the desired secret value. If the secret contains
83+
* only a single entry and no {@code field_name} is provided, that sole
84+
* value will be used. In cases where the secret is plain text,
85+
* the {@code field_name} parameter is not required.
86+
* </p>
87+
*
6988
* @param map Map object to be parsed
7089
* @return encoded char array in base64 format that represents the retrieved
7190
* Secret.
7291
*/
7392
@Override
7493
public char[] getSecret(Map<String, String> map) {
7594
ParameterSet parameterSet = PARAMETER_SET_PARSER.parseNamedValues(map);
95+
String fieldName = parameterSet.getOptional(FIELD_NAME);
7696

7797
String secretString = SecretsManagerFactory.getInstance()
7898
.request(parameterSet)
7999
.getContent();
80100

101+
String extractedSecret;
102+
103+
try {
104+
OracleJsonObject jsonObject = JSON_FACTORY.createJsonTextValue(
105+
new ByteArrayInputStream(secretString.getBytes(StandardCharsets.UTF_8)))
106+
.asJsonObject();
107+
108+
if (fieldName != null) {
109+
if (!jsonObject.containsKey(fieldName)) {
110+
throw new IllegalStateException("Field '" + fieldName + "' not found in secret JSON.");
111+
}
112+
extractedSecret = jsonObject.get(fieldName).asJsonString().getString();
113+
} else if (jsonObject.size() == 1) {
114+
extractedSecret = jsonObject.values().iterator().next().asJsonString().getString();
115+
} else {
116+
throw new IllegalStateException(
117+
"FIELD_NAME is required when multiple keys exist in the secret JSON");
118+
}
119+
120+
} catch (OracleJsonException e) {
121+
extractedSecret = secretString;
122+
}
123+
81124
return Base64.getEncoder()
82-
.encodeToString(secretString.getBytes())
125+
.encodeToString(extractedSecret.getBytes(StandardCharsets.UTF_8))
83126
.toCharArray();
84127
}
85128

ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsSecretsManagerConfigurationProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import oracle.jdbc.driver.configuration.OracleConfigurationParsableProvider;
4141
import oracle.jdbc.provider.aws.secrets.SecretsManagerFactory;
42+
import oracle.jdbc.provider.parameter.Parameter;
4243
import oracle.jdbc.provider.parameter.ParameterSet;
4344
import oracle.jdbc.provider.parameter.ParameterSetParser;
4445
import oracle.jdbc.util.OracleConfigurationCache;
@@ -64,6 +65,8 @@ public class AwsSecretsManagerConfigurationProvider extends OracleConfigurationP
6465
ParameterSetParser.builder()
6566
.addParameter("value", SecretsManagerFactory.SECRET_NAME)
6667
.addParameter("key", AwsConfigurationParameters.KEY)
68+
.addParameter("type", Parameter.create())
69+
.addParameter("field_name", AwsConfigurationParameters.FIELD_NAME)
6770
.addParameter("AWS_REGION", AwsConfigurationParameters.REGION))
6871
.build();
6972

ojdbc-provider-azure/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ JDK versions. The coordinates for the latest release are:
4444
<dependency>
4545
<groupId>com.oracle.database.jdbc</groupId>
4646
<artifactId>ojdbc-provider-azure</artifactId>
47-
<version>1.0.4</version>
47+
<version>1.0.5</version>
4848
</dependency>
4949
```
5050

ojdbc-provider-azure/example-test.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ AZURE_APP_CONFIG_NAME=app-config-name
117117
# The prefix of the Azure App Configuration key-names
118118
AZURE_APP_CONFIG_KEY=your-app-config-key/
119119

120+
# The prefix of the Azure App Configuration key-names which contains invalid properties
121+
AZURE_APP_CONFIG_KEY_INVALID_PROPERTIES=your-app-config-key-with-invalid-properties/
122+
123+
# The prefix of the Azure App Configuration key-names which contains non-whitelisted properties
124+
AZURE_APP_CONFIG_KEY_NON_WHITELISTED_PROPERTIES=your-app-config-key-with-non-whitelisted-properties/
125+
120126
# The label of the Azure App Configuration
121127
AZURE_APP_CONFIG_LABEL=your-label
122128

ojdbc-provider-azure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>com.oracle.database.jdbc</groupId>
1212
<artifactId>ojdbc-extensions</artifactId>
13-
<version>1.0.4</version>
13+
<version>1.0.5</version>
1414
</parent>
1515

1616
<dependencyManagement>

0 commit comments

Comments
 (0)