-
Notifications
You must be signed in to change notification settings - Fork 0
Generator: Update SDK /services/objectstorage #135
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| dependencies { | ||
| implementation project (':services:objectstorage') | ||
| implementation 'com.squareup.okhttp3:okhttp:4.12.0' | ||
| } | ||
|
|
||
| ext.mainClassName = 'cloud.stackit.sdk.objectstorage.examples.ObjectStorageExample' |
211 changes: 211 additions & 0 deletions
211
...tstorage/src/main/java/cloud/stackit/sdk/objectstorage/examples/ObjectStorageExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| package cloud.stackit.sdk.objectstorage.examples; | ||
|
|
||
| import cloud.stackit.sdk.core.KeyFlowAuthenticator; | ||
| import cloud.stackit.sdk.core.config.CoreConfiguration; | ||
| import cloud.stackit.sdk.core.exception.ApiException; | ||
| import cloud.stackit.sdk.objectstorage.api.ObjectStorageApi; | ||
| import cloud.stackit.sdk.objectstorage.model.*; | ||
| import java.io.IOException; | ||
| import java.net.HttpURLConnection; | ||
| import java.time.Duration; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import okhttp3.OkHttpClient; | ||
|
|
||
| @SuppressWarnings("PMD.CouplingBetweenObjects") | ||
| final class ObjectStorageExample { | ||
|
|
||
| private ObjectStorageExample() {} | ||
|
|
||
| @SuppressWarnings({ | ||
| "PMD.CyclomaticComplexity", | ||
| "PMD.CognitiveComplexity", | ||
| "PMD.NPathComplexity", | ||
| "PMD.NcssCount", | ||
| "PMD.SystemPrintln", | ||
| "PMD.AvoidThrowingRawExceptionTypes" | ||
| }) | ||
| public static void main(String[] args) throws IOException { | ||
| // Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env | ||
| // STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY | ||
| CoreConfiguration configuration = new CoreConfiguration(); | ||
|
|
||
| OkHttpClient httpClient = new OkHttpClient(); | ||
| KeyFlowAuthenticator authenticator = new KeyFlowAuthenticator(httpClient, configuration); | ||
| httpClient = | ||
| httpClient | ||
| .newBuilder() | ||
| .authenticator(authenticator) | ||
| // The object storage requests are sychronous and may take a few seconds. | ||
| // To prevent an timeout, we increase the read timeout to 15 seconds | ||
| .readTimeout(Duration.ofSeconds(15)) | ||
| .build(); | ||
|
|
||
| ObjectStorageApi objectStorageApi = new ObjectStorageApi(httpClient); | ||
|
|
||
| // the id of your STACKIT project, read from env var for this example | ||
| String projectId = System.getenv("STACKIT_PROJECT_ID"); | ||
| if (projectId == null || projectId.isEmpty()) { | ||
| System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found."); | ||
| return; | ||
| } | ||
|
|
||
| // the region which should be used to interact with objectstorage | ||
| String region = "eu01"; | ||
|
|
||
| try { | ||
| /* | ||
| * /////////////////////////////////////////////////////// | ||
| * // P R O J E C T E N A B L E M E N T // | ||
| * /////////////////////////////////////////////////////// | ||
| */ | ||
| /* check if object storage is enabled for the project */ | ||
| ProjectStatus projectStatus; | ||
| System.out.println("Checking if object storage is enabled"); | ||
| try { | ||
| projectStatus = objectStorageApi.getServiceStatus(projectId, region); | ||
| System.out.println("* Object storage is enabled"); | ||
| } catch (ApiException e) { | ||
| // If response status is not found, object storage is not enabled for the | ||
| // project | ||
| if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) { | ||
| System.out.println("* Object storage is not enabled for the project"); | ||
| System.out.println("* Enabling object storage"); | ||
| projectStatus = objectStorageApi.enableService(projectId, region); | ||
| System.out.println("* Object storage successful enabled for the project"); | ||
| } else { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| ProjectScope scope = projectStatus.getScope(); | ||
| System.out.println("* Scope of the object storage: " + scope); | ||
|
|
||
| /* | ||
| * /////////////////////////////////////////////////////// | ||
| * // B U C K E T S // | ||
| * /////////////////////////////////////////////////////// | ||
| * */ | ||
|
|
||
| /* create a new bucket in the project */ | ||
| System.out.println("\nCreating bucket"); | ||
| CreateBucketResponse newBucket = | ||
| objectStorageApi.createBucket(projectId, region, "java-sdk-example"); | ||
| System.out.println(" * Bucket name: " + newBucket.getBucket()); | ||
| System.out.println(" * Project ID: " + newBucket.getProject()); | ||
|
|
||
| /* list all available buckets in the project */ | ||
| System.out.println("\nListing all buckets:"); | ||
| ListBucketsResponse fetchedBuckets = objectStorageApi.listBuckets(projectId, region); | ||
| List<Bucket> listBuckets = fetchedBuckets.getBuckets(); | ||
| for (Bucket bucket : listBuckets) { | ||
| System.out.println("*******************"); | ||
| System.out.println("* Bucket name: " + bucket.getName()); | ||
| System.out.println("* Virtual host: " + bucket.getUrlPathStyle()); | ||
| } | ||
|
|
||
| /* deleting the bucket we just created */ | ||
| System.out.println("\nDeleting bucket:"); | ||
| DeleteBucketResponse deleteBucketResponse = | ||
| objectStorageApi.deleteBucket(projectId, region, newBucket.getBucket()); | ||
| System.out.println("* Bucket name: " + deleteBucketResponse.getBucket()); | ||
| System.out.println("* Bucket successfully deleted"); | ||
|
|
||
| /* | ||
| * /////////////////////////////////////////////////////// | ||
| * // C R E D E N T I A L G R O U P // | ||
| * /////////////////////////////////////////////////////// | ||
| * */ | ||
|
|
||
| /* creating a new credential group in the project */ | ||
| System.out.println("\nCreating credential group:"); | ||
| CreateCredentialsGroupResponse newCredentialGroup = | ||
| objectStorageApi.createCredentialsGroup( | ||
| projectId, | ||
| region, | ||
| new CreateCredentialsGroupPayload().displayName("java-sdk-example")); | ||
| System.out.println( | ||
| "* Group ID" | ||
| + newCredentialGroup.getCredentialsGroup().getCredentialsGroupId()); | ||
| System.out.println( | ||
| "* Display name" + newCredentialGroup.getCredentialsGroup().getDisplayName()); | ||
| System.out.println("* URN" + newCredentialGroup.getCredentialsGroup().getUrn()); | ||
|
|
||
| /* list all available credentials groups */ | ||
| System.out.println("\nListing all credentials groups:"); | ||
| ListCredentialsGroupsResponse fetchedCredentialGroups = | ||
| objectStorageApi.listCredentialsGroups(projectId, region); | ||
| List<CredentialsGroup> listCredentialsGroups = | ||
| fetchedCredentialGroups.getCredentialsGroups(); | ||
| for (CredentialsGroup credentialsGroup : listCredentialsGroups) { | ||
| System.out.println("*******************"); | ||
| System.out.println("* Group ID: " + credentialsGroup.getCredentialsGroupId()); | ||
| System.out.println("* Display name: " + credentialsGroup.getDisplayName()); | ||
| System.out.println("* URN: " + credentialsGroup.getUrn()); | ||
| } | ||
|
|
||
| /* | ||
| * /////////////////////////////////////////////////////// | ||
| * // A C C E S S K E Y // | ||
| * /////////////////////////////////////////////////////// | ||
| * */ | ||
|
|
||
| /* creating a new access key in the credentials group we just created */ | ||
| System.out.println("\nCreating access key:"); | ||
| CreateAccessKeyResponse newAccessKey = | ||
| objectStorageApi.createAccessKey( | ||
| projectId, | ||
| region, | ||
| new CreateAccessKeyPayload() | ||
| .expires(OffsetDateTime.now().plusMinutes(5)), | ||
| newCredentialGroup.getCredentialsGroup().getCredentialsGroupId()); | ||
| System.out.println("* Key ID: " + newAccessKey.getKeyId()); | ||
| System.out.println("* Display name: " + newAccessKey.getDisplayName()); | ||
| System.out.println("* Expires: " + newAccessKey.getExpires()); | ||
|
|
||
| /* list all available access key in the credential group */ | ||
| System.out.println("\nListing all access key of the created credentials group:"); | ||
| ListAccessKeysResponse fetchedAccessKeys = | ||
| objectStorageApi.listAccessKeys( | ||
| projectId, | ||
| region, | ||
| newCredentialGroup.getCredentialsGroup().getCredentialsGroupId()); | ||
| List<AccessKey> listAccessKeys = fetchedAccessKeys.getAccessKeys(); | ||
| for (AccessKey accessKey : listAccessKeys) { | ||
| System.out.println("*******************"); | ||
| System.out.println("* Key ID: " + accessKey.getKeyId()); | ||
| System.out.println("* Display name: " + accessKey.getDisplayName()); | ||
| System.out.println("* Expires: " + accessKey.getExpires()); | ||
| } | ||
|
|
||
| /* | ||
| * /////////////////////////////////////////////////////// | ||
| * // D E L E T I O N // | ||
| * /////////////////////////////////////////////////////// | ||
| * */ | ||
|
|
||
| /* deleting the access key we just created */ | ||
| System.out.println("\nDeleting access key:"); | ||
| DeleteAccessKeyResponse deletedAccessKey = | ||
| objectStorageApi.deleteAccessKey( | ||
| projectId, | ||
| region, | ||
| newAccessKey.getKeyId(), | ||
| newCredentialGroup.getCredentialsGroup().getCredentialsGroupId()); | ||
| System.out.println("* Key ID: " + deletedAccessKey.getKeyId()); | ||
| System.out.println("* Bucket successfully deleted"); | ||
|
|
||
| /* deleting the credentials group we just created */ | ||
| System.out.println("\nDeleting credentials group:"); | ||
| DeleteCredentialsGroupResponse deleteCredentialsGroupResponse = | ||
| objectStorageApi.deleteCredentialsGroup( | ||
| projectId, | ||
| region, | ||
| newCredentialGroup.getCredentialsGroup().getCredentialsGroupId()); | ||
| System.out.println( | ||
| "* Group ID: " + deleteCredentialsGroupResponse.getCredentialsGroupId()); | ||
| System.out.println("* Credentials group successfully deleted"); | ||
| } catch (ApiException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ## v0.1.0 | ||
| - Initial onboarding of STACKIT Java SDK for Object storage service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # STACKIT Java SDK for STACKIT Object Storage API | ||
|
|
||
| - API version: 2.0.1 | ||
|
|
||
| STACKIT API to manage the Object Storage | ||
|
|
||
|
|
||
|
|
||
| This package is part of the STACKIT Java SDK. For additional information, please visit the [GitHub repository](https://github.com/stackitcloud/stackit-sdk-java) of the SDK. | ||
|
|
||
| ## Installation from Maven Central (recommended) | ||
|
|
||
| The release artifacts for this SDK submodule are available on [Maven Central](https://central.sonatype.com/artifact/cloud.stackit.sdk/objectstorage). | ||
|
|
||
| ### Maven users | ||
|
|
||
| Add this dependency to your project's POM: | ||
|
|
||
| ```xml | ||
| <dependency> | ||
| <groupId>cloud.stackit.sdk</groupId> | ||
| <artifactId>objectstorage</artifactId> | ||
| <version><SDK_VERSION></version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| ### Gradle users | ||
|
|
||
| Add this dependency to your project's build file: | ||
|
|
||
| ```groovy | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "cloud.stackit.sdk:objectstorage:<SDK_VERSION>" | ||
| } | ||
| ``` | ||
|
|
||
| ## Installation from local build | ||
|
|
||
| Building the API client library requires: | ||
| 1. Java SDK (version 11 to 21 should be supported) installed on your system | ||
|
|
||
| To install the API client library to your local Maven repository, simply execute: | ||
|
|
||
| ```shell | ||
| ./gradlew services:objectstorage:publishToMavenLocal | ||
| ``` | ||
|
|
||
| ### Maven users | ||
|
|
||
| Add this dependency to your project's POM: | ||
|
|
||
| ```xml | ||
| <dependency> | ||
| <groupId>cloud.stackit.sdk</groupId> | ||
| <artifactId>objectstorage</artifactId> | ||
| <version><SDK_VERSION></version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| ### Gradle users | ||
|
|
||
| Add this dependency to your project's build file: | ||
|
|
||
| ```groovy | ||
| repositories { | ||
| mavenLocal() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "cloud.stackit.sdk:objectstorage:<SDK_VERSION>" | ||
| } | ||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| See the [objectstorage examples](https://github.com/stackitcloud/stackit-sdk-java/tree/main/examples/objectstorage/src/main/java/cloud/stackit/sdk/objectstorage/examples). | ||
|
|
||
| ## Recommendation | ||
|
|
||
| It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0.1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
|
|
||
| ext { | ||
| jakarta_annotation_version = "1.3.5" | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "com.google.code.findbugs:jsr305:3.0.2" | ||
| implementation 'com.squareup.okhttp3:okhttp:4.12.0' | ||
| implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0' | ||
| implementation 'com.google.code.gson:gson:2.9.1' | ||
| implementation 'io.gsonfire:gson-fire:1.9.0' | ||
| implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6' | ||
| implementation 'org.openapitools:jackson-databind-nullable:0.2.6' | ||
| implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0' | ||
| implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version" | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3' | ||
| testImplementation 'org.mockito:mockito-core:3.12.4' | ||
| testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3' | ||
| } |
60 changes: 60 additions & 0 deletions
60
services/objectstorage/src/main/java/cloud/stackit/sdk/objectstorage/ApiCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * STACKIT Object Storage API | ||
| * STACKIT API to manage the Object Storage | ||
| * | ||
| * The version of the OpenAPI document: 2.0.1 | ||
| * | ||
| * | ||
| * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| * https://openapi-generator.tech | ||
| * Do not edit the class manually. | ||
| */ | ||
|
|
||
| package cloud.stackit.sdk.objectstorage; | ||
|
|
||
| import cloud.stackit.sdk.core.exception.ApiException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Callback for asynchronous API call. | ||
| * | ||
| * @param <T> The return type | ||
| */ | ||
| public interface ApiCallback<T> { | ||
| /** | ||
| * This is called when the API call fails. | ||
| * | ||
| * @param e The exception causing the failure | ||
| * @param statusCode Status code of the response if available, otherwise it would be 0 | ||
| * @param responseHeaders Headers of the response if available, otherwise it would be null | ||
| */ | ||
| void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders); | ||
|
|
||
| /** | ||
| * This is called when the API call succeeded. | ||
| * | ||
| * @param result The result deserialized from response | ||
| * @param statusCode Status code of the response | ||
| * @param responseHeaders Headers of the response | ||
| */ | ||
| void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders); | ||
|
|
||
| /** | ||
| * This is called when the API upload processing. | ||
| * | ||
| * @param bytesWritten bytes Written | ||
| * @param contentLength content length of request body | ||
| * @param done write end | ||
| */ | ||
| void onUploadProgress(long bytesWritten, long contentLength, boolean done); | ||
|
|
||
| /** | ||
| * This is called when the API download processing. | ||
| * | ||
| * @param bytesRead bytes Read | ||
| * @param contentLength content length of the response | ||
| * @param done Read end | ||
| */ | ||
| void onDownloadProgress(long bytesRead, long contentLength, boolean done); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.