-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add secrets commands * Test secrets commands * Update SDK v1.4.2
- Loading branch information
Showing
18 changed files
with
818 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
30 changes: 30 additions & 0 deletions
30
src/main/java/io/seqera/tower/cli/commands/SecretsCmd.java
This file contains 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,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 { | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/io/seqera/tower/cli/commands/secrets/AbstractSecretsCmd.java
This file contains 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,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
47
src/main/java/io/seqera/tower/cli/commands/secrets/AddCmd.java
This file contains 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,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
42
src/main/java/io/seqera/tower/cli/commands/secrets/DeleteCmd.java
This file contains 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,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)); | ||
} | ||
} |
Oops, something went wrong.