Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ The `galasactl` tool can generate the following errors:
- GAL1230E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1231E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1232E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1233E: The stream name provided by the --name field cannot be an empty string.
- GAL1234E: Could not get list of test streams from API server. Reason: '{}'.
- GAL1235E: The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).
- GAL1236E: Failed to get streams. Unexpected http status code {} received from the server.
- GAL1237E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1238E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1239E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1240E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL2000W: Warning: Maven configuration file settings.xml should contain a reference to a Galasa repository so that the galasa OBR can be resolved. The official release repository is '{}', and 'pre-release' repository is '{}'
- GAL2501I: Downloaded {} artifacts to folder '{}'

Expand Down
1 change: 1 addition & 0 deletions docs/generated/galasactl.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ A tool for controlling Galasa resources using the command-line.
* [galasactl roles](galasactl_roles.md) - Manage roles stored in the Galasa service
* [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 streams](galasactl_streams.md) - Manages test streams in a Galasa service
* [galasactl users](galasactl_users.md) - Manages users in an ecosystem

29 changes: 29 additions & 0 deletions docs/generated/galasactl_streams.md
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

34 changes: 34 additions & 0 deletions docs/generated/galasactl_streams_get.md
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

26 changes: 26 additions & 0 deletions pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const (
COMMAND_NAME_USERS_DELETE = "users delete"
COMMAND_NAME_ROLES = "roles"
COMMAND_NAME_ROLES_GET = "roles get"
COMMAND_NAME_STREAMS = "streams"
COMMAND_NAME_STREAMS_GET = "streams get"
)

// -----------------------------------------------------------------
Expand Down Expand Up @@ -172,6 +174,10 @@ func (commands *commandCollectionImpl) init(factory spi.Factory) error {
err = commands.addRolesCommands(factory, rootCommand, commsFlagSet)
}

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

if err == nil {
commands.setHelpFlags()
}
Expand Down Expand Up @@ -508,6 +514,26 @@ func (commands *commandCollectionImpl) addRolesCommands(factory spi.Factory, roo
return err
}

func (commands *commandCollectionImpl) addStreamsCommands(factory spi.Factory, rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {

var err error
var streamsCommand spi.GalasaCommand
var streamsGetCommand spi.GalasaCommand

streamsCommand, err = NewStreamsCommand(rootCommand, commsFlagSet)

if err == nil {
streamsGetCommand, err = NewStreamsGetCommand(factory, streamsCommand, commsFlagSet)
if err == nil {
commands.commandMap[streamsCommand.Name()] = streamsCommand
commands.commandMap[streamsGetCommand.Name()] = streamsGetCommand
}
}

return err

}

func (commands *commandCollectionImpl) setHelpFlags() {
for _, command := range commands.commandMap {
command.CobraCommand().Flags().BoolP("help", "h", false, "Displays the options for the '"+command.Name()+"' command.")
Expand Down
98 changes: 98 additions & 0 deletions pkg/cmd/streams.go
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)
}

}
159 changes: 159 additions & 0 deletions pkg/cmd/streamsGet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* 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+".")

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()
var byteReader = factory.GetByteReader()

getStreamsFunc := func(apiClient *galasaapi.APIClient) error {
return streams.GetStreams(streamsCmdValues.name, cmd.values.outputFormat, apiClient, console,byteReader)
}

err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(getStreamsFunc)

}

}

}

return err
}
Loading