Skip to content

Commit

Permalink
feat: Add galasactl secrets delete command
Browse files Browse the repository at this point in the history
Signed-off-by: Eamonn Mansour <[email protected]>
  • Loading branch information
eamansour committed Oct 28, 2024
1 parent 3e710bc commit 8e2c8bc
Show file tree
Hide file tree
Showing 17 changed files with 917 additions and 51 deletions.
20 changes: 20 additions & 0 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
}
],
"results": {
"dockerfiles/certs/ibminter.pem": [
{
"hashed_secret": "b3723414cb4a90ac8c2bc504ea01923fe5fccc8a",
"is_secret": false,
"is_verified": false,
"line_number": 28,
"type": "Artifactory Credentials",
"verified_result": null
}
],
"gherkin-docs.md": [
{
"hashed_secret": "c61db10457a740b07845146f2d1b391c133a6ebf",
Expand Down Expand Up @@ -125,6 +135,16 @@
"type": "Hex High Entropy String",
"verified_result": null
}
],
"pkg/secrets/secretsDelete_test.go": [
{
"hashed_secret": "2dfbe3ec00a96d6f711d9a70f78be17f6fd574ca",
"is_secret": false,
"is_verified": false,
"line_number": 83,
"type": "Secret Keyword",
"verified_result": null
}
]
},
"version": "0.13.1+ibm.62.dss",
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,19 @@ galasactl resources delete -f my_resources.yaml
For a complete list of supported parameters see [here](./docs/generated/galasactl_resources_delete.md).


## secrets delete

This command deletes a secret with the given name from the Galasa Ecosystem's credentials store. The name of the secret to be deleted must be provided using the `--name` flag.

### Examples

To delete a secret named `SYSTEM1`, run the following command:

```
galasactl secrets delete --name SYSTEM1
```

For a complete list of supported parameters see [here](./docs/generated/galasactl_secrets_delete.md).

## Reference Material

Expand Down
7 changes: 7 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ The `galasactl` tool can generate the following errors:
- GAL1164E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1165E: '{}' is not supported as a valid login ID. Login ID should not contain spaces.
- GAL1166E: The loginId provided by the --user field cannot be an empty string.
- GAL1167E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server.
- GAL1168E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1169E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1170E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1171E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1172E: Invalid secret name provided. The name provided with the --name flag cannot be empty or contain spaces.
- GAL1173E: An attempt to delete a secret named '{}' failed. Sending the delete request to the Galasa service failed. Cause is {}
- GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions.
- GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {}
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
Expand Down
1 change: 1 addition & 0 deletions docs/generated/galasactl.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ A tool for controlling Galasa resources using the command-line.
* [galasactl properties](galasactl_properties.md) - Manages properties in an ecosystem
* [galasactl resources](galasactl_resources.md) - Manages resources in an ecosystem
* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem
* [galasactl secrets](galasactl_secrets.md) - Manage secrets stored in the Galasa service's credentials store
* [galasactl users](galasactl_users.md) - Manages users in an ecosystem

27 changes: 27 additions & 0 deletions docs/generated/galasactl_secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## galasactl secrets

Manage secrets stored in the Galasa service's credentials store

### Synopsis

The parent command for operations to manipulate secrets in the Galasa service's credentials store

