From 6949378fa655749404e3421438af27c402e10a41 Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Fri, 10 Mar 2023 16:24:17 +0100 Subject: [PATCH 1/4] fix(config): info display overriden variables --- internal/namespaces/config/commands.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/namespaces/config/commands.go b/internal/namespaces/config/commands.go index 2a48e37314..6afbce031f 100644 --- a/internal/namespaces/config/commands.go +++ b/internal/namespaces/config/commands.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "reflect" + "strings" "github.com/scaleway/scaleway-sdk-go/validation" @@ -569,6 +570,18 @@ func configInfoCommand() *core.Command { return nil, err } + profileEnv := scw.LoadEnvProfile() + + // Search for env variable that will override profile + // Will be used to display them + overridedVariables := []string(nil) + for _, key := range getProfileKeys() { + value, err := getProfileField(profileEnv, key) + if err == nil && !value.IsZero() { + overridedVariables = append(overridedVariables, key) + } + } + profileName := core.ExtractProfileName(ctx) // use config.GetProfile instead of getProfile as we want the profile merged with the default profile, err := config.GetProfile(profileName) @@ -576,6 +589,8 @@ func configInfoCommand() *core.Command { return nil, err } + profile = scw.MergeProfiles(profile, profileEnv) + values := map[string]any{} for _, key := range getProfileKeys() { value, err := getProfileValue(profile, key) @@ -584,6 +599,11 @@ func configInfoCommand() *core.Command { } } + if len(overridedVariables) > 0 { + msg := "Some variables are overridden by the environment: " + strings.Join(overridedVariables, ", ") + fmt.Println(terminal.Style(msg, color.FgRed)) + } + return struct { ConfigPath string ProfileName string From d6a49101cad03cd8af160bccdf4bfcb430b2ce41 Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Fri, 10 Mar 2023 17:06:48 +0100 Subject: [PATCH 2/4] bump sdk-go --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c20b317eec..b3d19dc262 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98 github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.17 - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.2 diff --git a/go.sum b/go.sum index c9646c10f6..f1f3bb8d4e 100644 --- a/go.sum +++ b/go.sum @@ -76,6 +76,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480 h1:NG+457cV++Hm3nB29tX+8a6doqx5VIksxGBnfYQGlIQ= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6 h1:bAqxZt/1FAD/M4XLqWYHySz5kNcoQ7Mrdo7imgWAyaQ= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= From 49e38d11f1d1523c80599ec0795091241e806192 Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Fri, 10 Mar 2023 17:07:02 +0100 Subject: [PATCH 3/4] update goldens --- .../config/testdata/test-config-info-command-profile.golden | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/namespaces/config/testdata/test-config-info-command-profile.golden b/internal/namespaces/config/testdata/test-config-info-command-profile.golden index af25dc930d..54add83381 100644 --- a/internal/namespaces/config/testdata/test-config-info-command-profile.golden +++ b/internal/namespaces/config/testdata/test-config-info-command-profile.golden @@ -9,6 +9,7 @@ Profile.default-region fr-par Profile.default-zone fr-par-1 Profile.insecure true Profile.secret-key 11111111-1111-1111-1111-111111111111 +Profile.send-telemetry true 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 { "ConfigPath": "/tmp/scw/.config/scw/config.yaml", @@ -22,6 +23,6 @@ Profile.secret-key 11111111-1111-1111-1111-111111111111 "default-zone": "fr-par-1", "insecure": true, "secret-key": "11111111-1111-1111-1111-111111111111", - "send-telemetry": null + "send-telemetry": true } } From b983ae69aa796b276c553a793c85caa9e0c19639 Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Fri, 10 Mar 2023 17:12:40 +0100 Subject: [PATCH 4/4] go mod tidy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index f1f3bb8d4e..d139854820 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,6 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480 h1:NG+457cV++Hm3nB29tX+8a6doqx5VIksxGBnfYQGlIQ= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6 h1:bAqxZt/1FAD/M4XLqWYHySz5kNcoQ7Mrdo7imgWAyaQ= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=