Skip to content

Commit f580576

Browse files
committed
Update name, simple samples and documentation
1 parent 6de6b4d commit f580576

File tree

8 files changed

+201
-17
lines changed

8 files changed

+201
-17
lines changed

ojdbc-provider-gcp/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The rest are dependent on the driver, in our case `/jdbc`. The key-value pairs t
6464
For example, let's suppose an url like:
6565

6666
<pre>
67-
jdbc:oracle:thin:@config-gcpobject://project=myproject;bucket=mybucket;object=payload_ojdbc_objectstorage.json
67+
jdbc:oracle:thin:@config-gcpstorage://project=myproject;bucket=mybucket;object=payload_ojdbc_objectstorage.json
6868
</pre>
6969

7070
And the JSON Payload for the file **payload_ojdbc_objectstorage.json** in the **mybucket** which belongs to the project **myproject** is as following:
@@ -198,6 +198,19 @@ Providers use Google Cloud APIs which support
198198
the libraries look for credentials in a set of defined locations and use those
199199
credentials to authenticate requests to the API.
200200

201+
When your code is running in a local development environment, such as a development workstation, the best option is to use the credentials associated with your user
202+
account.
201203

204+
###Configure ADC with your Google Account
205+
To configure ADC with a Google Account, you use the Google Cloud CLI:
202206

207+
1. Install and initialize the gcloud CLI.
208+
209+
When you initialize the gcloud CLI, be sure to specify a Google Cloud project in which you have permission to access the resources your application needs.
210+
211+
2. Configure ADC:
212+
```
213+
gcloud auth application-default login
214+
```
215+
A sign-in screen appears. After you sign in, your credentials are stored in the local credential file used by ADC.
203216

ojdbc-provider-gcp/src/main/java/oracle/jdbc/provider/gcp/configuration/GcpObjectStorageConfigurationProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class GcpObjectStorageConfigurationProvider extends OracleConfigurationJs
5858

5959
@Override
6060
public String getType() {
61-
return "gcpobject";
61+
return "gcpstorage";
6262
}
6363

6464
/**

ojdbc-provider-gcp/src/main/java/oracle/jdbc/provider/gcp/resource/GcpVaultSecretPasswordProvider.java

-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
*/
3838
package oracle.jdbc.provider.gcp.resource;
3939

40-
import java.io.UnsupportedEncodingException;
4140
import java.nio.charset.Charset;
42-
import java.util.Base64;
4341
import java.util.Map;
4442

4543
import com.google.protobuf.ByteString;

ojdbc-provider-gcp/src/test/java/oracle/provider/gcp/configuration/GcpObjectStorageProviderTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ private enum GcpTestProperties {
5656
}
5757

5858
static {
59-
OracleConfigurationProvider.allowedProviders.add("gcpobject");
59+
OracleConfigurationProvider.allowedProviders.add("gcpstorage");
6060
}
6161

62-
private static final OracleConfigurationProvider PROVIDER = OracleConfigurationProvider.find("gcpobject");
62+
private static final OracleConfigurationProvider PROVIDER = OracleConfigurationProvider.find("gcpstorage");
6363

