Skip to content

Commit

Permalink
environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Feb 18, 2024
1 parent 83284a6 commit d59dc5e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 18 deletions.
23 changes: 23 additions & 0 deletions api/bb-api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// vim: foldmethod=indent foldnestmax=1

package api

import (
Expand Down Expand Up @@ -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
}
42 changes: 25 additions & 17 deletions api/bb-types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// vim: foldmethod=indent foldnestmax=1

package api

import (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ var EnvironmentCmd = &cobra.Command{

func init() {
EnvironmentCmd.AddCommand(ListCmd)
EnvironmentCmd.AddCommand(VariablesCmd)
EnvironmentCmd.PersistentFlags().StringP("repo", "R", "", "selected repository")
}
28 changes: 28 additions & 0 deletions cmd/environment/variables.go
Original file line number Diff line number Diff line change
@@ -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()
}
},
}
21 changes: 21 additions & 0 deletions cmd/pipeline/logs.go
Original file line number Diff line number Diff line change
@@ -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() {
}
1 change: 1 addition & 0 deletions cmd/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion cmd/pipeline/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d59dc5e

Please sign in to comment.