diff --git a/api/bb-api.go b/api/bb-api.go index 297c224..80faed1 100644 --- a/api/bb-api.go +++ b/api/bb-api.go @@ -1,3 +1,5 @@ +// vim: foldmethod=indent foldnestmax=1 + package api import ( @@ -377,3 +379,24 @@ func GetEnvironmentList(repository string, status bool) <-chan Environment { }() return channel } + +func GetEnvironmentVariables(repository string, envName string) <-chan EnvironmentVariable { + channel := make(chan EnvironmentVariable) + go func() { + defer close(channel) + + for env := range GetEnvironmentList(repository, false) { + if env.Name == envName { + var environmentResponse BBPaginatedResponse[EnvironmentVariable] + response := bbApiGet(fmt.Sprintf("repositories/%s/deployments_config/environments/%s/variables", repository, env.UUID)) + err := json.Unmarshal(response, &environmentResponse) + cobra.CheckErr(err) + for _, envVar := range environmentResponse.Values { + channel <- envVar + } + break + } + } + }() + return channel +} diff --git a/api/bb-types.go b/api/bb-types.go index e6f5974..a7b68c3 100644 --- a/api/bb-types.go +++ b/api/bb-types.go @@ -1,3 +1,5 @@ +// vim: foldmethod=indent foldnestmax=1 + package api import ( @@ -75,23 +77,6 @@ type CommitStatus struct { UpdatedOn time.Time `json:"updated_on"` } -type Environment struct { - UUID string `json:"uuid"` - Name string - Category struct { - Name string - } - EnvironmentType struct { - Name string - } `json:"environment_type"` - Lock struct { - Triggerer struct { - PipelineUUID string `json:"pipeline_uuid"` - } - } - Status Pipeline -} - type Pipeline struct { BuildNumber int `json:"build_number"` State struct { @@ -133,6 +118,29 @@ type PrComment struct { UpdatedOn time.Time `json:"updated_on"` } +type Environment struct { + UUID string `json:"uuid"` + Name string + Category struct { + Name string + } + EnvironmentType struct { + Name string + } `json:"environment_type"` + Lock struct { + Triggerer struct { + PipelineUUID string `json:"pipeline_uuid"` + } + } + Status Pipeline +} + +type EnvironmentVariable struct { + Key string + Value string + Secured bool +} + // DEFAULT ACTIONS OVERRIDES // String is used both by fmt.Print and by Cobra in help text diff --git a/cmd/environment/environment.go b/cmd/environment/environment.go index 7df61e1..90bcc40 100644 --- a/cmd/environment/environment.go +++ b/cmd/environment/environment.go @@ -25,5 +25,6 @@ var EnvironmentCmd = &cobra.Command{ func init() { EnvironmentCmd.AddCommand(ListCmd) + EnvironmentCmd.AddCommand(VariablesCmd) EnvironmentCmd.PersistentFlags().StringP("repo", "R", "", "selected repository") } diff --git a/cmd/environment/variables.go b/cmd/environment/variables.go new file mode 100644 index 0000000..f1bb6f4 --- /dev/null +++ b/cmd/environment/variables.go @@ -0,0 +1,28 @@ +package environment + +import ( + "bb/api" + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var VariablesCmd = &cobra.Command{ + Use: "variables", + Short: "List variables for specific environment", + Long: "List variables for specific environment. If variable is secured only *** is displayed", + Aliases: []string{"var"}, + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + for variable := range api.GetEnvironmentVariables(viper.GetString("repo"), args[0]) { + if variable.Secured { + fmt.Printf("%s = \033[37m***\033[m", variable.Key) + } else { + fmt.Printf("%s = \033[37m%s\033[m", variable.Key, variable.Value) + } + + fmt.Println() + } + }, +} diff --git a/cmd/pipeline/logs.go b/cmd/pipeline/logs.go new file mode 100644 index 0000000..09bc7b6 --- /dev/null +++ b/cmd/pipeline/logs.go @@ -0,0 +1,21 @@ +package pipeline + +import ( + "bb/api" + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var LogsCmd = &cobra.Command{ + Use: "logs", + Short: "Show logs of a pipeline", + Run: func(cmd *cobra.Command, args []string) { + api.GetPipelineList(viper.GetString("repo"), 0, "") + fmt.Println("Not implemented") + }, +} + +func init() { +} diff --git a/cmd/pipeline/pipeline.go b/cmd/pipeline/pipeline.go index 1ecd38d..9361942 100644 --- a/cmd/pipeline/pipeline.go +++ b/cmd/pipeline/pipeline.go @@ -28,5 +28,6 @@ func init() { PipelineCmd.AddCommand(ViewCmd) PipelineCmd.AddCommand(StopCmd) PipelineCmd.AddCommand(RunCmd) + PipelineCmd.AddCommand(LogsCmd) PipelineCmd.PersistentFlags().StringP("repo", "R", "", "selected repository") } diff --git a/cmd/pipeline/view.go b/cmd/pipeline/view.go index 72642a5..d166f62 100644 --- a/cmd/pipeline/view.go +++ b/cmd/pipeline/view.go @@ -47,7 +47,7 @@ var ViewCmd = &cobra.Command{ fmt.Printf("\033[1;34m[ %s ]\033[m\n", pipeline.Target.RefName) } - fmt.Printf(" \033[33m%s\033[m \033[37mTrigger: %s\033[m\n", pipeline.Author.DisplayName, pipeline.Trigger.Name) // \033[37mComments: %d\033[m", + fmt.Printf(" \033[33m%s\033[m \033[37mTrigger: %s\033[m\n", pipeline.Author.DisplayName, pipeline.Trigger.Name) web, _ := cmd.Flags().GetBool("web") if web {