Skip to content

Commit 7135566

Browse files
committed
Extract AbstractStorageProfile.
1 parent e248d90 commit 7135566

File tree

4 files changed

+45
-62
lines changed

4 files changed

+45
-62
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 shift7 GmbH. All rights reserved.
3+
*/
4+
5+
package cloud.katta.cli.commands.hub;
6+
7+
import java.util.UUID;
8+
import java.util.concurrent.Callable;
9+
10+
import cloud.katta.cli.commands.AbstractAuthorizationCode;
11+
import cloud.katta.client.ApiClient;
12+
import cloud.katta.client.ApiException;
13+
import picocli.CommandLine;
14+
15+
public abstract class AbstractStorageProfile extends AbstractAuthorizationCode implements Callable<Void> {
16+
@CommandLine.Option(names = {"--hubUrl"}, description = "Hub URL. Example: \"https://testing.katta.cloud/tamarind\"", required = true)
17+
String hubUrl;
18+
19+
@CommandLine.Option(names = {"--uuid"}, description = "The uuid.", required = true)
20+
String uuid;
21+
22+
@Override
23+
public Void call() throws Exception {
24+
final String accessToken = login();
25+
call(hubUrl, accessToken, uuid);
26+
return null;
27+
}
28+
29+
protected void call(final String hubUrl, final String accessToken, final String uuid) throws ApiException {
30+
final ApiClient apiClient = new ApiClient();
31+
apiClient.setBasePath(hubUrl);
32+
apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
33+
call(UUID.fromString(uuid), apiClient);
34+
}
35+
36+
37+
protected abstract void call(final UUID uuid, final ApiClient apiClient) throws ApiException;
38+
}

admin-cli/src/main/java/cloud/katta/cli/commands/hub/StorageProfileArchive.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
package cloud.katta.cli.commands.hub;
66

77
import java.util.UUID;
8-
import java.util.concurrent.Callable;
98

