Skip to content

Commit

Permalink
Add secrets support (#273)
Browse files Browse the repository at this point in the history
* Add secrets commands

* Test secrets commands

* Update SDK v1.4.2
  • Loading branch information
jordeu authored Oct 26, 2022
1 parent b7ffe9d commit 6ddd97f
Show file tree
Hide file tree
Showing 18 changed files with 818 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'ch.qos.logback:logback-core:1.2.11'
implementation 'ch.qos.logback:logback-classic:1.2.11'
implementation 'io.seqera.tower:tower-java-sdk:1.4.1'
implementation 'io.seqera.tower:tower-java-sdk:1.4.2'
implementation 'info.picocli:picocli:4.6.3'
annotationProcessor 'info.picocli:picocli-codegen:4.6.3'

Expand Down
137 changes: 137 additions & 0 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@
"allDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.SecretsCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.TeamsCmd",
"allDeclaredFields":true,
Expand Down Expand Up @@ -1286,6 +1292,53 @@
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.tower.cli.commands.secrets.AbstractSecretsCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.tower.cli.commands.secrets.AddCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.DeleteCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.ListCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.SecretRefOptions",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.SecretRefOptions$SecretRef",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.UpdateCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.secrets.ViewCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.teams.AbstractTeamsCmd",
"allDeclaredFields":true,
Expand Down Expand Up @@ -1691,6 +1744,36 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.secrets.SecretAdded",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.secrets.SecretDeleted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.secrets.SecretUpdated",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.secrets.SecretView",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.secrets.SecretsList",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.teams.TeamAdded",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2135,6 +2218,26 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.CreatePipelineSecretRequest",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[
{"name":"getName","parameterTypes":[] },
{"name":"getValue","parameterTypes":[] }
]
},
{
"name":"io.seqera.tower.model.CreatePipelineSecretResponse",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[
{"name":"<init>","parameterTypes":[] },
{"name":"setSecretId","parameterTypes":["java.lang.Long"] }
]
},
{
"name":"io.seqera.tower.model.CreateTeamMemberRequest",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2532,6 +2635,17 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.ListPipelineSecretsResponse",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[
{"name":"<init>","parameterTypes":[] },
{"name":"setPipelineSecrets","parameterTypes":["java.util.List"] },
{"name":"setTotalSize","parameterTypes":["java.lang.Long"] }
]
},
{
"name":"io.seqera.tower.model.ListPipelinesResponse",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2664,6 +2778,22 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.PipelineSecret",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[
{"name":"<init>","parameterTypes":[] },
{"name":"getDateCreated","parameterTypes":[] },
{"name":"getId_JsonNullable","parameterTypes":[] },
{"name":"getLastUpdated","parameterTypes":[] },
{"name":"getLastUsed","parameterTypes":[] },
{"name":"getName","parameterTypes":[] },
{"name":"setId_JsonNullable","parameterTypes":["org.openapitools.jackson.nullable.JsonNullable"] },
{"name":"setName","parameterTypes":["java.lang.String"] }
]
},
{
"name":"io.seqera.tower.model.PodCleanupPolicy",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2809,6 +2939,13 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.UpdatePipelineSecretRequest",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"getValue","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.model.UpdateWorkspaceRequest",
"allDeclaredFields":true,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/seqera/tower/cli/Tower.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.seqera.tower.cli.commands.ParticipantsCmd;
import io.seqera.tower.cli.commands.PipelinesCmd;
import io.seqera.tower.cli.commands.RunsCmd;
import io.seqera.tower.cli.commands.SecretsCmd;
import io.seqera.tower.cli.commands.TeamsCmd;
import io.seqera.tower.cli.commands.WorkspacesCmd;
import io.seqera.tower.cli.commands.enums.OutputType;
Expand Down Expand Up @@ -61,6 +62,7 @@
RunsCmd.class,
TeamsCmd.class,
WorkspacesCmd.class,
SecretsCmd.class,
}
)
public class Tower extends AbstractCmd {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/SecretsCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands;

import io.seqera.tower.cli.commands.secrets.*;
import picocli.CommandLine.Command;


@Command(
name = "secrets",
description = "Manage workspace secrets.",
subcommands = {
ListCmd.class,
AddCmd.class,
DeleteCmd.class,
ViewCmd.class,
UpdateCmd.class,
}
)
public class SecretsCmd extends AbstractRootCmd {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.secrets;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.AbstractApiCmd;
import io.seqera.tower.cli.exceptions.SecretNotFoundException;
import io.seqera.tower.model.ListPipelineSecretsResponse;
import io.seqera.tower.model.PipelineSecret;
import picocli.CommandLine.Command;

@Command
public abstract class AbstractSecretsCmd extends AbstractApiCmd {

public AbstractSecretsCmd() {
}

protected PipelineSecret secretByName(Long workspaceId, String name) throws ApiException {
ListPipelineSecretsResponse list = api().listPipelineSecrets(workspaceId);
for (PipelineSecret secret : list.getPipelineSecrets()) {
if (name.equals(secret.getName())) {
return secret;
}
}
throw new SecretNotFoundException(name, workspaceRef(workspaceId));
}

protected PipelineSecret fetchSecret(SecretRefOptions ref, Long wspId) throws ApiException {
return ref.secret.id != null ? api().describePipelineSecret(ref.secret.id, wspId).getPipelineSecret() : secretByName(wspId, ref.secret.name);
}

}


47 changes: 47 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/secrets/AddCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.secrets;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.secrets.SecretAdded;
import io.seqera.tower.model.CreatePipelineSecretRequest;
import io.seqera.tower.model.CreatePipelineSecretResponse;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;

import java.io.IOException;

@Command(
name = "add",
description = "Add a workspace secret."
)
public class AddCmd extends AbstractSecretsCmd {

@Option(names = {"-n", "--name"}, description = "Secret name.", required = true)
public String name;

@Mixin
public WorkspaceOptionalOptions workspace;

@Option(names = {"-v", "--value"}, description = "Secret value.")
public String value;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(workspace.workspace);
CreatePipelineSecretResponse response = api().createPipelineSecret(new CreatePipelineSecretRequest().name(name).value(value), wspId);
return new SecretAdded(workspaceRef(wspId), response.getSecretId(), name);
}
}
42 changes: 42 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/secrets/DeleteCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.secrets;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.secrets.SecretDeleted;
import io.seqera.tower.model.PipelineSecret;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

import java.io.IOException;

@Command(
name = "delete",
description = "Delete a workspace secret."
)
public class DeleteCmd extends AbstractSecretsCmd {

@Mixin
public WorkspaceOptionalOptions workspace;
@Mixin
SecretRefOptions ref;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(workspace.workspace);
PipelineSecret secret = fetchSecret(ref, wspId);
api().deletePipelineSecret(secret.getId(), wspId);
return new SecretDeleted(secret, workspaceRef(wspId));
}
}
Loading

0 comments on commit 6ddd97f

Please sign in to comment.