-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add galasactl secrets get command and formatters (#301)
* feat: Add galasactl secrets get command and formatters Signed-off-by: Eamonn Mansour <[email protected]> * feat: Add validation to secrets Signed-off-by: Eamonn Mansour <[email protected]> * Empty commit to kick off build Signed-off-by: Eamonn Mansour <[email protected]> --------- Signed-off-by: Eamonn Mansour <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,711 additions
and
5 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## galasactl secrets get | ||
|
||
Get secrets from the credentials store | ||
|
||
### Synopsis | ||
|
||
Get a list of secrets or a specific secret from the credentials store | ||
|
||
``` | ||
galasactl secrets get [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--format string the output format of the returned secrets. Supported formats are: 'summary', 'yaml'. (default "summary") | ||
-h, --help Displays the options for the 'secrets get' command. | ||
--name string An optional flag that identifies the secret to be retrieved. | ||
``` | ||
|
||
### 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 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/galasa-dev/cli/pkg/api" | ||
"github.com/galasa-dev/cli/pkg/galasaapi" | ||
"github.com/galasa-dev/cli/pkg/secrets" | ||
"github.com/galasa-dev/cli/pkg/spi" | ||
"github.com/galasa-dev/cli/pkg/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type SecretsGetCmdValues struct { | ||
outputFormat string | ||
} | ||
|
||
type SecretsGetCommand struct { | ||
values *SecretsGetCmdValues | ||
cobraCommand *cobra.Command | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Constructors methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func NewSecretsGetCommand( | ||
factory spi.Factory, | ||
secretsGetCommand spi.GalasaCommand, | ||
rootCmd spi.GalasaCommand, | ||
) (spi.GalasaCommand, error) { | ||
|
||
cmd := new(SecretsGetCommand) | ||
|
||
err := cmd.init(factory, secretsGetCommand, rootCmd) | ||
return cmd, err | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Public methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func (cmd *SecretsGetCommand) Name() string { | ||
return COMMAND_NAME_SECRETS_GET | ||
} | ||
|
||
func (cmd *SecretsGetCommand) CobraCommand() *cobra.Command { | ||
return cmd.cobraCommand | ||
} | ||
|
||
func (cmd *SecretsGetCommand) Values() interface{} { | ||
return cmd.values | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Private methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func (cmd *SecretsGetCommand) init(factory spi.Factory, secretsCommand spi.GalasaCommand, rootCmd spi.GalasaCommand) error { | ||
var err error | ||
|
||
cmd.values = &SecretsGetCmdValues{} | ||
cmd.cobraCommand, err = cmd.createCobraCmd(factory, secretsCommand, rootCmd.Values().(*RootCmdValues)) | ||
|
||
return err | ||
} | ||
|
||
func (cmd *SecretsGetCommand) createCobraCmd( | ||
factory spi.Factory, | ||
secretsCommand spi.GalasaCommand, | ||
rootCommandValues *RootCmdValues, | ||
) (*cobra.Command, error) { | ||
|
||
var err error | ||
|
||
secretsCommandValues := secretsCommand.Values().(*SecretsCmdValues) | ||
secretsGetCobraCmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "Get secrets from the credentials store", | ||
Long: "Get a list of secrets or a specific secret from the credentials store", | ||
Aliases: []string{COMMAND_NAME_SECRETS_GET}, | ||
RunE: func(cobraCommand *cobra.Command, args []string) error { | ||
return cmd.executeSecretsGet(factory, secretsCommand.Values().(*SecretsCmdValues), rootCommandValues) | ||
}, | ||
} | ||
|
||
addSecretNameFlag(secretsGetCobraCmd, false, secretsCommandValues) | ||
|
||
formatters := secrets.GetFormatterNamesAsString() | ||
secretsGetCobraCmd.Flags().StringVar(&cmd.values.outputFormat, "format", "summary", "the output format of the returned secrets. Supported formats are: "+formatters+".") | ||
|
||
secretsCommand.CobraCommand().AddCommand(secretsGetCobraCmd) | ||
|
||
return secretsGetCobraCmd, err | ||
} | ||
|
||
func (cmd *SecretsGetCommand) executeSecretsGet( | ||
factory spi.Factory, | ||
secretsCmdValues *SecretsCmdValues, | ||
rootCmdValues *RootCmdValues, | ||
) error { | ||
|
||
var err error | ||
// Operations on the file system will all be relative to the current folder. | ||
fileSystem := factory.GetFileSystem() | ||
|
||
err = utils.CaptureLog(fileSystem, rootCmdValues.logFileName) | ||
|
||
if err == nil { | ||
rootCmdValues.isCapturingLogs = true | ||
|
||
log.Println("Galasa CLI - Get secrets from the ecosystem") | ||
|
||
env := factory.GetEnvironment() | ||
|
||
var galasaHome spi.GalasaHome | ||
galasaHome, err = utils.NewGalasaHome(fileSystem, env, rootCmdValues.CmdParamGalasaHomePath) | ||
if err == nil { | ||
|
||
var urlService *api.RealUrlResolutionService = new(api.RealUrlResolutionService) | ||
var bootstrapData *api.BootstrapData | ||
bootstrapData, err = api.LoadBootstrap(galasaHome, fileSystem, env, secretsCmdValues.bootstrap, urlService) | ||
if err == nil { | ||
|
||
var console = factory.GetStdOutConsole() | ||
|
||
apiServerUrl := bootstrapData.ApiServerURL | ||
log.Printf("The API server is at '%s'\n", apiServerUrl) | ||
|
||
authenticator := factory.GetAuthenticator( | ||
apiServerUrl, | ||
galasaHome, | ||
) | ||
|
||
var apiClient *galasaapi.APIClient | ||
apiClient, err = authenticator.GetAuthenticatedAPIClient() | ||
|
||
byteReader := factory.GetByteReader() | ||
|
||
if err == nil { | ||
err = secrets.GetSecrets(secretsCmdValues.name, cmd.values.outputFormat, console, apiClient, byteReader) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.