-
Notifications
You must be signed in to change notification settings - Fork 0
Katta Admin CLI #139
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
Draft
chenkins
wants to merge
33
commits into
main
Choose a base branch
from
feature/admin-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Katta Admin CLI #139
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
fe4d23e
Add katta setup cli.
chenkins e1ece9f
Add docs.
chenkins c7fee4d
Refactor camel case.
chenkins b2939b2
Refactor package structure.
chenkins 3073fd2
Add storage profile archive test.
chenkins 5ccc90a
Refactor args.
chenkins aa8e289
Extract AbstractStorageProfile.
chenkins de8817b
Add storage profile AWS STS setup test.
chenkins e9e842a
Add storage profile AWS static setup test.
chenkins b6bb562
Pull up testcontainer setup and teardown.
chenkins 19bad20
Add assertions.
chenkins 8d414bf
Cleanup package structure.
chenkins 515f4f3
Pull up hub session setup.
chenkins d960e3e
Add IT for storageProfileAWSSTS command.
chenkins e525e39
Cleanup docs.
chenkins a02b205
Cleanup docs.
chenkins c76f76a
Add MinioStsSetup createbucket policy.
chenkins d2954bc
Cleanup package structure.
chenkins a9708cf
Add MinioStsSetup createbucket + accessbucket policy.
chenkins 99a7532
Print mc idp commands in lack of client API.
chenkins 60a2681
Fix compile.
chenkins b5e3d61
Improve documentation.
chenkins 4da7507
Cleanup.
chenkins 92c11da
Fix resource path.
chenkins d52e319
Add --name option for storage profile clis.
chenkins bbd220e
Add --clientId option for AWS STS setup.
chenkins 618042d
Use AWS SDK for MinIO createbucket policy.
chenkins 6c6bfcc
Get rid of dependency to cloud.katta.testsetup apart from docker comp…
chenkins 425a25c
Add tamarind example.
chenkins 2e3eae3
Add --region and --regions option for AWS STS setup.
chenkins 596fa2d
Add storage profile AWS static setup IT.
chenkins db4905d
Harmonize trailing hyphen in --bucketPrefix as in --rolePrefix.
chenkins 9f947e5
Add --region and --regions option for AWS STS setup.
chenkins 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>cloud.katta</groupId> | ||
| <artifactId>katta-clientlib</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>admin-cli</artifactId> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>21</maven.compiler.source> | ||
| <maven.compiler.target>21</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <picocli.version>4.7.6</picocli.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>cloud.katta</groupId> | ||
| <artifactId>katta-clientlib-hub</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>cloud.katta</groupId> | ||
| <artifactId>katta-clientlib-hub</artifactId> | ||
| <version>${project.version}</version> | ||
| <classifier>tests</classifier> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>ch.cyberduck</groupId> | ||
| <artifactId>core</artifactId> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>ch.cyberduck</groupId> | ||
| <artifactId>test</artifactId> | ||
| <type>pom</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.github.coffeelibs</groupId> | ||
| <artifactId>tiny-oauth2-client</artifactId> | ||
| <version>0.8.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>commons-codec</groupId> | ||
| <artifactId>commons-codec</artifactId> | ||
| <version>1.18.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>iam</artifactId> | ||
| <version>2.31.27</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>iam-policy-builder</artifactId> | ||
| <version>2.31.27</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.json</groupId> | ||
| <artifactId>json</artifactId> | ||
| <version>20250107</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-compress</artifactId> | ||
| <version>1.27.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>info.picocli</groupId> | ||
| <artifactId>picocli</artifactId> | ||
| <version>${picocli.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.rest-assured</groupId> | ||
| <artifactId>rest-assured</artifactId> | ||
| <version>5.5.0</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| <version>2.18.2</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.minio</groupId> | ||
| <artifactId>minio-admin</artifactId> | ||
| <version>8.5.17</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <version>3.8.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>unpack</id> | ||
| <phase>process-sources</phase> | ||
| <goals> | ||
| <goal>unpack</goal> | ||
| </goals> | ||
| <configuration> | ||
| <artifactItems> | ||
| <artifactItem> | ||
| <groupId>cloud.katta</groupId> | ||
| <artifactId>katta-clientlib-hub</artifactId> | ||
| <version>${project.version}</version> | ||
| <classifier>tests</classifier> | ||
| <type>jar</type> | ||
| <overWrite>false</overWrite> | ||
| <outputDirectory>${project.build.directory}/test-classes</outputDirectory> | ||
| <includes>**/*</includes> | ||
| </artifactItem> | ||
| </artifactItems> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-enforcer-plugin</artifactId> | ||
| <version>3.5.0</version> | ||
| <executions> | ||
| <execution> | ||
| <id>enforce-bytecode-version</id> | ||
| <goals> | ||
| <goal>enforce</goal> | ||
| </goals> | ||
| <configuration> | ||
| <skip>true</skip> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>extra-enforcer-rules</artifactId> | ||
| <version>1.10.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
37 changes: 37 additions & 0 deletions
37
admin-cli/src/main/java/cloud/katta/cli/KattaSetupCli.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,37 @@ | ||
| /* | ||
| * Copyright (c) 2025 shift7 GmbH. All rights reserved. | ||
| */ | ||
|
|
||
| package cloud.katta.cli; | ||
|
|
||
| import cloud.katta.cli.commands.hub.StorageProfileArchive; | ||
| import cloud.katta.cli.commands.hub.StorageProfileAwsStaticSetup; | ||
| import cloud.katta.cli.commands.hub.StorageProfileAwsStsSetup; | ||
| import cloud.katta.cli.commands.login.AuthorizationCode; | ||
| import cloud.katta.cli.commands.storage.AwsStsSetup; | ||
| import cloud.katta.cli.commands.storage.MinioStsSetup; | ||
| import picocli.CommandLine; | ||
|
|
||
| @CommandLine.Command(name = "katta-admin-cli", | ||
| mixinStandardHelpOptions = true, | ||
| subcommands = { | ||
| // storage | ||
| AwsStsSetup.class, | ||
| MinioStsSetup.class, | ||
| // hub | ||
| StorageProfileAwsStsSetup.class, StorageProfileAwsStaticSetup.class, | ||
| StorageProfileArchive.class, | ||
| // misc. | ||
| AuthorizationCode.class, | ||
| CommandLine.HelpCommand.class, | ||
| }) | ||
| public class KattaSetupCli { | ||
|
|
||
| public static void main(String... args) { | ||
| var app = new KattaSetupCli(); | ||
| int exitCode = new CommandLine(app) | ||
| .setPosixClusteredShortOptionsAllowed(false) | ||
| .execute(args); | ||
| System.exit(exitCode); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
admin-cli/src/main/java/cloud/katta/cli/commands/AbstractAuthorizationCode.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,57 @@ | ||
| /* | ||
| * Copyright (c) 2025 shift7 GmbH. All rights reserved. | ||
| */ | ||
|
|
||
| package cloud.katta.cli.commands; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.github.coffeelibs.tinyoauth2client.TinyOAuth2; | ||
| import picocli.CommandLine; | ||
|
|
||
| public class AbstractAuthorizationCode { | ||
|
|
||
| @CommandLine.Option(names = {"--tokenUrl"}, description = "Keycloak realm URL with scheme. Example: \"https://testing.katta.cloud/kc/realms/tamarind/protocol/openid-connect/token\"", required = false) | ||
| String tokenUrl; | ||
|
|
||
| @CommandLine.Option(names = {"--authUrl"}, description = "Keycloak realm URL with scheme. Example: \"https://testing.katta.cloud/kc/realms/tamarind/protocol/openid-connect/auth\"", required = false) | ||
| String authUrl; | ||
|
|
||
| @CommandLine.Option(names = {"--clientId"}, description = "Keycloak realm URL with scheme. Example: \"cryptomator\"", required = false) | ||
| String clientId; | ||
|
|
||
| @CommandLine.Option(names = {"--accessToken"}, description = "The access token. If not provided, --tokenUrl, --authUrl and --clientId need to be provided. Requires admin role in the hub.", required = false) | ||
| String accessToken; | ||
|
|
||
| protected String login() throws IOException, InterruptedException { | ||
| if(StringUtils.isEmpty(accessToken)) { | ||
| var authResponse = TinyOAuth2.client(clientId) | ||
| .withTokenEndpoint(URI.create(tokenUrl)) | ||
| .authorizationCodeGrant(URI.create(authUrl)) | ||
| .authorize(HttpClient.newHttpClient(), uri -> { | ||
| System.out.println("Please login on " + uri); | ||
| }); | ||
| return extractAccessToken(authResponse); | ||
| } | ||
| else { | ||
| return accessToken; | ||
| } | ||
| } | ||
|
|
||
| private static String extractAccessToken(HttpResponse<String> response) throws JsonProcessingException { | ||
| var statusCode = response.statusCode(); | ||
| if(statusCode != 200) { | ||
| System.err.println(""" | ||
| Request was responded with code %d and body:\n%s\n""".formatted(statusCode, response.body())); | ||
| return null; | ||
| } | ||
| return new ObjectMapper().reader().readTree(response.body()).get("access_token").asText(); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
admin-cli/src/main/java/cloud/katta/cli/commands/hub/AbstractStorageProfile.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,40 @@ | ||
| /* | ||
| * Copyright (c) 2025 shift7 GmbH. All rights reserved. | ||
| */ | ||
|
|
||
| package cloud.katta.cli.commands.hub; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| import cloud.katta.cli.commands.AbstractAuthorizationCode; | ||
| import cloud.katta.client.ApiClient; | ||
| import cloud.katta.client.ApiException; | ||
| import picocli.CommandLine; | ||
|
|
||
| public abstract class AbstractStorageProfile extends AbstractAuthorizationCode implements Callable<Void> { | ||
| @CommandLine.Option(names = {"--hubUrl"}, description = "Hub URL. Example: \"https://testing.katta.cloud/tamarind\"", required = true) | ||
| String hubUrl; | ||
|
|
||
| @CommandLine.Option(names = {"--uuid"}, description = "The uuid.", required = true) | ||
| String uuid; | ||
|
|
||
| @CommandLine.Option(names = {"--name"}, description = "The name.", required = true) | ||
| String name; | ||
|
|
||
| @Override | ||
| public Void call() throws Exception { | ||
| final String accessToken = login(); | ||
| call(hubUrl, accessToken, uuid, name); | ||
| return null; | ||
| } | ||
|
|
||
| protected void call(final String hubUrl, final String accessToken, final String uuid, final String name) throws ApiException { | ||
| final ApiClient apiClient = new ApiClient(); | ||
| apiClient.setBasePath(hubUrl); | ||
| apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken); | ||
| call(UUID.fromString(uuid), name, apiClient); | ||
| } | ||
|
|
||
| protected abstract void call(final UUID uuid, final String name, final ApiClient apiClient) throws ApiException; | ||
| } |
39 changes: 39 additions & 0 deletions
39
admin-cli/src/main/java/cloud/katta/cli/commands/hub/StorageProfileArchive.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,39 @@ | ||
| /* | ||
| * Copyright (c) 2025 shift7 GmbH. All rights reserved. | ||
| */ | ||
|
|
||
| package cloud.katta.cli.commands.hub; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import cloud.katta.client.ApiClient; | ||
| import cloud.katta.client.ApiException; | ||
| import cloud.katta.client.api.StorageProfileResourceApi; | ||
| import picocli.CommandLine; | ||
|
|
||
| /** | ||
| * Archives a storage profile using <code>/api/storageprofile</code>. | ||
| * <p> | ||
| * Requires <code>admin</code> role in Katta Server. | ||
| * <p> | ||
| * See also <a href="https://github.com/shift7-ch/katta-clientlib/blob/main/hub/src/main/resources/openapi.json>OpenAPI Specification</a>. | ||
| */ | ||
| @CommandLine.Command(name = "storageProfileArchive", | ||
| description = "Upload storage profile for AWS Static.", | ||
| mixinStandardHelpOptions = true) | ||
| public class StorageProfileArchive extends AbstractStorageProfile { | ||
|
|
||
| @Override | ||
| protected void call(final UUID uuid, final String name, final ApiClient apiClient) throws ApiException { | ||
| final StorageProfileResourceApi storageProfileResourceApi = new StorageProfileResourceApi(apiClient); | ||
| call(uuid, storageProfileResourceApi); | ||
| } | ||
|
|
||
| protected void call(final UUID uuid, final StorageProfileResourceApi storageProfileResourceApi) throws ApiException { | ||
| System.out.println("storage profiles:"); | ||
| System.out.println(storageProfileResourceApi.apiStorageprofileGet(null)); | ||
| storageProfileResourceApi.apiStorageprofileProfileIdPut(uuid, true); | ||
| System.out.println("updated:"); | ||
| System.out.println(storageProfileResourceApi.apiStorageprofileProfileIdGet(uuid)); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs packaged/installed dependency in reactory - is there a better way?