Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapted providers to new version of the driver #148

Merged
merged 25 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ojdbc-provider-azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JDK versions. The coordinates for the latest release are:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-azure</artifactId>
<version>1.0.1</version>
<version>1.0.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* {@link TokenCredential} created by {@link TokenCredentialFactory} is passed
* to the {@link #request(TokenCredential, ParameterSet)} method of a subclass.
* </p>
* @param <T> the type
*/
public abstract class AzureResourceFactory<T> implements ResourceFactory<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import oracle.jdbc.spi.OracleConfigurationCachableProvider;
import oracle.jdbc.util.OracleConfigurationCache;
import oracle.jdbc.util.OracleConfigurationProviderNetworkError;
import oracle.jdbc.spi.OracleConfigurationProvider;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.azure.authentication.TokenCredentialFactory;
import oracle.sql.json.OracleJsonFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

package oracle.jdbc.provider.azure.configuration;

import oracle.jdbc.driver.OracleConfigurationJsonProvider;
import oracle.jdbc.driver.configuration.OracleConfigurationParsableProvider;
import oracle.jdbc.provider.azure.keyvault.KeyVaultSecretFactory;
import oracle.jdbc.provider.parameter.Parameter;
import oracle.jdbc.provider.parameter.ParameterSet;
Expand All @@ -52,9 +52,9 @@

/**
* A provider for JSON payload which contains configuration from Azure Vault.
* See {@link #getJson(String)} for the spec of the JSON payload.
* See {@link #getInputStream(String)} for the spec of the JSON payload.
*/
public class AzureVaultJsonProvider extends OracleConfigurationJsonProvider {
public class AzureVaultJsonProvider extends OracleConfigurationParsableProvider {

/**
* Parser that recognizes the "key" and "value" field,
Expand Down Expand Up @@ -85,7 +85,7 @@ public class AzureVaultJsonProvider extends OracleConfigurationJsonProvider {
* @return JSON payload
**/
@Override
public InputStream getJson(String secretIdentifier) {
public InputStream getInputStream(String secretIdentifier) {
final String valueFieldName = "value";
Map<String, String> optionsWithSecret = new HashMap<>(options);
optionsWithSecret.put(valueFieldName, secretIdentifier);
Expand Down Expand Up @@ -116,6 +116,11 @@ public String getType() {
return "azurevault";
}

@Override
public String getParserType(String arg0) {
return "json";
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@
package oracle.jdbc.provider.azure.configuration;

import oracle.jdbc.provider.azure.keyvault.KeyVaultSecretFactory;
import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider;
import oracle.jdbc.provider.configuration.JsonSecretUtil;
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
import oracle.sql.json.OracleJsonObject;
import oracle.jdbc.provider.parameter.Parameter;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.parameter.ParameterSetParser;
import oracle.sql.json.OracleJsonObject;

import java.util.Base64;
import java.util.Map;

/**
* A provider of Secret values from Azure Key Vault.
*/
public final class AzureVaultSecretProvider
implements OracleConfigurationJsonSecretProvider {
implements OracleConfigurationSecretProvider {
/**
* Parser that recognizes the "value" field and parses it as a Key Vault
* secret URL.
Expand All @@ -62,15 +64,16 @@ public final class AzureVaultSecretProvider
public static final ParameterSetParser PARAMETER_SET_PARSER =
AzureConfigurationParameters.configureBuilder(
ParameterSetParser.builder()
.addParameter("type", Parameter.create())
.addParameter("value", AzureVaultURLParser::parseVaultSecretUri))
.build();

/**
* {@inheritDoc}
* <p>
* Returns the password of the Secret that is retrieved from Azure Key Vault.
* Returns the password of the Secret that is retrieved from Azure Key Vault.
* </p><p>
* The {@code secretJsonObject} has the following form:
* The JSON object has the following form:
* </p><pre>{@code
* "password": {
* "type": "azurevault",
Expand All @@ -81,16 +84,15 @@ public final class AzureVaultSecretProvider
* }
* }</pre>
*
* @param secretJsonObject json object to be parsed
* @param secretProperties a map containing the flattened JSON object.
* @return encoded char array in base64 format that represents the retrieved
* Secret.
*/
@Override
public char[] getSecret(OracleJsonObject secretJsonObject) {
public char[] getSecret(Map<String, String> secretProperties) {

ParameterSet parameterSet =
PARAMETER_SET_PARSER.parseNamedValues(
JsonSecretUtil.toNamedValues(secretJsonObject));
PARAMETER_SET_PARSER.parseNamedValues(secretProperties);

String secretString = KeyVaultSecretFactory.getInstance()
.request(parameterSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
import oracle.jdbc.provider.azure.authentication.AzureAuthenticationMethod;
import oracle.jdbc.provider.azure.AzureTestProperty;
import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider;
import oracle.sql.json.OracleJsonFactory;
import oracle.sql.json.OracleJsonObject;
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static oracle.jdbc.provider.TestProperties.getOrAbort;
import java.util.HashMap;
import java.util.Map;

public class AzureVaultSecretProviderTest {
private static final OracleConfigurationJsonSecretProvider PROVIDER =
OracleConfigurationJsonSecretProvider.find("azurevault");
private static final OracleConfigurationSecretProvider PROVIDER =
OracleConfigurationSecretProvider.find("azurevault");

/**
* Verifies {@link OracleConfigurationJsonSecretProvider} as implementing
Expand All @@ -61,7 +61,7 @@ public class AzureVaultSecretProviderTest {
@Test
public void test() {
Assertions.assertNotNull(PROVIDER.getSecret(
constructJsonObject(
constructSecretProperties(
TestProperties.getOrAbort(AzureTestProperty.AZURE_KEY_VAULT_URL),
TestProperties.getOrAbort(AzureTestProperty.AZURE_KEY_VAULT_SECRET_NAME),
TestProperties.getOrAbort(AzureTestProperty.AZURE_CLIENT_ID),
Expand All @@ -84,7 +84,6 @@ public void test() {
* }
* }
* </pre>
*/
private OracleJsonObject constructJsonObject(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this method.

String vaultUrl, String secretName, String clientId, String clientSecret, String tenantId) {

Expand All @@ -103,6 +102,19 @@ private OracleJsonObject constructJsonObject(

return password;
}
*/

private Map<String,String> constructSecretProperties(
String vaultUrl, String secretName, String clientId, String clientSecret, String tenantId) {
Map<String,String> secretProperties = new HashMap<>();
secretProperties.put("AUTHENTICATION", "AZURE_SERVICE_PRINCIPAL");
secretProperties.put("AZURE_CLIENT_ID", clientId);
secretProperties.put("AZURE_CLIENT_SECRET", clientSecret);
secretProperties.put("AZURE_TENANT_ID", tenantId);
secretProperties.put("type", "azurevault");
secretProperties.put("value", constructSecretUri(vaultUrl, secretName));
return secretProperties;
}

private String constructSecretUri(String vaultUrl, String secretName) {
if (!vaultUrl.endsWith("/")) {
Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions ojdbc-provider-jackson-oson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JDK versions. The coordinates for the latest release are:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-jackson-oson</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```
### Note
Expand All @@ -56,7 +56,7 @@ It can be done in maven as:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-jackson-oson</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<exclusions>
<exclusion>
<groupId>com.oracle.database.jdbc</groupId>
Expand Down
4 changes: 2 additions & 2 deletions ojdbc-provider-jackson-oson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<artifactId>ojdbc-provider-jackson-oson</artifactId>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-common</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public void writeNull() throws IOException {

/**
* Checks if the generator is closed.
* @return
* @return true if the generator is closed, otherwise false.
*/
@Override
public boolean isClosed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* <li>{@link Duration} - {@link OsonDurationDeserializer} and {@link OsonDurationSerializer}</li>
* <li>{@link BigInteger} - {@link OsonBigIntegerDeserializer} and {@link OsonBigIntegerSerializer}</li>
* <li>{@link Year} - {@link OsonYearDeserializer} and {@link OsonYearSerializer}</li>
* <li>{@link byte[]} - {@link OsonByteDeserializer} and {@link OsonByteSerializer}</li>
* <li>byte[] - {@link OsonByteDeserializer} and {@link OsonByteSerializer}</li>
* <li>{@link java.util.Date}- {@link OsonDateSerializer} and {@link OsonDateDeserializer} </li>
* <li>{@link java.sql.Date}- {@link OsonDateSerializer} and {@link OsonSqlDateDeserializer} </li>
* <li>{@link Timestamp}- {@link OsonDateSerializer} and {@link OsonTimeStampDeserializer} </li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@
*
* @see StdScalarDeserializer
* @see OsonParser
* @see byte[]
*/
*/
public class OsonByteDeserializer extends StdScalarDeserializer<byte[]> {
/**
/**
* A singleton instance of the deserializer.
*/
public static final OsonByteDeserializer INSTANCE = new OsonByteDeserializer();

/**
* Default constructor that initializes the deserializer for the {@link byte[]} class.
/**
* Default constructor that initializes the deserializer for the byte[] class.
*/
protected OsonByteDeserializer() {
super(Year.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
*
* @see StdSerializer
* @see OsonGenerator
* @see byte[]
*/
public class OsonByteSerializer extends StdSerializer<byte[]> {

Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-oci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ JDK versions. The coordinates for the latest release are:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-oci</artifactId>
<version>1.0.1</version>
<version>1.0.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-oci/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private OciConfigurationParameters(){}
ParameterSetParser.builder()
.addParameter("key", KEY, "")
.addParameter("value", OCID, "")
.addParameter("type", Parameter.create())
.addParameter("object_url", OBJECT_URL, "")
.addParameter("AUTHENTICATION", AUTHENTICATION_METHOD,
API_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

package oracle.jdbc.provider.oci.configuration;

import oracle.jdbc.driver.OracleConfigurationJsonProvider;
import oracle.jdbc.driver.configuration.OracleConfigurationParsableProvider;
import oracle.jdbc.provider.oci.objectstorage.ObjectFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.util.OracleConfigurationCache;
Expand All @@ -49,10 +49,10 @@

/**
* A provider for JSON payload which contains configuration from OCI Object
* Storage. See {@link #getJson(String)} for the spec of the JSON payload.
* Storage. See {@link #getInputStream(String)} for the spec of the JSON payload.
*/
public class OciObjectStorageProvider
extends OracleConfigurationJsonProvider {
extends OracleConfigurationParsableProvider {

/**
* {@inheritDoc}
Expand All @@ -71,7 +71,7 @@ public class OciObjectStorageProvider
* @return JSON payload
*/
@Override
public InputStream getJson(String objectUrl) {
public InputStream getInputStream(String objectUrl) {
// Add implicit prefix if not informed
if (!objectUrl.startsWith("https://")) {
objectUrl = "https://" + objectUrl;
Expand Down Expand Up @@ -101,6 +101,11 @@ public String getType() {
return "ociobject";
}

@Override
public String getParserType(String arg0) {
return "json";
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
Expand Down
Loading
Loading