Skip to content

Commit e2570db

Browse files
committed
Add ojdbc-provider-pkl
1 parent 16bcae3 commit e2570db

File tree

7 files changed

+120
-143
lines changed

7 files changed

+120
-143
lines changed

ojdbc-provider-azure/src/main/java/oracle/jdbc/provider/azure/configuration/AzureConfigurationParameters.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/**
4646
* <p>
4747
* This class defines the common set of named parameters recognized by
48-
* {@link AzureAppConfigurationProvider} and {@link AzureVaultJsonSecretProvider}.
48+
* {@link AzureAppConfigurationProvider} and {@link AzureVaultSecretProvider}.
4949
* </p>
5050
*/
5151
public final class AzureConfigurationParameters {
@@ -58,7 +58,7 @@ private AzureConfigurationParameters() {}
5858
/**
5959
* Configures a {@code builder} to build a parser that recognizes the common
6060
* set of parameters accepted by {@link AzureAppConfigurationProvider} and
61-
* {@link AzureVaultJsonSecretProvider}.
61+
* {@link AzureVaultSecretProvider}.
6262
* @param builder Builder to configure. Not null.
6363
* @return The {@code builder}, with configuration added. Not null.
6464
*/

ojdbc-provider-azure/src/main/java/oracle/jdbc/provider/azure/configuration/AzureVaultJsonSecretProvider.java

-108
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,102 @@
1+
/*
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
3+
**
4+
** The Universal Permissive License (UPL), Version 1.0
5+
**
6+
** Subject to the condition set forth below, permission is hereby granted to any
7+
** person obtaining a copy of this software, associated documentation and/or data
8+
** (collectively the "Software"), free of charge and under any and all copyright
9+
** rights in the Software, and any and all patent rights owned or freely
10+
** licensable by each licensor hereunder covering either (i) the unmodified
11+
** Software as contributed to or provided by such licensor, or (ii) the Larger
12+
** Works (as defined below), to deal in both
13+
**
14+
** (a) the Software, and
15+
** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
** one is included with the Software (each a "Larger Work" to which the Software
17+
** is contributed by such licensors),
18+
**
19+
** without restriction, including without limitation the rights to copy, create
20+
** derivative works of, display, perform, and distribute the Software and make,
21+
** use, sell, offer for sale, import, export, have made, and have sold the
22+
** Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
** either these or other terms.
24+
**
25+
** This license is subject to the following condition:
26+
** The above copyright notice and either this complete permission notice or at
27+
** a minimum a reference to the UPL must be included in all copies or
28+
** substantial portions of the Software.
29+
**
30+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
** SOFTWARE.
37+
*/
38+
139
package oracle.jdbc.provider.azure.configuration;
240

41+
import com.azure.security.keyvault.secrets.models.KeyVaultSecret;
42+
import oracle.jdbc.provider.azure.keyvault.KeyVaultSecretFactory;
43+
import oracle.jdbc.provider.parameter.ParameterSet;
344
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
45+
import oracle.sql.json.OracleJsonObject;
446

47+
import java.util.Base64;
48+
import java.util.HashMap;
549
import java.util.Map;
650

7-
public class AzureVaultSecretProvider implements OracleConfigurationSecretProvider {
51+
import static oracle.jdbc.provider.azure.configuration.AzureVaultURLParser.PARAMETER_SET_PARSER;
52+
53+
/**
54+
* A provider of Secret values from Azure Key Vault.
55+
*/
56+
public final class AzureVaultSecretProvider
57+
implements OracleConfigurationSecretProvider {
858

59+
/**
60+
* {@inheritDoc}
61+
* <p>
62+
* Returns the password of the Secret that is retrieved from Azure Key Vault.
63+
* </p><p>
64+
* The {@code secretJsonObject} has the following form:
65+
* </p><pre>{@code
66+
* "password": {
67+
* "type": "azurevault",
68+
* "value": "https://myvault.vault.azure.net/secrets/mysecret",
69+
* "authentication": {
70+
* "method": "AZURE_DEFAULT"
71+
* }
72+
* }
73+
* }</pre>
74+
*
75+
* @param secretJsonObject json object to be parsed
76+
* @return encoded char array in base64 format that represents the retrieved
77+
* Secret.
78+
*/
979
@Override
10-
public char[] getSecret(Map<String, String> map) {
11-
return new char[0];
80+
public char[] getSecret(Map<String, String> secretMap) {
81+
ParameterSet parameters = PARAMETER_SET_PARSER.parseNamedValues(secretMap);
82+
83+
String secretString = KeyVaultSecretFactory.getInstance()
84+
.request(parameters)
85+
.getContent()
86+
.getValue();
87+
88+
return Base64.getEncoder()
89+
.encodeToString(secretString.getBytes())
90+
.toCharArray();
1291
}
1392

93+
/**
94+
* {@inheritDoc}
95+
*
96+
* @return secret type. Not null.
97+
*/
1498
@Override
1599
public String getSecretType() {
16-
return null;
100+
return "azurevault";
17101
}
18-
}
102+
}

ojdbc-provider-azure/src/main/java/oracle/jdbc/provider/azure/configuration/AzureVaultURLParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import oracle.jdbc.provider.parameter.ParameterSetParser;
4545

4646
/**
47-
* A URL parser used by {@link AzureVaultJsonSecretProvider} and {@link AzureVaultJsonProvider}.
47+
* A URL parser used by {@link AzureVaultSecretProvider} and {@link AzureVaultJsonProvider}.
4848
*/
4949
public class AzureVaultURLParser {
5050
/**
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
oracle.jdbc.provider.azure.configuration.AzureVaultJsonSecretProvider
1+
oracle.jdbc.provider.azure.configuration.AzureVaultSecretProvider

ojdbc-provider-oci/src/main/java/oracle/jdbc/provider/oci/configuration/OciVaultSecretProvider.java

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public char[] getSecret(Map<String, String> secretMap) {
8181
.request(parameters)
8282
.getContent();
8383

84-
// secretName = secret.
85-
8684
return secretBundle.getBase64Secret()
8785
.toCharArray();
8886
}

ojdbc-provider-pkl/pom.xml

+27-24
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,33 @@
7777
</executions>
7878
</plugin>
7979

80-
<plugin>
81-
<groupId>org.codehaus.mojo</groupId>
82-
<artifactId>exec-maven-plugin</artifactId>
83-
<version>3.3.0</version>
84-
<executions>
85-
<execution>
86-
<goals>
87-
<goal>java</goal>
88-
</goals>
89-
<phase>initialize</phase>
90-
</execution>
91-
</executions>
92-
<configuration>
93-
<mainClass>org.pkl.codegen.java.Main</mainClass>
94-
<arguments>
95-
<argument>--generate-javadoc</argument>
96-
<argument>-w</argument>
97-
<argument>${maven.multiModuleProjectDirectory}/ojdbc-provider-pkl</argument>
98-
<argument>-o</argument>
99-
<argument>${maven.multiModuleProjectDirectory}/ojdbc-provider-pkl/src/main</argument>
100-
<argument>src/main/resources/OjdbcConfig.pkl</argument>
101-
</arguments>
102-
</configuration>
103-
</plugin>
80+
<!-- <plugin>-->
81+
<!-- &lt;!&ndash; Comment out this plugin for now. We only need to generate the Java class from pkl template only once. &ndash;&gt;-->
82+
<!-- &lt;!&ndash; There are some changes being made manually in the generated Java class. For example, replacing &ndash;&gt;-->
83+
<!-- &lt;!&ndash; dots (.) in variable names with double dollar sign ($$), since dot is illegal in Java variable names. &ndash;&gt;-->
84+
<!-- <groupId>org.codehaus.mojo</groupId>-->
85+
<!-- <artifactId>exec-maven-plugin</artifactId>-->
86+
<!-- <version>3.3.0</version>-->
87+
<!-- <executions>-->
88+
<!-- <execution>-->
89+
<!-- <goals>-->
90+
<!-- <goal>java</goal>-->
91+
<!-- </goals>-->
92+
<!-- <phase>initialize</phase>-->
93+
<!-- </execution>-->
94+
<!-- </executions>-->
95+
<!-- <configuration>-->
96+
<!-- <mainClass>org.pkl.codegen.java.Main</mainClass>-->
97+
<!-- <arguments>-->
98+
<!-- <argument>&#45;&#45;generate-javadoc</argument>-->
99+
<!-- <argument>-w</argument>-->
100+
<!-- <argument>${maven.multiModuleProjectDirectory}/ojdbc-provider-pkl</argument>-->
101+
<!-- <argument>-o</argument>-->
102+
<!-- <argument>${maven.multiModuleProjectDirectory}/ojdbc-provider-pkl/src/main</argument>-->
103+
<!-- <argument>src/main/resources/OjdbcConfig.pkl</argument>-->
104+
<!-- </arguments>-->
105+
<!-- </configuration>-->
106+
<!-- </plugin>-->
104107
<plugin>
105108
<artifactId>maven-clean-plugin</artifactId>
106109
<version>3.3.2</version>

0 commit comments

Comments
 (0)