Skip to content

Commit 8db0568

Browse files
committed
Fix
1 parent c5b8e17 commit 8db0568

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

internal/namespaces/infos/custom.go

+46-11
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,45 @@ type info struct {
1919
Origin string
2020
}
2121

22+
type infoRequest struct {
23+
ShowSecret *bool
24+
}
25+
2226
func infosRoot() *core.Command {
2327
return &core.Command{
24-
Short: `Send feedback to the Scaleway CLI Team!`,
25-
Namespace: "infos",
26-
ArgsType: reflect.TypeOf(struct{}{}),
27-
ArgSpecs: core.ArgSpecs{},
28+
Short: `Get current config status`,
29+
// TODO status, infos ?
30+
Namespace: "status",
31+
ArgsType: reflect.TypeOf(infoRequest{}),
32+
ArgSpecs: core.ArgSpecs{
33+
{
34+
Name: "show-secret",
35+
Short: `Reveal secret`,
36+
Required: false,
37+
},
38+
},
2839
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
40+
req := argsI.(*infoRequest)
2941
return []info{
30-
{
31-
Key: "config_path",
32-
Value: "~/.config/scw/config.yaml",
33-
},
42+
configPath(ctx),
3443
defaultRegion(ctx),
3544
defaultZone(ctx),
3645
defaultOrganizationId(ctx),
3746
accessKey(ctx),
38-
secretKey(ctx),
47+
secretKey(ctx, req.ShowSecret),
3948
profile(ctx),
4049
}, nil
4150
},
4251
}
4352
}
4453

54+
func configPath(ctx context.Context) info {
55+
return info{
56+
Key: "config_path",
57+
Value: "~/.config/scw/config.yaml",
58+
}
59+
}
60+
4561
func defaultRegion(ctx context.Context) info {
4662
info := info{Key: "default_region"}
4763
client := core.ExtractClient(ctx)
@@ -86,12 +102,31 @@ func accessKey(ctx context.Context) info {
86102
return info
87103
}
88104

89-
func secretKey(ctx context.Context) info {
105+
func HideSecretKey(k string) string {
106+
switch {
107+
case len(k) == 0:
108+
return ""
109+
case len(k) > 8:
110+
return k[0:8] + "-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
111+
default:
112+
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
113+
}
114+
}
115+
116+
func secretKey(ctx context.Context, secrets *bool) info {
90117
info := info{Key: "secret_key"}
91118
client := core.ExtractClient(ctx)
92119
sK, exists := client.GetSecretKey()
93120
if exists {
94-
info.Value = sK
121+
showSecrets := false
122+
if secrets != nil {
123+
showSecrets = *secrets
124+
}
125+
if showSecrets {
126+
info.Value = sK
127+
} else {
128+
info.Value = HideSecretKey(sK)
129+
}
95130
info.Origin = "config_file"
96131
}
97132
return info

0 commit comments

Comments
 (0)