@@ -19,29 +19,45 @@ type info struct {
19
19
Origin string
20
20
}
21
21
22
+ type infoRequest struct {
23
+ ShowSecret * bool
24
+ }
25
+
22
26
func infosRoot () * core.Command {
23
27
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
+ },
28
39
Run : func (ctx context.Context , argsI interface {}) (i interface {}, e error ) {
40
+ req := argsI .(* infoRequest )
29
41
return []info {
30
- {
31
- Key : "config_path" ,
32
- Value : "~/.config/scw/config.yaml" ,
33
- },
42
+ configPath (ctx ),
34
43
defaultRegion (ctx ),
35
44
defaultZone (ctx ),
36
45
defaultOrganizationId (ctx ),
37
46
accessKey (ctx ),
38
- secretKey (ctx ),
47
+ secretKey (ctx , req . ShowSecret ),
39
48
profile (ctx ),
40
49
}, nil
41
50
},
42
51
}
43
52
}
44
53
54
+ func configPath (ctx context.Context ) info {
55
+ return info {
56
+ Key : "config_path" ,
57
+ Value : "~/.config/scw/config.yaml" ,
58
+ }
59
+ }
60
+
45
61
func defaultRegion (ctx context.Context ) info {
46
62
info := info {Key : "default_region" }
47
63
client := core .ExtractClient (ctx )
@@ -86,12 +102,31 @@ func accessKey(ctx context.Context) info {
86
102
return info
87
103
}
88
104
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 {
90
117
info := info {Key : "secret_key" }
91
118
client := core .ExtractClient (ctx )
92
119
sK , exists := client .GetSecretKey ()
93
120
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
+ }
95
130
info .Origin = "config_file"
96
131
}
97
132
return info
0 commit comments