This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
CLI now supports streams command #356
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,29 @@ | ||
| ## galasactl streams | ||
|
|
||
| Manages test streams in a Galasa service | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Parent command for managing test streams in a Galasa service | ||
|
|
||
| ### 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 'streams' command. | ||
| --rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3) | ||
| --rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1) | ||
| ``` | ||
|
|
||
| ### 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 streams get](galasactl_streams_get.md) - Gets a list of test streams | ||
|
|
This file contains hidden or 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,34 @@ | ||
| ## galasactl streams get | ||
|
|
||
| Gets a list of test streams | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Get a list of test streams from the Galasa service | ||
|
|
||
| ``` | ||
| galasactl streams get [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --format string the output format of the returned streams. Supported formats are: 'summary', 'yaml'. (default "summary") | ||
| -h, --help Displays the options for the 'streams get' command. | ||
| --name string An optional field indicating the name of a test stream | ||
| ``` | ||
|
|
||
| ### 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. | ||
| --rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3) | ||
| --rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [galasactl streams](galasactl_streams.md) - Manages test streams in a Galasa service | ||
|
|
This file contains hidden or 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 hidden or 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,98 @@ | ||
| /* | ||
| * 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 StreamsCmdValues struct { | ||
| name string | ||
| } | ||
|
|
||
| type StreamsCommand struct { | ||
| values *StreamsCmdValues | ||
| cobraCommand *cobra.Command | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Constructors methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func NewStreamsCommand(rootCmd spi.GalasaCommand, commsFlagSet GalasaFlagSet) (spi.GalasaCommand, error) { | ||
|
|
||
| cmd := new(StreamsCommand) | ||
| err := cmd.init(rootCmd, commsFlagSet) | ||
| return cmd, err | ||
|
|
||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Public methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *StreamsCommand) Name() string { | ||
| return COMMAND_NAME_STREAMS | ||
| } | ||
|
|
||
| func (cmd *StreamsCommand) CobraCommand() *cobra.Command { | ||
| return cmd.cobraCommand | ||
| } | ||
|
|
||
| func (cmd *StreamsCommand) Values() interface{} { | ||
| return cmd.values | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Private methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| func (cmd *StreamsCommand) init(rootCmd spi.GalasaCommand, commsFlagSet GalasaFlagSet) error { | ||
|
|
||
| var err error | ||
| cmd.values = &StreamsCmdValues{} | ||
| cmd.cobraCommand = cmd.createCobraCommand(rootCmd, commsFlagSet) | ||
|
|
||
| return err | ||
|
|
||
| } | ||
|
|
||
| func (cmd *StreamsCommand) createCobraCommand( | ||
| rootCommand spi.GalasaCommand, | ||
| commsFlagSet GalasaFlagSet, | ||
| ) *cobra.Command { | ||
|
|
||
| streamsCobraCmd := &cobra.Command{ | ||
| Use: "streams", | ||
| Short: "Manages test streams in a Galasa service", | ||
| Long: "Parent command for managing test streams in a Galasa service", | ||
| } | ||
|
|
||
| streamsCobraCmd.PersistentFlags().AddFlagSet(commsFlagSet.Flags()) | ||
| rootCommand.CobraCommand().AddCommand(streamsCobraCmd) | ||
|
|
||
| return streamsCobraCmd | ||
|
|
||
| } | ||
|
|
||
| func addStreamNameFlag(cmd *cobra.Command, isMandatory bool, streamCmdValues *StreamsCmdValues) { | ||
|
|
||
| flagName := "name" | ||
| var description string | ||
|
|
||
| if isMandatory { | ||
| description = "A mandatory field indicating the name of a test stream." | ||
| } else { | ||
| description = "An optional field indicating the name of a test stream" | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&streamCmdValues.name, flagName, "", description) | ||
|
|
||
| if isMandatory { | ||
| cmd.MarkFlagRequired(flagName) | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,156 @@ | ||
| /* | ||
| * 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/spi" | ||
| "github.com/galasa-dev/cli/pkg/streams" | ||
| "github.com/galasa-dev/cli/pkg/utils" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type StreamsGetCmdValues struct { | ||
| outputFormat string | ||
| } | ||
|
|
||
| // Objective: Allow user to do this: | ||
| // | ||
| // streams get | ||
| type StreamsGetCommand struct { | ||
| cobraCommand *cobra.Command | ||
| values *StreamsGetCmdValues | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Constructors methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func NewStreamsGetCommand( | ||
| factory spi.Factory, | ||
| streamsGetCommand spi.GalasaCommand, | ||
| commsFlagSet GalasaFlagSet, | ||
| ) (spi.GalasaCommand, error) { | ||
|
|
||
| cmd := new(StreamsGetCommand) | ||
| err := cmd.init(factory, streamsGetCommand, commsFlagSet) | ||
| return cmd, err | ||
|
|
||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Public methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *StreamsGetCommand) Name() string { | ||
| return COMMAND_NAME_STREAMS_GET | ||
| } | ||
|
|
||
| func (cmd *StreamsGetCommand) CobraCommand() *cobra.Command { | ||
| return cmd.cobraCommand | ||
| } | ||
|
|
||
| func (cmd *StreamsGetCommand) Values() interface{} { | ||
| return cmd.values | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Private methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *StreamsGetCommand) init(factory spi.Factory, streamsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error { | ||
|
|
||
| var err error | ||
| cmd.values = &StreamsGetCmdValues{} | ||
| cmd.cobraCommand, err = cmd.createCobraCmd(factory, streamsCommand, commsFlagSet) | ||
| return err | ||
|
|
||
| } | ||
|
|
||
| func (cmd *StreamsGetCommand) createCobraCmd( | ||
| factory spi.Factory, | ||
| streamsCommand spi.GalasaCommand, | ||
| commsFlagSet GalasaFlagSet, | ||
| ) (*cobra.Command, error) { | ||
|
|
||
| var err error | ||
|
|
||
| commsFlagSetValues := commsFlagSet.Values().(*CommsFlagSetValues) | ||
| streamCommandValues := streamsCommand.Values().(*StreamsCmdValues) | ||
|
|
||
| streamsGetCobraCmd := &cobra.Command{ | ||
| Use: "get", | ||
| Short: "Gets a list of test streams", | ||
| Long: "Get a list of test streams from the Galasa service", | ||
| Aliases: []string{COMMAND_NAME_STREAMS_GET}, | ||
| RunE: func(cobraCommand *cobra.Command, args []string) error { | ||
| return cmd.executeStreamsGet( | ||
| factory, streamsCommand.Values().(*StreamsCmdValues), commsFlagSetValues, | ||
| ) | ||
| }, | ||
| } | ||
|
|
||
| addStreamNameFlag(streamsGetCobraCmd, false, streamCommandValues) | ||
|
|
||
| formatters := streams.GetFormatterNamesAsString() | ||
| streamsGetCobraCmd.Flags().StringVar(&cmd.values.outputFormat, "format", "summary", "the output format of the returned streams. Supported formats are: "+formatters+".") | ||
aashir21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| streamsCommand.CobraCommand().AddCommand(streamsGetCobraCmd) | ||
|
|
||
| return streamsGetCobraCmd, err | ||
|
|
||
| } | ||
|
|
||
| func (cmd *StreamsGetCommand) executeStreamsGet( | ||
| factory spi.Factory, | ||
| streamsCmdValues *StreamsCmdValues, | ||
| commsFlagSetValues *CommsFlagSetValues, | ||
| ) error { | ||
|
|
||
| var err error | ||
|
|
||
| // Operations on the file system will all be relative to the current folder. | ||
| fileSystem := factory.GetFileSystem() | ||
|
|
||
| err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName) | ||
| if err == nil { | ||
|
|
||
| commsFlagSetValues.isCapturingLogs = true | ||
| log.Println("Galasa CLI - Get streams from the Galasa service") | ||
|
|
||
| env := factory.GetEnvironment() | ||
|
|
||
| var galasaHome spi.GalasaHome | ||
| galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath) | ||
|
|
||
| if err == nil { | ||
|
|
||
| var commsClient api.APICommsClient | ||
| commsClient, err = api.NewAPICommsClient( | ||
| commsFlagSetValues.bootstrap, | ||
| commsFlagSetValues.maxRetries, | ||
| commsFlagSetValues.retryBackoffSeconds, | ||
| factory, | ||
| galasaHome, | ||
| ) | ||
|
|
||
| if err == nil { | ||
| var console = factory.GetStdOutConsole() | ||
| getStreamsFunc := func(apiClient *galasaapi.APIClient) error { | ||
| return streams.GetStreams(streamsCmdValues.name, cmd.values.outputFormat, apiClient, console) | ||
| } | ||
|
|
||
| err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(getStreamsFunc) | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| return err | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.