Skip to content

Commit e27510c

Browse files
committed
Hiding sensitive data in inspect (#64)
1 parent 92b2c25 commit e27510c

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ Examples:
403403
$ scw inspect my-server | jq '.[0].public_ip.address'
404404
$ scw inspect $(scw inspect my-image | jq '.[0].root_volume.id')
405405
$ scw inspect -f "{{ .PublicAddress.IP }}" my-server
406+
$ scw --sensitive inspect my-server
406407
```
407408

408409

@@ -1017,6 +1018,8 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
10171018

10181019
#### Features
10191020

1021+
* Hiding sensitive data by default on `scw inspect` ([#64](https://github.com/scaleway/scaleway-cli/issues/64))
1022+
* Support of `scw --sensitive` option ([#64](https://github.com/scaleway/scaleway-cli/issues/64))
10201023
* Support of `scw run --attach` option ([#65](https://github.com/scaleway/scaleway-cli/issues/65))
10211024
* `scw {create,run}`, prefixing root-volume with the server hostname ([#63](https://github.com/scaleway/scaleway-cli/issues/63))
10221025
* `scw {create,run} IMAGE`, *IMAGE* can be a snapshot ([#19](https://github.com/scaleway/scaleway-cli/issues/19))

api/api.go

+7
Original file line numberDiff line numberDiff line change
@@ -1273,3 +1273,10 @@ func (s *ScalewayAPI) GetBootscriptID(needle string) string {
12731273
os.Exit(1)
12741274
return ""
12751275
}
1276+
1277+
// HideApiCredentials removes API credentials from a string
1278+
func (s *ScalewayAPI) HideApiCredentials(input string) string {
1279+
output := strings.Replace(input, s.Token, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX", -1)
1280+
output = strings.Replace(output, s.Organization, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX", -1)
1281+
return output
1282+
}

commands/help.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Options:
4444
-D, --debug=false Enable debug mode
4545
-h, --help=false Print usage
4646
-v, --version=false Print version information and quit
47+
--sensitive=false Show sensitive data in outputs, i.e. API Token/Organization
4748
4849
Commands:
4950
{{range .}}{{if not .Hidden}} {{.Name | printf "%-9s"}} {{.Description}}

commands/inspect.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var cmdInspect = &types.Command{
3535
$ scw inspect my-server | jq '.[0].public_ip.address'
3636
$ scw inspect $(scw inspect my-image | jq '.[0].root_volume.id')
3737
$ scw inspect -f "{{ .PublicAddress.IP }}" my-server
38+
$ scw --sensitive inspect my-server
3839
`,
3940
}
4041

@@ -92,6 +93,9 @@ func runInspect(cmd *types.Command, args []string) {
9293
res += "]"
9394

9495
if inspectFormat == "" {
96+
if os.Getenv("SCW_SENSITIVE") != "1" {
97+
res = cmd.API.HideApiCredentials(res)
98+
}
9599
fmt.Println(res)
96100
}
97101

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var (
5151
flAPIEndPoint *string
5252
flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
5353
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
54+
flSensitive = flag.Bool([]string{"-sensitive"}, false, "Show sensitive data in outputs, i.e. API Token/Organization")
5455
)
5556

5657
func main() {
@@ -73,6 +74,10 @@ func main() {
7374
os.Setenv("scaleway_api_endpoint", *flAPIEndPoint)
7475
}
7576

77+
if *flSensitive {
78+
os.Setenv("SCW_SENSITIVE", "1")
79+
}
80+
7681
if *flDebug {
7782
os.Setenv("DEBUG", "1")
7883
}

0 commit comments

Comments
 (0)