Skip to content
Draft
Show file tree
Hide file tree
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 Jul 1, 2025
e1ece9f
Add docs.
chenkins Jul 12, 2025
c7fee4d
Refactor camel case.
chenkins Jul 12, 2025
b2939b2
Refactor package structure.
chenkins Jul 12, 2025
3073fd2
Add storage profile archive test.
chenkins Jul 12, 2025
5ccc90a
Refactor args.
chenkins Jul 12, 2025
aa8e289
Extract AbstractStorageProfile.
chenkins Jul 12, 2025
de8817b
Add storage profile AWS STS setup test.
chenkins Jul 12, 2025
e9e842a
Add storage profile AWS static setup test.
chenkins Jul 12, 2025
b6bb562
Pull up testcontainer setup and teardown.
chenkins Sep 24, 2025
19bad20
Add assertions.
chenkins Sep 24, 2025
8d414bf
Cleanup package structure.
chenkins Sep 24, 2025
515f4f3
Pull up hub session setup.
chenkins Sep 24, 2025
d960e3e
Add IT for storageProfileAWSSTS command.
chenkins Sep 24, 2025
e525e39
Cleanup docs.
chenkins Sep 24, 2025
a02b205
Cleanup docs.
chenkins Sep 25, 2025
c76f76a
Add MinioStsSetup createbucket policy.
chenkins Sep 25, 2025
d2954bc
Cleanup package structure.
chenkins Sep 25, 2025
a9708cf
Add MinioStsSetup createbucket + accessbucket policy.
chenkins Sep 25, 2025
99a7532
Print mc idp commands in lack of client API.
chenkins Sep 26, 2025
60a2681
Fix compile.
chenkins Nov 4, 2025
b5e3d61
Improve documentation.
chenkins Nov 4, 2025
4da7507
Cleanup.
chenkins Nov 4, 2025
92c11da
Fix resource path.
chenkins Nov 4, 2025
d52e319
Add --name option for storage profile clis.
chenkins Nov 4, 2025
bbd220e
Add --clientId option for AWS STS setup.
chenkins Nov 4, 2025
618042d
Use AWS SDK for MinIO createbucket policy.
chenkins Nov 4, 2025
6c6bfcc
Get rid of dependency to cloud.katta.testsetup apart from docker comp…
chenkins Nov 4, 2025
425a25c
Add tamarind example.
chenkins Nov 6, 2025
2e3eae3
Add --region and --regions option for AWS STS setup.
chenkins Nov 6, 2025
596fa2d
Add storage profile AWS static setup IT.
chenkins Nov 6, 2025
db4905d
Harmonize trailing hyphen in --bucketPrefix as in --rolePrefix.
chenkins Nov 6, 2025
9f947e5
Add --region and --regions option for AWS STS setup.
chenkins Nov 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions admin-cli/pom.xml
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>
Comment on lines +122 to +135
Copy link
Contributor Author

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?

</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 admin-cli/src/main/java/cloud/katta/cli/KattaSetupCli.java
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);
}
}
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();
}
}
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;
}
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));
}
}
Loading