Skip to content

Commit

Permalink
Inital Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamario Rankins committed Aug 2, 2019
1 parent 52e2906 commit 867ff5e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Download exercises and submit your solutions.`,
if verbose, _ := cmd.Flags().GetBool("verbose"); verbose {
debug.Verbose = verbose
}
if unmask, _ := cmd.Flags().GetBool("unmask-token"); unmask {
debug.UnmaskAPIKey = unmask
}
if timeout, _ := cmd.Flags().GetInt("timeout"); timeout > 0 {
cli.TimeoutInSeconds = timeout
api.TimeoutInSeconds = timeout
Expand All @@ -46,4 +49,5 @@ func init() {
api.UserAgent = fmt.Sprintf("github.com/exercism/cli v%s (%s/%s)", Version, runtime.GOOS, runtime.GOARCH)
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
RootCmd.PersistentFlags().IntP("timeout", "", 0, "override the default HTTP timeout (seconds)")
RootCmd.PersistentFlags().BoolP("unmask-token", "", false, "will unmask the API duruing a request/response dump")
}
10 changes: 2 additions & 8 deletions cmd/troubleshoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"html/template"
"runtime"
"strings"
"sync"
"time"

"github.com/exercism/cli/cli"
"github.com/exercism/cli/config"
"github.com/exercism/cli/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -192,7 +192,7 @@ func newConfigurationStatus(status *Status) configurationStatus {
TokenURL: config.SettingsURL(v.GetString("apibaseurl")),
}
if status.Censor && cs.Token != "" {
cs.Token = redact(cs.Token)
cs.Token = utils.Redact(cs.Token)
}
return cs
}
Expand All @@ -212,12 +212,6 @@ func (ping *apiPing) Call(wg *sync.WaitGroup) {
ping.Status = "connected"
}

func redact(token string) string {
str := token[4 : len(token)-3]
redaction := strings.Repeat("*", len(str))
return string(token[:4]) + redaction + string(token[len(token)-3:])
}

const tmplSelfTest = `
Troubleshooting Information
===========================
Expand Down
14 changes: 0 additions & 14 deletions cmd/troubleshoot_test.go

This file was deleted.

15 changes: 13 additions & 2 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
"net/http"
"net/http/httputil"
"os"
"strings"

"github.com/exercism/cli/utils"
)

var (
// Verbose determines if debugging output is displayed to the user
Verbose bool
output io.Writer = os.Stderr
Verbose bool
output io.Writer = os.Stderr
UnmaskAPIKey bool
)

// Println conditionally outputs a message to Stderr
Expand All @@ -41,6 +45,12 @@ func DumpRequest(req *http.Request) {
body := io.TeeReader(req.Body, &bodyCopy)
req.Body = ioutil.NopCloser(body)

temp := req.Header.Get("Authorization")

if !UnmaskAPIKey {
req.Header.Set("Authorization", "Bearer "+utils.Redact(strings.Split(temp, " ")[1]))
}

dump, err := httputil.DumpRequest(req, req.ContentLength > 0)
if err != nil {
log.Fatal(err)
Expand All @@ -51,6 +61,7 @@ func DumpRequest(req *http.Request) {
Println("========================= END DumpRequest =========================")
Println("")

req.Header.Set("Authorization", temp)
req.Body = ioutil.NopCloser(&bodyCopy)
}

Expand Down
31 changes: 17 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ module github.com/exercism/cli

require (
github.com/blang/semver v3.5.1+incompatible
github.com/davecgh/go-spew v1.1.0
github.com/fsnotify/fsnotify v1.4.2
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.2 // indirect
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/inconshreveable/mousetrap v1.0.0
github.com/magiconair/properties v1.7.3
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992
github.com/pelletier/go-buffruneio v0.2.0
github.com/pelletier/go-toml v1.0.0
github.com/pmezard/go-difflib v1.0.0
github.com/spf13/afero v0.0.0-20170217164146-9be650865eab
github.com/spf13/cast v1.1.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/ld9999999999/go-interfacetools v0.0.0-20151014172923-5c708af5db62
github.com/magiconair/properties v1.7.3 // indirect
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992 // indirect
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/pelletier/go-toml v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v0.0.0-20170217164146-9be650865eab // indirect
github.com/spf13/cast v1.1.0 // indirect
github.com/spf13/cobra v0.0.0-20170731170427-b26b538f6930
github.com/spf13/jwalterweatherman v0.0.0-20170523133247-0efa5202c046
github.com/spf13/jwalterweatherman v0.0.0-20170523133247-0efa5202c046 // indirect
github.com/spf13/pflag v1.0.0
github.com/spf13/viper v0.0.0-20180507071007-15738813a09d
github.com/stretchr/testify v1.1.4
golang.org/x/net v0.0.0-20170726083632-f5079bd7f6f7
golang.org/x/sys v0.0.0-20170803140359-d8f5ea21b929
golang.org/x/sys v0.0.0-20170803140359-d8f5ea21b929 // indirect
golang.org/x/text v0.0.0-20170730040918-3bd178b88a81
gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/exercism/c v0.0.0-20190801120910-35035966d3ef h1:DIBUBpXo2Zot+UiaPmuwPYdmqg8pYqB5thsNWINiPD4=
github.com/fsnotify/fsnotify v1.4.2 h1:v5tKwtf2hNhBV24eNYfQ5UmvFOGlOCmRqk7/P1olxtk=
github.com/fsnotify/fsnotify v1.4.2/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e h1:KJWs1uTCkN3E/J5ofCH9Pf8KKsibTFc3fv0CA9+WsVo=
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ld9999999999/go-interfacetools v0.0.0-20151014172923-5c708af5db62 h1:Yxmgqjdx/bnDhp8TSw9CENvRrMiJklKYDfruUMROaFk=
github.com/ld9999999999/go-interfacetools v0.0.0-20151014172923-5c708af5db62/go.mod h1:HaEcNiqo/Y5y/ZpHKx6bWRvJJ+HXelkjSCpk0MEf19k=
github.com/magiconair/properties v1.7.3 h1:6AOjgCKyZFMG/1yfReDPDz3CJZPxnYk7DGmj2HtyF24=
github.com/magiconair/properties v1.7.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992 h1:W7VHAEVflA5/eTyRvQ53Lz5j8bhRd1myHZlI/IZFvbU=
Expand Down Expand Up @@ -39,5 +48,7 @@ golang.org/x/sys v0.0.0-20170803140359-d8f5ea21b929 h1:M4VPQYSW/nB4Bcg1XMD4yW2sp
golang.org/x/sys v0.0.0-20170803140359-d8f5ea21b929/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.0.0-20170730040918-3bd178b88a81 h1:7aXI3TQ9sZ4JdDoIDGjxL6G2mQxlsPy9dySnJaL6Bdk=
golang.org/x/text v0.0.0-20170730040918-3bd178b88a81/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d h1:2DX7x6HUDGZUyuEDAhUsQQNqkb1zvDyKTjVoTdzaEzo=
gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=

0 comments on commit 867ff5e

Please sign in to comment.