Skip to content

Commit dd5427f

Browse files
Generator: Update SDK /services/objectstorage (#135)
onboard objectstorage - add examples
1 parent 94cc7fa commit dd5427f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+11614
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Release (2025-MM-DD)
2+
- `objectstorage`: [v0.1.0](services/objectstorage/CHANGELOG.md#v010)
3+
- Initial onboarding of STACKIT Java SDK for Object storage service
4+
15
## Release (2025-10-29)
26
- `core`:
37
- [v0.4.0](core/CHANGELOG.md#v040)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies {
2+
implementation project (':services:objectstorage')
3+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
4+
}
5+
6+
ext.mainClassName = 'cloud.stackit.sdk.objectstorage.examples.ObjectStorageExample'
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
package cloud.stackit.sdk.objectstorage.examples;
2+
3+
import cloud.stackit.sdk.core.KeyFlowAuthenticator;
4+
import cloud.stackit.sdk.core.config.CoreConfiguration;
5+
import cloud.stackit.sdk.core.exception.ApiException;
6+
import cloud.stackit.sdk.objectstorage.api.ObjectStorageApi;
7+
import cloud.stackit.sdk.objectstorage.model.*;
8+
import java.io.IOException;
9+
import java.net.HttpURLConnection;
10+
import java.time.Duration;
11+
import java.time.OffsetDateTime;
12+
import java.util.List;
13+
import okhttp3.OkHttpClient;
14+
15+
@SuppressWarnings("PMD.CouplingBetweenObjects")
16+
final class ObjectStorageExample {
17+
18+
private ObjectStorageExample() {}
19+
20+
@SuppressWarnings({
21+
"PMD.CyclomaticComplexity",
22+
"PMD.CognitiveComplexity",
23+
"PMD.NPathComplexity",
24+
"PMD.NcssCount",
25+
"PMD.SystemPrintln",
26+
"PMD.AvoidThrowingRawExceptionTypes"
27+
})
28+
public static void main(String[] args) throws IOException {
29+
// Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
30+
// STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
31+
CoreConfiguration configuration = new CoreConfiguration();
32+
33+
OkHttpClient httpClient = new OkHttpClient();
34+
KeyFlowAuthenticator authenticator = new KeyFlowAuthenticator(httpClient, configuration);
35+
httpClient =
36+
httpClient
37+
.newBuilder()
38+
.authenticator(authenticator)
39+
// The object storage requests are sychronous and may take a few seconds.
40+
// To prevent an timeout, we increase the read timeout to 15 seconds
41+
.readTimeout(Duration.ofSeconds(15))
42+
.build();
43+
44+
ObjectStorageApi objectStorageApi = new ObjectStorageApi(httpClient);
45+
46+
// the id of your STACKIT project, read from env var for this example
47+
String projectId = System.getenv("STACKIT_PROJECT_ID");
48+
if (projectId == null || projectId.isEmpty()) {
49+
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
50+
return;
51+
}
52+
53+
// the region which should be used to interact with objectstorage
54+
String region = "eu01";
55+
56+
try {
57+
/*
58+
* ///////////////////////////////////////////////////////
59+
* // P R O J E C T E N A B L E M E N T //
60+
* ///////////////////////////////////////////////////////
61+
*/
62+
/* check if object storage is enabled for the project */
63+
ProjectStatus projectStatus;
64+
System.out.println("Checking if object storage is enabled");
65+
try {
66+
projectStatus = objectStorageApi.getServiceStatus(projectId, region);
67+
System.out.println("* Object storage is enabled");
68+
} catch (ApiException e) {
69+
// If response status is not found, object storage is not enabled for the
70+
// project
71+
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
72+
System.out.println("* Object storage is not enabled for the project");
73+
System.out.println("* Enabling object storage");
74+
projectStatus = objectStorageApi.enableService(projectId, region);
75+
System.out.println("* Object storage successful enabled for the project");
76+
} else {
77+
throw new RuntimeException(e);
78+
}
79+
}
80+
ProjectScope scope = projectStatus.getScope();
81+
System.out.println("* Scope of the object storage: " + scope);
82+
83+
/*
84+
* ///////////////////////////////////////////////////////
85+
* // B U C K E T S //
86+
* ///////////////////////////////////////////////////////
87+
* */
88+
89+
/* create a new bucket in the project */
90+
System.out.println("\nCreating bucket");
91+
CreateBucketResponse newBucket =
92+
objectStorageApi.createBucket(projectId, region, "java-sdk-example");
93+
System.out.println(" * Bucket name: " + newBucket.getBucket());
94+
System.out.println(" * Project ID: " + newBucket.getProject());
95+
96+
/* list all available buckets in the project */
97+
System.out.println("\nListing all buckets:");
98+
ListBucketsResponse fetchedBuckets = objectStorageApi.listBuckets(projectId, region);
99+
List<Bucket> listBuckets = fetchedBuckets.getBuckets();
100+
for (Bucket bucket : listBuckets) {
101+
System.out.println("*******************");
102+
System.out.println("* Bucket name: " + bucket.getName());
103+
System.out.println("* Virtual host: " + bucket.getUrlPathStyle());
104+
}
105+
106+
/* deleting the bucket we just created */
107+
System.out.println("\nDeleting bucket:");
108+
DeleteBucketResponse deleteBucketResponse =
109+
objectStorageApi.deleteBucket(projectId, region, newBucket.getBucket());
110+
System.out.println("* Bucket name: " + deleteBucketResponse.getBucket());
111+
System.out.println("* Bucket successfully deleted");
112+
113+
/*
114+
* ///////////////////////////////////////////////////////
115+
* // C R E D E N T I A L G R O U P //
116+
* ///////////////////////////////////////////////////////
117+
* */
118+
119+
/* creating a new credential group in the project */
120+
System.out.println("\nCreating credential group:");
121+
CreateCredentialsGroupResponse newCredentialGroup =
122+
objectStorageApi.createCredentialsGroup(
123+
projectId,
124+
region,
125+
new CreateCredentialsGroupPayload().displayName("java-sdk-example"));
126+
System.out.println(
127+
"* Group ID"
128+
+ newCredentialGroup.getCredentialsGroup().getCredentialsGroupId());
129+
System.out.println(
130+
"* Display name" + newCredentialGroup.getCredentialsGroup().getDisplayName());
131+
System.out.println("* URN" + newCredentialGroup.getCredentialsGroup().getUrn());
132+
133+
/* list all available credentials groups */
134+
System.out.println("\nListing all credentials groups:");
135+
ListCredentialsGroupsResponse fetchedCredentialGroups =
136+
objectStorageApi.listCredentialsGroups(projectId, region);
137+
List<CredentialsGroup> listCredentialsGroups =
138+
fetchedCredentialGroups.getCredentialsGroups();
139+
for (CredentialsGroup credentialsGroup : listCredentialsGroups) {
140+
System.out.println("*******************");
141+
System.out.println("* Group ID: " + credentialsGroup.getCredentialsGroupId());
142+
System.out.println("* Display name: " + credentialsGroup.getDisplayName());
143+
System.out.println("* URN: " + credentialsGroup.getUrn());
144+
}
145+
146+
/*
147+
* ///////////////////////////////////////////////////////
148+
* // A C C E S S K E Y //
149+
* ///////////////////////////////////////////////////////
150+
* */
151+
152+
/* creating a new access key in the credentials group we just created */
153+
System.out.println("\nCreating access key:");
154+
CreateAccessKeyResponse newAccessKey =
155+
objectStorageApi.createAccessKey(
156+
projectId,
157+
region,
158+
new CreateAccessKeyPayload()
159+
.expires(OffsetDateTime.now().plusMinutes(5)),
160+
newCredentialGroup.getCredentialsGroup().getCredentialsGroupId());
161+
System.out.println("* Key ID: " + newAccessKey.getKeyId());
162+
System.out.println("* Display name: " + newAccessKey.getDisplayName());
163+
System.out.println("* Expires: " + newAccessKey.getExpires());
164+
165+
/* list all available access key in the credential group */
166+
System.out.println("\nListing all access key of the created credentials group:");
167+
ListAccessKeysResponse fetchedAccessKeys =
168+
objectStorageApi.listAccessKeys(
169+
projectId,
170+
region,
171+
newCredentialGroup.getCredentialsGroup().getCredentialsGroupId());
172+
List<AccessKey> listAccessKeys = fetchedAccessKeys.getAccessKeys();
173+
for (AccessKey accessKey : listAccessKeys) {
174+
System.out.println("*******************");
175+
System.out.println("* Key ID: " + accessKey.getKeyId());
176+
System.out.println("* Display name: " + accessKey.getDisplayName());
177+
System.out.println("* Expires: " + accessKey.getExpires());
178+
}
179+
180+
/*
181+
* ///////////////////////////////////////////////////////
182+
* // D E L E T I O N //
183+
* ///////////////////////////////////////////////////////
184+
* */
185+
186+
/* deleting the access key we just created */
187+
System.out.println("\nDeleting access key:");
188+
DeleteAccessKeyResponse deletedAccessKey =
189+
objectStorageApi.deleteAccessKey(
190+
projectId,
191+
region,
192+
newAccessKey.getKeyId(),
193+
newCredentialGroup.getCredentialsGroup().getCredentialsGroupId());
194+
System.out.println("* Key ID: " + deletedAccessKey.getKeyId());
195+
System.out.println("* Bucket successfully deleted");
196+
197+
/* deleting the credentials group we just created */
198+
System.out.println("\nDeleting credentials group:");
199+
DeleteCredentialsGroupResponse deleteCredentialsGroupResponse =
200+
objectStorageApi.deleteCredentialsGroup(
201+
projectId,
202+
region,
203+
newCredentialGroup.getCredentialsGroup().getCredentialsGroupId());
204+
System.out.println(
205+
"* Group ID: " + deleteCredentialsGroupResponse.getCredentialsGroupId());
206+
System.out.println("* Credentials group successfully deleted");
207+
} catch (ApiException e) {
208+
throw new RuntimeException(e);
209+
}
210+
}
211+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## v0.1.0
2+
- Initial onboarding of STACKIT Java SDK for Object storage service

services/objectstorage/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# STACKIT Java SDK for STACKIT Object Storage API
2+
3+
- API version: 2.0.1
4+
5+
STACKIT API to manage the Object Storage
6+
7+
8+
9+
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.
10+
11+
## Installation from Maven Central (recommended)
12+
13+
The release artifacts for this SDK submodule are available on [Maven Central](https://central.sonatype.com/artifact/cloud.stackit.sdk/objectstorage).
14+
15+
### Maven users
16+
17+
Add this dependency to your project's POM:
18+
19+
```xml
20+
<dependency>
21+
<groupId>cloud.stackit.sdk</groupId>
22+
<artifactId>objectstorage</artifactId>
23+
<version><SDK_VERSION></version>
24+
<scope>compile</scope>
25+
</dependency>
26+
```
27+
28+
### Gradle users
29+
30+
Add this dependency to your project's build file:
31+
32+
```groovy
33+
repositories {
34+
mavenCentral()
35+
}
36+
37+
dependencies {
38+
implementation "cloud.stackit.sdk:objectstorage:<SDK_VERSION>"
39+
}
40+
```
41+
42+
## Installation from local build
43+
44+
Building the API client library requires:
45+
1. Java SDK (version 11 to 21 should be supported) installed on your system
46+
47+
To install the API client library to your local Maven repository, simply execute:
48+
49+
```shell
50+
./gradlew services:objectstorage:publishToMavenLocal
51+
```
52+
53+
### Maven users
54+
55+
Add this dependency to your project's POM:
56+
57+
```xml
58+
<dependency>
59+
<groupId>cloud.stackit.sdk</groupId>
60+
<artifactId>objectstorage</artifactId>
61+
<version><SDK_VERSION></version>
62+
<scope>compile</scope>
63+
</dependency>
64+
```
65+
66+
### Gradle users
67+
68+
Add this dependency to your project's build file:
69+
70+
```groovy
71+
repositories {
72+
mavenLocal()
73+
}
74+
75+
dependencies {
76+
implementation "cloud.stackit.sdk:objectstorage:<SDK_VERSION>"
77+
}
78+
```
79+
80+
## Getting Started
81+
82+
See the [objectstorage examples](https://github.com/stackitcloud/stackit-sdk-java/tree/main/examples/objectstorage/src/main/java/cloud/stackit/sdk/objectstorage/examples).
83+
84+
## Recommendation
85+
86+
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

services/objectstorage/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
ext {
3+
jakarta_annotation_version = "1.3.5"
4+
}
5+
6+
dependencies {
7+
implementation "com.google.code.findbugs:jsr305:3.0.2"
8+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
9+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
10+
implementation 'com.google.code.gson:gson:2.9.1'
11+
implementation 'io.gsonfire:gson-fire:1.9.0'
12+
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
13+
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
14+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
15+
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
16+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
17+
testImplementation 'org.mockito:mockito-core:3.12.4'
18+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
19+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* STACKIT Object Storage API
3+
* STACKIT API to manage the Object Storage
4+
*
5+
* The version of the OpenAPI document: 2.0.1
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package cloud.stackit.sdk.objectstorage;
14+
15+
import cloud.stackit.sdk.core.exception.ApiException;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
/**
20+
* Callback for asynchronous API call.
21+
*
22+
* @param <T> The return type
23+
*/
24+
public interface ApiCallback<T> {
25+
/**
26+
* This is called when the API call fails.
27+
*
28+
* @param e The exception causing the failure
29+
* @param statusCode Status code of the response if available, otherwise it would be 0
30+
* @param responseHeaders Headers of the response if available, otherwise it would be null
31+
*/
32+
void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders);
33+
34+
/**
35+
* This is called when the API call succeeded.
36+
*
37+
* @param result The result deserialized from response
38+
* @param statusCode Status code of the response
39+
* @param responseHeaders Headers of the response
40+
*/
41+
void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders);
42+
43+
/**
44+
* This is called when the API upload processing.
45+
*
46+
* @param bytesWritten bytes Written
47+
* @param contentLength content length of request body
48+
* @param done write end
49+
*/
50+
void onUploadProgress(long bytesWritten, long contentLength, boolean done);
51+
52+
/**
53+
* This is called when the API download processing.
54+
*
55+
* @param bytesRead bytes Read
56+
* @param contentLength content length of the response
57+
* @param done Read end
58+
*/
59+
void onDownloadProgress(long bytesRead, long contentLength, boolean done);
60+
}

0 commit comments

Comments
 (0)