@@ -6,12 +6,13 @@ import (
66 "net/http"
77 "os"
88 "runtime"
9+ "strings"
910 "sync"
1011 "time"
1112
12- "github.com/urfave/cli"
1313 "github.com/exercism/cli/config"
1414 "github.com/exercism/cli/paths"
15+ "github.com/urfave/cli"
1516)
1617
1718type pingResult struct {
@@ -53,27 +54,9 @@ func Debug(ctx *cli.Context) error {
5354 log .Fatal (err )
5455 }
5556
56- configured := true
57- if _ , err = os .Stat (c .File ); err != nil {
58- if os .IsNotExist (err ) {
59- configured = false
60- } else {
61- log .Fatal (err )
62- }
63- }
64-
65- if configured {
66- fmt .Printf ("Config file: %s\n " , c .File )
67- if c .APIKey != "" {
68- fmt .Printf ("API Key: %s\n " , c .APIKey )
69- } else {
70- fmt .Println ("API Key: Please set your API Key to access all of the CLI features" )
71- }
72- } else {
73- fmt .Printf ("Config file: %s (not configured)\n " , c .File )
74- fmt .Println ("API Key: Please set your API Key to access all of the CLI features" )
57+ if err := printConfigFileData (ctx , c ); err != nil {
58+ log .Fatal (err )
7559 }
76- fmt .Printf ("Exercises Directory: %s\n " , c .Dir )
7760
7861 fmt .Println ("Testing API endpoints reachability" )
7962
@@ -131,3 +114,40 @@ func Debug(ctx *cli.Context) error {
131114
132115 return nil
133116}
117+
118+ func printConfigFileData (ctx * cli.Context , cfg * config.Config ) error {
119+ configured := true
120+ if _ , err := os .Stat (cfg .File ); err != nil {
121+ if os .IsNotExist (err ) {
122+ configured = false
123+ } else {
124+ return err
125+ }
126+ }
127+
128+ apiKey := "Please set your API key to access all of the CLI features"
129+ configFile := fmt .Sprintf ("%s (not configured)" , cfg .File )
130+
131+ if configured {
132+ configFile = cfg .File
133+ if cfg .APIKey != "" {
134+ if ctx .Bool ("full-api-key" ) {
135+ apiKey = cfg .APIKey
136+ } else {
137+ apiKey = redactAPIKey (cfg .APIKey )
138+ }
139+ }
140+ }
141+
142+ fmt .Printf ("Config File: %s\n " , configFile )
143+ fmt .Printf ("API Key: %s\n " , apiKey )
144+ fmt .Printf ("Exercises Directory: %s\n " , cfg .Dir )
145+
146+ return nil
147+ }
148+
149+ func redactAPIKey (apiKey string ) string {
150+ str := apiKey [4 : len (apiKey )- 3 ]
151+ redaction := strings .Repeat ("*" , len (str ))
152+ return string (apiKey [:4 ]) + redaction + string (apiKey [len (apiKey )- 3 :])
153+ }
0 commit comments