Skip to content

Commit f614e9e

Browse files
authored
Merge pull request #1 from oracle-devrel/initial-commit
Initial commit
2 parents 7a88356 + be56be3 commit f614e9e

File tree

14 files changed

+3152
-8
lines changed

14 files changed

+3152
-8
lines changed

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,39 @@
22

33
[![License: UPL](https://img.shields.io/badge/license-UPL-green)](https://img.shields.io/badge/license-UPL-green) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=oracle-devrel_oci-java-sdk-simple-wrappers)](https://sonarcloud.io/dashboard?id=oracle-devrel_oci-java-sdk-simple-wrappers)
44

5-
## THIS IS A NEW, BLANK REPO THAT IS NOT READY FOR USE YET. PLEASE CHECK BACK SOON!
6-
75
## Introduction
8-
MISSING
6+
This is a small set of wrappers around the OCI Java SDK.
7+
8+
I created it because while the oci java SDK is very powerfuil it's also not a model I foound intuitive (for me at least) So as I need them I have been creating simple wrappers around the OCI Java SDK to help me do things. Of course you may not find them to be useful, but they help me.
9+
10+
This is by no means a complete set of functionality, it's focused on things that I needed to do, but I suspect over time more capabilities will be added.
911

1012
## Getting Started
11-
MISSING
13+
You will need to have setup a OCI tenancy, and created a user within that tenancy. That user should have the appropriate permisions (set via OCI policies) to do the things you want to use - this code **will not** override the OCI security (not least of which is it's impemented in the API, not my code).
14+
15+
To get started you will also user API signing keys and credentials for the user in OCI and a ".oci" directory appropriately configured ([see the OCI documentation on hos to do this](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File))
16+
17+
To use the code to manage objects in OCI you will need to :
18+
19+
Create an AuthenticationProcessor (com.oracle.timg.oci.authentication) - this does the security work for you, speciy the OCI configuration file section to use for the connection and optionall the OCI region to work on (by defual it will sue the region in the config file)
20+
21+
From there use the other processor classes as needed, these will all need the AuthenticationProcessor you created as part of their consructor.
22+
23+
1224

1325
### Prerequisites
14-
MISSING
26+
You will need a development environment with Java (17 is the cersion Im using, earlier versions may not be supported by the OCI Java SDK).
27+
28+
I also use Maven to build this and to manage the dependencies, but if you have other mechanisms feel free.
29+
30+
I use [Lombok](https://projectlombok.org/) to generate logs and the like, this is included in the Maven pom.xml, but your IDE or compile time will need to include the lombok jar file to process the annotations - usually just running the lombok jar file will let you locate the IDE and install it for you.
31+
1532

1633
## Notes/Issues
17-
MISSING
34+
This is a **very** limited set of OCI services that are being wrapped here, over time I'll probabaly add some more.
1835

1936
## URLs
20-
* Nothing at this time
37+
[The OCI Java SDK is documented here](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk.htm)
2138

2239
## Contributing
2340
This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open source community.
@@ -29,4 +46,4 @@ Licensed under the Universal Permissive License (UPL), Version 1.0.
2946

3047
See [LICENSE](LICENSE) for more details.
3148

32-
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
49+
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
<attribute name="optional" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
16+
<attributes>
17+
<attribute name="optional" value="true"/>
18+
<attribute name="maven.pomderived" value="true"/>
19+
<attribute name="test" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
23+
<attributes>
24+
<attribute name="maven.pomderived" value="true"/>
25+
<attribute name="test" value="true"/>
26+
<attribute name="optional" value="true"/>
27+
</attributes>
28+
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
30+
<attributes>
31+
<attribute name="maven.pomderived" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
35+
<attributes>
36+
<attribute name="maven.pomderived" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="output" path="target/classes"/>
40+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>oci-java-sdk-simple-wrappers</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
4+
encoding//src/test/java=UTF-8
5+
encoding//src/test/resources=UTF-8
6+
encoding/<project>=UTF-8
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!-- Copyright (c) 2023 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE. -->
36+
37+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
38+
<modelVersion>4.0.0</modelVersion>
39+
<groupId>com.oracle.timg.demo</groupId>
40+
<artifactId>oci-java-sdk-simple-wrappers</artifactId>
41+
<name>ocicore</name>
42+
<version>1.0.0</version>
43+
<properties>
44+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45+
<version.ocisdk>3.17.0</version.ocisdk>
46+
<version.lombok>1.18.28</version.lombok>
47+
<version.slf4j>2.0.7</version.slf4j>
48+
<maven.compiler.source>17</maven.compiler.source>
49+
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
50+
</properties>
51+
<dependencyManagement>
52+
<dependencies>
53+
<dependency>
54+
<groupId>com.oracle.oci.sdk</groupId>
55+
<artifactId>oci-java-sdk-bom</artifactId>
56+
<version>${version.ocisdk}</version>
57+
<type>pom</type>
58+
<scope>import</scope>
59+
</dependency>
60+
</dependencies>
61+
</dependencyManagement>
62+
<dependencies>
63+
<dependency>
64+
<groupId>com.oracle.oci.sdk</groupId>
65+
<artifactId>oci-java-sdk-core</artifactId>
66+
</dependency>
67+
<!-- A http client isn't included as standard, so you need to specify the one to use -->
68+
<dependency>
69+
<groupId>com.oracle.oci.sdk</groupId>
70+
<artifactId>oci-java-sdk-common-httpclient-jersey3</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.oracle.oci.sdk</groupId>
74+
<artifactId>oci-java-sdk-streaming</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>com.oracle.oci.sdk</groupId>
78+
<artifactId>oci-java-sdk-objectstorage</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.oracle.oci.sdk</groupId>
82+
<artifactId>oci-java-sdk-identity</artifactId>
83+
</dependency>
84+
<!-- Lombok does the auto method creation, used for the log stuff -->
85+
<dependency>
86+
<groupId>org.projectlombok</groupId>
87+
<artifactId>lombok</artifactId>
88+
<version>${version.lombok}</version>
89+
<scope>compile</scope>
90+
</dependency>
91+
<!-- SLF4J is a logging facade that let's us change the actual logger used
92+
under the covers without changing our code, slf4j-jdk14 is for output to
93+
the standard Java logging utilities. By making the dependency declaration
94+
below Maven will bring in the core SLF4J jar files, and also the SLJ4J to
95+
java.util.logging binding -->
96+
<dependency>
97+
<groupId>org.slf4j</groupId>
98+
<artifactId>slf4j-jdk14</artifactId>
99+
<version>${version.slf4j}</version>
100+
</dependency>
101+
</dependencies>
102+
</project>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*Copyright (c) 2023 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
36+
*/
37+
38+
package com.oracle.timg.oci.authentication;
39+
40+
import java.io.IOException;
41+
42+
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
43+
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
44+
45+
import lombok.Getter;
46+
import lombok.NonNull;
47+
import lombok.Setter;
48+
49+
/**
50+
* This class provides a wrapper round the OCI authentication mechanisms
51+
*/
52+
53+
public class AuthenticationProcessor {
54+
55+
private final ConfigFileAuthenticationDetailsProvider provider;
56+
@Getter
57+
@Setter
58+
private String regionName;
59+
@Getter
60+
private String configFileRegionName;
61+
62+
/**
63+
* Creates a processor looking for the specific configuration section name in
64+
* the .oci config file using the region specified in that section
65+
*
66+
* @param providerName - must not be null
67+
* @throws IllegalArgumentException
68+
* @throws IOException
69+
*/
70+
public AuthenticationProcessor(@NonNull String providerName) throws IllegalArgumentException, IOException {
71+
this(providerName, null);
72+
}
73+
74+
/**
75+
* Creates a processor looking for the specific configuration section name in
76+
* the .oci config file using the region specified
77+
*
78+
* @param providerName - must not be null
79+
* @prram regionName - if null will use the default region in the confguration
80+
* file.
81+
* @throws IllegalArgumentException
82+
* @throws IOException
83+
*/
84+
public AuthenticationProcessor(@NonNull String providerName, String regionName)
85+
throws IllegalArgumentException, IOException {
86+
// get and save the provider away
87+
provider = new ConfigFileAuthenticationDetailsProvider(providerName);
88+
if (regionName != null) {
89+
this.regionName = regionName;
90+
} else {
91+
this.regionName = provider.getRegion().getRegionId();
92+
}
93+
}
94+
95+
/**
96+
* Provides a way to get the the underlying provider form the oci sdk, used for
97+
* tasks that this class does not support
98+
*
99+
* @return
100+
* @throws IllegalArgumentException
101+
*/
102+
public AuthenticationDetailsProvider getProvider() throws IllegalArgumentException {
103+
return provider;
104+
}
105+
106+
/**
107+
* way to get the tenancy OCID - needed for the root compartment amongst other
108+
* things
109+
*
110+
* @return
111+
*/
112+
public String getTenancyOCID() {
113+
return provider.getTenantId();
114+
}
115+
}

0 commit comments

Comments
 (0)