6464
@Test
6565
public void testDefaultAuthentication() throws SQLException {

ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/gcp/configuration/ObjectStorageExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class ObjectStorageExample {
6868
* @throws SQLException if an error occurs during the database calls
6969
*/
7070
public static void main(String[] args) throws SQLException {
71-
String url = "jdbc:oracle:thin:@config-gcpobject://" + OBJECT_PROPERTIES;
71+
String url = "jdbc:oracle:thin:@config-gcpstorage://" + OBJECT_PROPERTIES;
7272

7373
// Standard JDBC code
7474
OracleDataSource ds = new OracleDataSource();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
** Copyright (c) 2024 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+
package oracle.jdbc.provider.gcp.configuration;
39+
40+
import oracle.jdbc.datasource.impl.OracleDataSource;
41+
42+
import java.sql.Connection;
43+
import java.sql.ResultSet;
44+
import java.sql.SQLException;
45+
import java.sql.Statement;
46+
47+
/**
48+
* A standalone example that configures Oracle JDBC to be provided with the
49+
* connection properties retrieved from OCI Object Storage.
50+
*/
51+
public class SimpleObjectStorageExample {
52+
53+
/**
54+
* <p>
55+
* Connects to a database using connection properties retrieved from GCP
56+
* Object Storage.
57+
* </p>
58+
*
59+
* @param args the command line arguments
60+
* @throws SQLException if an error occurs during the database calls
61+
*/
62+
public static void main(String[] args) throws SQLException {
63+
String url = "jdbc:oracle:thin:@config-gcpstorage://project=onyx-eye-426013-i5;bucket=fm-test-bucket-123564;object=testObjectStorage.json";
64+
65+
// Standard JDBC code
66+
OracleDataSource ds = new OracleDataSource();
67+
ds.setURL(url);
68+
69+
System.out.println("Connection URL: " + url);
70+
71+
try (Connection cn = ds.getConnection()) {
72+
String connectionString = cn.getMetaData().getURL();
73+
System.out.println("Connected to: " + connectionString);
74+
75+
Statement st = cn.createStatement();
76+
ResultSet rs = st.executeQuery("SELECT 'Hello, db' FROM sys.dual");
77+
if (rs.next())
78+
System.out.println(rs.getString(1));
79+
}
80+
}
81+
82+
}

ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/gcp/configuration/SimpleVaultJsonExample.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,13 @@
4343
import java.sql.Statement;
4444

4545
import oracle.jdbc.datasource.impl.OracleDataSource;
46-
import oracle.jdbc.provider.Configuration;
4746

4847
/**
4948
* A standalone example that configures Oracle JDBC to be provided with the
5049
* connection properties retrieved from GCP Secret Manager.
5150
*/
5251
public class SimpleVaultJsonExample {
5352

54-
/**
55-
* An GCP SecretManager resource name configured as a JVM system property,
56-
* environment variable, or configuration.properties file entry named
57-
* "gcp_secret_version_name_config".
58-
*/
59-
private static final String RESOURCE_NAME = Configuration
60-
.getRequired("gcp_secret_version_name_config");
61-
6253
/**
6354
* <p>
6455
* Simple example to retrieve connection properties from GCP Secret Manager.
@@ -79,7 +70,7 @@ public class SimpleVaultJsonExample {
7970
* @throws SQLException if an error occurs during the database calls
8071
**/
8172
public static void main(String[] args) throws SQLException {
82-
String url = "jdbc:oracle:thin:@config-gcpsecret://" + RESOURCE_NAME;
73+
String url = "jdbc:oracle:thin:@config-gcpsecret://projects/138028249883/secrets/config-secret/versions/4";
8374
// Sample default URL if non present
8475
if (args.length > 0) {
8576
url = args[0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
** Copyright (c) 2024 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+
package oracle.jdbc.provider.gcp.configuration;
39+
40+
import java.sql.Connection;
41+
import java.sql.ResultSet;
42+
import java.sql.SQLException;
43+
import java.sql.Statement;
44+
45+
import oracle.jdbc.datasource.impl.OracleDataSource;
46+
import oracle.jdbc.provider.Configuration;
47+
48+
/**
49+
* A standalone example that configures Oracle JDBC to be provided with the
50+
* connection properties retrieved from GCP Secret Manager.
51+
*/
52+
public class VaultJsonExample {
53+
54+
/**
55+
* An GCP SecretManager resource name configured as a JVM system property,
56+
* environment variable, or configuration.properties file entry named
57+
* "gcp_secret_version_name_config".
58+
*/
59+
private static final String RESOURCE_NAME = Configuration
60+
.getRequired("gcp_secret_version_name_config");
61+
62+
/**
63+
* <p>
64+
* Simple example to retrieve connection properties from GCP Secret Manager.
65+
* </p>
66+
* <p>
67+
* To run this example, the payload needs to be stored in GCP Secret Manager.
68+
* The payload examples can be found in
69+
* {@link oracle.jdbc.spi.OracleConfigurationProvider}.
70+
* </p>
71+
* Users need to indicate the resource name of the Secret with the following
72+
* syntax:
73+
*
74+
* <pre>
75+
* jdbc:oracle:thin:@config-gcpvault:{resource-name}
76+
* </pre>
77+
*
78+
* @param args the command line arguments
79+
* @throws SQLException if an error occurs during the database calls
80+
**/
81+
public static void main(String[] args) throws SQLException {
82+
String url = "jdbc:oracle:thin:@config-gcpsecret://" + RESOURCE_NAME;
83+
// Sample default URL if non present
84+
if (args.length > 0) {
85+
url = args[0];
86+
}
87+
88+
// No changes required, configuration provider is loaded at runtime
89+
OracleDataSource ds = new OracleDataSource();
90+
ds.setURL(url);
91+
92+
// Standard JDBC code
93+
try (Connection cn = ds.getConnection()) {
94+
Statement st = cn.createStatement();
95+
ResultSet rs = st.executeQuery("SELECT 'Hello, db' FROM sys.dual");
96+
if (rs.next())
97+
System.out.println(rs.getString(1));
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)