10-
import cloud.katta.cli.commands.AbstractAuthorizationCode;
119
import cloud.katta.client.ApiClient;
1210
import cloud.katta.client.ApiException;
1311
import cloud.katta.client.api.StorageProfileResourceApi;
@@ -23,28 +21,9 @@
2321
@CommandLine.Command(name = "storageProfileArchive",
2422
description = "Upload storage profile for AWS Static.",
2523
mixinStandardHelpOptions = true)
26-
public class StorageProfileArchive extends AbstractAuthorizationCode implements Callable<Void> {
27-
28-
@CommandLine.Option(names = {"--hubUrl"}, description = "Hub URL. Example: \"https://testing.katta.cloud/tamarind\"", required = true)
29-
String hubUrl;
30-
31-
@CommandLine.Option(names = {"--uuid"}, description = "The uuid.", required = true)
32-
String uuid;
24+
public class StorageProfileArchive extends AbstractStorageProfile {
3325

3426
@Override
35-
public Void call() throws Exception {
36-
final String accessToken = login();
37-
call(hubUrl, accessToken, uuid);
38-
return null;
39-
}
40-
41-
protected void call(final String hubUrl, final String accessToken, final String uuid) throws ApiException {
42-
final ApiClient apiClient = new ApiClient();
43-
apiClient.setBasePath(hubUrl);
44-
apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
45-
call(UUID.fromString(uuid), apiClient);
46-
}
47-
4827
protected void call(final UUID uuid, final ApiClient apiClient) throws ApiException {
4928
final StorageProfileResourceApi storageProfileResourceApi = new StorageProfileResourceApi(apiClient);
5029
call(uuid, storageProfileResourceApi);

admin-cli/src/main/java/cloud/katta/cli/commands/setup/StorageProfileAwsStaticSetup.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
package cloud.katta.cli.commands.setup;
66

7-
import java.io.IOException;
87
import java.util.UUID;
9-
import java.util.concurrent.Callable;
108

11-
import cloud.katta.cli.commands.AbstractAuthorizationCode;
9+
import cloud.katta.cli.commands.hub.AbstractStorageProfile;
1210
import cloud.katta.client.ApiClient;
1311
import cloud.katta.client.ApiException;
1412
import cloud.katta.client.api.StorageProfileResourceApi;
@@ -26,24 +24,10 @@
2624
@CommandLine.Command(name = "storageProfileAWSStatic",
2725
description = "Upload storage profile for AWS Static.",
2826
mixinStandardHelpOptions = true)
29-
public class StorageProfileAwsStaticSetup extends AbstractAuthorizationCode implements Callable<Void> {
30-
@CommandLine.Option(names = {"--hubUrl"}, description = "Hub URL. Example: \"https://testing.katta.cloud/tamarind\"", required = true)
31-
String hubUrl;
32-
27+
public class StorageProfileAwsStaticSetup extends AbstractStorageProfile {
3328

3429
@Override
35-
public Void call() throws Exception {
36-
final UUID uuid = UUID.randomUUID();
37-
final String accessToken = login();
38-
call(hubUrl, accessToken, uuid);
39-
return null;
40-
}
41-
42-
protected void call(final String hubUrl, final String accessToken, final UUID uuid) throws IOException, ApiException {
43-
final ApiClient apiClient = new ApiClient();
44-
apiClient.setBasePath(hubUrl);
45-
apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
46-
30+
protected void call(final UUID uuid, final ApiClient apiClient) throws ApiException {
4731
final StorageProfileResourceApi storageProfileResourceApi = new StorageProfileResourceApi(apiClient);
4832

4933
storageProfileResourceApi.apiStorageprofileS3Put(new StorageProfileS3Dto()

admin-cli/src/main/java/cloud/katta/cli/commands/setup/StorageProfileAwsStsSetup.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
package cloud.katta.cli.commands.setup;
66

7-
import java.io.IOException;
87
import java.util.Arrays;
98
import java.util.UUID;
10-
import java.util.concurrent.Callable;
119

12-
import cloud.katta.cli.commands.AbstractAuthorizationCode;
10+
import cloud.katta.cli.commands.hub.AbstractStorageProfile;
1311
import cloud.katta.client.ApiClient;
1412
import cloud.katta.client.ApiException;
1513
import cloud.katta.client.api.StorageProfileResourceApi;
@@ -29,10 +27,7 @@
2927
@CommandLine.Command(name = "storageProfileAWSSTS",
3028
description = "Upload storage profile for AWS STS.",
3129
mixinStandardHelpOptions = true)
32-
public class StorageProfileAwsStsSetup extends AbstractAuthorizationCode implements Callable<Void> {
33-
34-
@CommandLine.Option(names = {"--hubUrl"}, description = "Hub URL. Example: \"https://testing.katta.cloud/tamarind\"", required = true)
35-
String hubUrl;
30+
public class StorageProfileAwsStsSetup extends AbstractStorageProfile {
3631

3732
@CommandLine.Option(names = {"--rolePrefix"}, description = "ARN Role Prefix. Example: \"arn:aws:iam::XXXXXXX:role/testing.katta.cloud-kc-realms-tamarind\"", required = true)
3833
String rolePrefix;
@@ -41,20 +36,7 @@ public class StorageProfileAwsStsSetup extends AbstractAuthorizationCode impleme
4136
String bucketPrefix;
4237

4338
@Override
44-
public Void call() throws Exception {
45-
final UUID uuid = UUID.randomUUID();
46-
47-
final String accessToken = login();
48-
call(hubUrl, accessToken, uuid);
49-
50-
return null;
51-
}
52-
53-
private void call(final String hubUrl, final String accessToken, final UUID uuid) throws IOException, ApiException {
54-
final ApiClient apiClient = new ApiClient();
55-
apiClient.setBasePath(hubUrl);
56-
apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
57-
39+
protected void call(final UUID uuid, final ApiClient apiClient) throws ApiException {
5840
final StorageProfileResourceApi storageProfileResourceApi = new StorageProfileResourceApi(apiClient);
5941

6042
storageProfileResourceApi.apiStorageprofileS3stsPut(new StorageProfileS3STSDto()

0 commit comments

Comments
 (0)