Skip to content

Commit

Permalink
[ND-7015] CR feedback implemented
Browse files Browse the repository at this point in the history
Signed-off-by: Aris Buzachis <[email protected]>
  • Loading branch information
aris-bunnyshell committed Dec 20, 2023
1 parent 157b5d8 commit 889334e
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 41 deletions.
1 change: 1 addition & 0 deletions cmd/environment/action/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func ensureKubernetesIntegration(deployOptions *environment.DeployOptions, kuber
}

editSettingsOptions := environment.NewEditSettingsOptions(deployOptions.ID)
editSettingsOptions.UpdateEditSettingsForType(model.GetType())

editSettingsOptions.EnvironmentEditSettings.KubernetesIntegration.Set(&kubernetesIntegration)

Expand Down
6 changes: 6 additions & 0 deletions cmd/environment/action/update.settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func init() {
RunE: func(cmd *cobra.Command, args []string) error {
editSettingsOptions.ID = settings.Profile.Context.Environment

environmentModel, err := environment.Get(&editSettingsOptions.ItemOptions)
if err != nil {
return lib.FormatCommandError(cmd, err)
}
editSettingsOptions.UpdateEditSettingsForType(environmentModel.GetType())

model, err := environment.EditSettings(editSettingsOptions)
if err != nil {
return lib.FormatCommandError(cmd, err)
Expand Down
1 change: 0 additions & 1 deletion cmd/registry_integration/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func init() {
flags := command.Flags()

flags.AddFlag(options.Organization.GetFlag("organization"))
// flags.AddFlag(options.Environment.GetFlag("environment"))

listOptions.UpdateFlagSet(flags)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ require (
bunnyshell.com/dev v0.5.5
bunnyshell.com/sdk v0.15.1
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/avast/retry-go/v4 v4.5.1
github.com/briandowns/spinner v1.23.0
github.com/fatih/color v1.15.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
github.com/thediveo/enumflag/v2 v2.0.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
Expand All @@ -26,7 +26,6 @@ require (
require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
Expand Down Expand Up @@ -85,6 +84,7 @@ require (
go.starlark.net v0.0.0-20231013162135-47c85baa7a64 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
Expand Down
9 changes: 8 additions & 1 deletion pkg/api/build_settings/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"bunnyshell.com/cli/pkg/api/common"
"bunnyshell.com/cli/pkg/net"
"bunnyshell.com/cli/pkg/util"
"bunnyshell.com/sdk"
"github.com/avast/retry-go/v4"
Expand All @@ -22,7 +23,13 @@ type ModelFetcher[T any, PT ModelWithBuildSettings[T]] func(*common.ItemOptions)

func CheckBuildSettingsValidation[T any, PT ModelWithBuildSettings[T]](fetcher ModelFetcher[T, PT], options *EditOptions, showSpinner bool) (PT, error) {
if showSpinner {
util.MakeSpinner("Validating the build settings...")
resume := net.PauseSpinner()
defer resume()

spinner := util.MakeSpinner("Validating the build settings...")

spinner.Start()
defer spinner.Stop()
}

itemOptions := common.NewItemOptions(options.ID)
Expand Down
56 changes: 42 additions & 14 deletions pkg/api/environment/action_edit_settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package environment

import (
"errors"
"fmt"
"net/http"

"bunnyshell.com/cli/pkg/api"
Expand All @@ -11,10 +13,15 @@ import (
"github.com/spf13/pflag"
)

var (
errUnknownEnvironmentType = errors.New("unknown environment type")
errUndefinedEnvironmentType = errors.New("undefined environment type")
)

type EditSettingsOptions struct {
common.ItemOptions

sdk.EnvironmentEditSettings
*sdk.EnvironmentEditSettings

EditSettingsData
}
Expand All @@ -37,11 +44,6 @@ type EditSettingsData struct {
}

func NewEditSettingsOptions(environment string) *EditSettingsOptions {
envPrimaryEditSettings := sdk.PrimaryAsEnvironmentEditSettingsEdit(sdk.NewPrimaryWithDefaults())

envEditSettings := sdk.NewEnvironmentEditSettings()
envEditSettings.Edit = &envPrimaryEditSettings

options := &EditSettingsOptions{
ItemOptions: *common.NewItemOptions(environment),

Expand All @@ -50,12 +52,27 @@ func NewEditSettingsOptions(environment string) *EditSettingsOptions {
AutoUpdate: enum.BoolNone,
},

EnvironmentEditSettings: *envEditSettings,
EnvironmentEditSettings: sdk.NewEnvironmentEditSettingsWithDefaults(),
}

return options
}

func (eso *EditSettingsOptions) UpdateEditSettingsForType(environmentType string) error {
switch environmentType {
case "primary":
primaryEdit := sdk.PrimaryAsEnvironmentEditSettingsEdit(sdk.NewPrimaryWithDefaults())
eso.Edit = &primaryEdit
case "ephemeral":
ephemeralEdit := sdk.EphemeralAsEnvironmentEditSettingsEdit(sdk.NewEphemeralWithDefaults())
eso.Edit = &ephemeralEdit
default:
return fmt.Errorf("%w: %s", errUnknownEnvironmentType, environmentType)
}

return nil
}

func (eso *EditSettingsOptions) UpdateFlagSet(flags *pflag.FlagSet) {
data := &eso.EditSettingsData

Expand Down Expand Up @@ -88,28 +105,32 @@ func (eso *EditSettingsOptions) UpdateFlagSet(flags *pflag.FlagSet) {
"Create ephemeral environments when pull requests are created (for 'primary' environments)",
)
flags.AddFlag(ephCreateFlag)
ephCreateFlag.NoOptDefVal = "false"
ephCreateFlag.NoOptDefVal = "true"

ephDestroyFlag := enum.BoolFlag(
&data.DestroyEphemeralOnPrClose,
"destroy-ephemeral-on-pr-close",
"Destroys the created ephemerals when the pull request is closed (or merged) (for 'primary' environments)",
)
flags.AddFlag(ephDestroyFlag)
ephDestroyFlag.NoOptDefVal = "false"
ephDestroyFlag.NoOptDefVal = "true"

ephAutoDeployFlag := enum.BoolFlag(
&data.AutoDeployEphemeral,
"auto-deploy-ephemerals",
"Auto deploy the created ephemerals (for 'primary' environments)",
)
flags.AddFlag(ephAutoDeployFlag)
ephAutoDeployFlag.NoOptDefVal = "false"
ephAutoDeployFlag.NoOptDefVal = "true"

flags.StringVar(&data.EphemeralK8SIntegration, "ephemerals-k8s", data.EphemeralK8SIntegration, "The Kubernetes integration to be used for the ephemeral environments triggered by this environment (for 'primary' environments)")
}

func EditSettings(options *EditSettingsOptions) (*sdk.EnvironmentItem, error) {
if options.Edit == nil {
return nil, fmt.Errorf("%w", errUndefinedEnvironmentType)
}

model, resp, err := EditSettingsRaw(options)
if err != nil {
return nil, api.ParseError(resp, err)
Expand Down Expand Up @@ -165,6 +186,17 @@ func applyEditSettingsOptions(
options.EnvironmentEditSettings.SetLabels(labelsEdit)
}

isPrimaryType := options.EnvironmentEditSettings.Edit.Primary != nil
if isPrimaryType {
applyPrimaryEditSettingsOptions(options)
}

request = request.EnvironmentEditSettings(*options.EnvironmentEditSettings)

return request
}

func applyPrimaryEditSettingsOptions(options *EditSettingsOptions) {
if options.EphemeralK8SIntegration != "" {
options.EnvironmentEditSettings.Edit.Primary.SetEphemeralKubernetesIntegration(options.EphemeralK8SIntegration)
}
Expand All @@ -180,8 +212,4 @@ func applyEditSettingsOptions(
if options.DestroyEphemeralOnPrClose != enum.BoolNone {
options.EnvironmentEditSettings.Edit.Primary.SetDestroyEphemeralOnPrClose(options.DestroyEphemeralOnPrClose == enum.BoolTrue)
}

request = request.EnvironmentEditSettings(options.EnvironmentEditSettings)

return request
}
18 changes: 15 additions & 3 deletions pkg/api/project_variable/action_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"bunnyshell.com/cli/pkg/api"
"bunnyshell.com/cli/pkg/api/common"
"bunnyshell.com/cli/pkg/config/enum"
"bunnyshell.com/cli/pkg/lib"
"bunnyshell.com/cli/pkg/util"
"bunnyshell.com/sdk"
Expand All @@ -17,14 +18,16 @@ type CreateOptions struct {
sdk.ProjectVariableCreateAction

Value string
IsSecret bool
IsSecret enum.Bool
}

func NewCreateOptions() *CreateOptions {
projectVariableCreateOptions := sdk.NewProjectVariableCreateAction("", "", "")

return &CreateOptions{
ProjectVariableCreateAction: *projectVariableCreateOptions,

IsSecret: enum.BoolNone,
}
}

Expand All @@ -34,12 +37,21 @@ func (co *CreateOptions) UpdateFlagSet(flags *pflag.FlagSet) {

flags.StringVar(&co.Value, "value", co.Value, "The value of the project variable")

flags.BoolVar(&co.IsSecret, "secret", co.IsSecret, "Whether the project variable is secret or not")
isSecretFlag := enum.BoolFlag(
&co.IsSecret,
"secret",
"Whether the project variable is secret or not",
)
flags.AddFlag(isSecretFlag)
isSecretFlag.NoOptDefVal = "true"
}

func Create(options *CreateOptions) (*sdk.ProjectVariableItem, error) {
options.ProjectVariableCreateAction.SetValue(options.Value)
options.ProjectVariableCreateAction.SetIsSecret(options.IsSecret)

if options.IsSecret == enum.BoolTrue {
options.ProjectVariableCreateAction.SetIsSecret(true)
}

model, resp, err := CreateRaw(options)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/project_variable/action_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (eso *EditOptions) UpdateFlagSet(flags *pflag.FlagSet) {
"Whether the project variable is secret or not",
)
flags.AddFlag(isSecretFlag)
isSecretFlag.NoOptDefVal = "false"
isSecretFlag.NoOptDefVal = "true"
}

func Edit(options *EditOptions) (*sdk.ProjectVariableItem, error) {
Expand Down
15 changes: 0 additions & 15 deletions pkg/api/registry_integration/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ func NewListOptions() *ListOptions {
}

func (lo *ListOptions) UpdateFlagSet(flags *pflag.FlagSet) {
// flags.StringVar(&lo.CloudProvider, "cloudProvider", lo.CloudProvider, "Filter by Cloud Provider")
// flags.StringVar(&lo.Status, "status", lo.Status, "Filter by Status")

lo.ListOptions.UpdateFlagSet(flags)
}

Expand Down Expand Up @@ -66,17 +63,5 @@ func applyOptions(request sdk.ApiRegistryIntegrationListRequest, options *ListOp
request = request.Organization(options.Organization)
}

// if options.Environment != "" {
// request = request.Environment(options.Environment)
// }

// if options.CloudProvider != "" {
// request = request.CloudProvider(options.CloudProvider)
// }

// if options.Status != "" {
// request = request.Status(options.Status)
// }

return request
}
16 changes: 13 additions & 3 deletions pkg/api/variable/action_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"bunnyshell.com/cli/pkg/api"
"bunnyshell.com/cli/pkg/api/common"
"bunnyshell.com/cli/pkg/config/enum"
"bunnyshell.com/cli/pkg/lib"
"bunnyshell.com/cli/pkg/util"
"bunnyshell.com/sdk"
Expand All @@ -17,7 +18,7 @@ type CreateOptions struct {
sdk.EnvironmentVariableCreateAction

Value string
IsSecret bool
IsSecret enum.Bool
}

func NewCreateOptions() *CreateOptions {
Expand All @@ -34,13 +35,22 @@ func (co *CreateOptions) UpdateFlagSet(flags *pflag.FlagSet) {

flags.StringVar(&co.Value, "value", co.Value, "The value of the project variable")

flags.BoolVar(&co.IsSecret, "secret", co.IsSecret, "Whether the environment variable is secret or not")
isSecretFlag := enum.BoolFlag(
&co.IsSecret,
"secret",
"Whether the project variable is secret or not",
)
flags.AddFlag(isSecretFlag)
isSecretFlag.NoOptDefVal = "true"
}

func Create(options *CreateOptions) (*sdk.EnvironmentVariableItem, error) {
options.EnvironmentVariableCreateAction.SetIsSecret(options.IsSecret)
options.EnvironmentVariableCreateAction.SetValue(options.Value)

if options.IsSecret == enum.BoolTrue {
options.EnvironmentVariableCreateAction.SetIsSecret(true)
}

model, resp, err := CreateRaw(options)
if err != nil {
return nil, api.ParseError(resp, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/variable/action_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (eso *EditOptions) UpdateFlagSet(flags *pflag.FlagSet) {
"Whether the environment variable is secret or not",
)
flags.AddFlag(isSecretFlag)
isSecretFlag.NoOptDefVal = "false"
isSecretFlag.NoOptDefVal = "true"
}

func Edit(options *EditOptions) (*sdk.EnvironmentVariableItem, error) {
Expand Down

0 comments on commit 889334e

Please sign in to comment.