Skip to content

Commit 1ae8f24

Browse files
authored
fix(config): info display overriden variables (#2856)
1 parent 06be86c commit 1ae8f24

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
2020
github.com/mattn/go-colorable v0.1.13
2121
github.com/mattn/go-isatty v0.0.17
22-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480
22+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6
2323
github.com/spf13/cobra v1.6.1
2424
github.com/spf13/pflag v1.0.5
2525
github.com/stretchr/testify v1.8.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw
7474
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7575
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7676
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
77-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480 h1:NG+457cV++Hm3nB29tX+8a6doqx5VIksxGBnfYQGlIQ=
78-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230308172750-e6fa6ad07480/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
77+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6 h1:bAqxZt/1FAD/M4XLqWYHySz5kNcoQ7Mrdo7imgWAyaQ=
78+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14.0.20230310155856-7a2786489bc6/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
7979
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
8080
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
8181
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=

internal/namespaces/config/commands.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"reflect"
9+
"strings"
910

1011
"github.com/scaleway/scaleway-sdk-go/validation"
1112

@@ -569,13 +570,27 @@ func configInfoCommand() *core.Command {
569570
return nil, err
570571
}
571572

573+
profileEnv := scw.LoadEnvProfile()
574+
575+
// Search for env variable that will override profile
576+
// Will be used to display them
577+
overridedVariables := []string(nil)
578+
for _, key := range getProfileKeys() {
579+
value, err := getProfileField(profileEnv, key)
580+
if err == nil && !value.IsZero() {
581+
overridedVariables = append(overridedVariables, key)
582+
}
583+
}
584+
572585
profileName := core.ExtractProfileName(ctx)
573586
// use config.GetProfile instead of getProfile as we want the profile merged with the default
574587
profile, err := config.GetProfile(profileName)
575588
if err != nil {
576589
return nil, err
577590
}
578591

592+
profile = scw.MergeProfiles(profile, profileEnv)
593+
579594
values := map[string]any{}
580595
for _, key := range getProfileKeys() {
581596
value, err := getProfileValue(profile, key)
@@ -584,6 +599,11 @@ func configInfoCommand() *core.Command {
584599
}
585600
}
586601

602+
if len(overridedVariables) > 0 {
603+
msg := "Some variables are overridden by the environment: " + strings.Join(overridedVariables, ", ")
604+
fmt.Println(terminal.Style(msg, color.FgRed))
605+
}
606+
587607
return struct {
588608
ConfigPath string
589609
ProfileName string

internal/namespaces/config/testdata/test-config-info-command-profile.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Profile.default-region fr-par
99
Profile.default-zone fr-par-1
1010
Profile.insecure true
1111
Profile.secret-key 11111111-1111-1111-1111-111111111111
12+
Profile.send-telemetry true
1213
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1314
{
1415
"ConfigPath": "/tmp/scw/.config/scw/config.yaml",
@@ -22,6 +23,6 @@ Profile.secret-key 11111111-1111-1111-1111-111111111111
2223
"default-zone": "fr-par-1",
2324
"insecure": true,
2425
"secret-key": "11111111-1111-1111-1111-111111111111",
25-
"send-telemetry": null
26+
"send-telemetry": true
2627
}
2728
}

0 commit comments

Comments
 (0)