### Options

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
-h, --help Displays the options for the 'secrets' command.
```

### Options inherited from parent commands

```
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
```

### SEE ALSO

* [galasactl](galasactl.md) - CLI for Galasa
* [galasactl secrets delete](galasactl_secrets_delete.md) - Deletes a secret from the credentials store

31 changes: 31 additions & 0 deletions docs/generated/galasactl_secrets_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## galasactl secrets delete

Deletes a secret from the credentials store

### Synopsis

Deletes a secret from the credentials store

```
galasactl secrets delete [flags]
```

### Options

```
-h, --help Displays the options for the 'secrets delete' command.
--name string A mandatory flag that identifies the secret to be created or manipulated.
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
```

### SEE ALSO

* [galasactl secrets](galasactl_secrets.md) - Manage secrets stored in the Galasa service's credentials store

26 changes: 26 additions & 0 deletions pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (
COMMAND_NAME_RESOURCES_CREATE = "resources create"
COMMAND_NAME_RESOURCES_UPDATE = "resources update"
COMMAND_NAME_RESOURCES_DELETE = "resources delete"
COMMAND_NAME_SECRETS = "secrets"
COMMAND_NAME_SECRETS_DELETE = "secrets delete"
COMMAND_NAME_USERS = "users"
COMMAND_NAME_USERS_GET = "users get"
)
Expand Down Expand Up @@ -142,6 +144,10 @@ func (commands *commandCollectionImpl) init(factory spi.Factory) error {
err = commands.addResourcesCommands(factory, rootCommand)
}

if err == nil {
err = commands.addSecretsCommands(factory, rootCommand)
}

if err == nil {
err = commands.addUsersCommands(factory, rootCommand)
}
Expand Down Expand Up @@ -375,6 +381,26 @@ func (commands *commandCollectionImpl) addResourcesCommands(factory spi.Factory,
return err
}

func (commands *commandCollectionImpl) addSecretsCommands(factory spi.Factory, rootCommand spi.GalasaCommand) error {

var err error
var secretsCommand spi.GalasaCommand
var secretsDeleteCommand spi.GalasaCommand

secretsCommand, err = NewSecretsCmd(rootCommand)

if err == nil {
secretsDeleteCommand, err = NewSecretsDeleteCommand(factory, secretsCommand, rootCommand)
}

if err == nil {
commands.commandMap[secretsCommand.Name()] = secretsCommand
commands.commandMap[secretsDeleteCommand.Name()] = secretsDeleteCommand
}

return err
}

func (commands *commandCollectionImpl) addUsersCommands(factory spi.Factory, rootCommand spi.GalasaCommand) error {

var err error
Expand Down
95 changes: 95 additions & 0 deletions pkg/cmd/secrets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"github.com/galasa-dev/cli/pkg/spi"
"github.com/spf13/cobra"
)

type SecretsCmdValues struct {
bootstrap string
name string
}

type SecretsCommand struct {
cobraCommand *cobra.Command
values *SecretsCmdValues
}

// ------------------------------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------------------------------

func NewSecretsCmd(rootCommand spi.GalasaCommand) (spi.GalasaCommand, error) {
cmd := new(SecretsCommand)
err := cmd.init(rootCommand)
return cmd, err
}

// ------------------------------------------------------------------------------------------------
// Public functions
// ------------------------------------------------------------------------------------------------

func (cmd *SecretsCommand) Name() string {
return COMMAND_NAME_SECRETS
}

func (cmd *SecretsCommand) CobraCommand() *cobra.Command {
return cmd.cobraCommand
}

func (cmd *SecretsCommand) Values() interface{} {
return cmd.values
}

// ------------------------------------------------------------------------------------------------
// Private functions
// ------------------------------------------------------------------------------------------------

func (cmd *SecretsCommand) init(rootCmd spi.GalasaCommand) error {

var err error

cmd.values = &SecretsCmdValues{}
cmd.cobraCommand, err = cmd.createCobraCommand(rootCmd)

return err
}

func (cmd *SecretsCommand) createCobraCommand(rootCommand spi.GalasaCommand) (*cobra.Command, error) {

var err error

secretsCobraCmd := &cobra.Command{
Use: "secrets",
Short: "Manage secrets stored in the Galasa service's credentials store",
Long: "The parent command for operations to manipulate secrets in the Galasa service's credentials store",
}

addBootstrapFlag(secretsCobraCmd, &cmd.values.bootstrap)

rootCommand.CobraCommand().AddCommand(secretsCobraCmd)

return secretsCobraCmd, err
}

func addSecretNameFlag(cmd *cobra.Command, isMandatory bool, secretsCmdValues *SecretsCmdValues) {

flagName := "name"
var description string
if isMandatory {
description = "A mandatory flag that identifies the secret to be created or manipulated."
} else {
description = "An optional flag that identifies the secret to be retrieved."
}

cmd.Flags().StringVar(&secretsCmdValues.name, flagName, "", description)

if isMandatory {
cmd.MarkFlagRequired(flagName)
}
}
Loading

0 comments on commit 8e2c8bc

Please sign in to comment.