Skip to content

Commit

Permalink
feat: add insecure mode, fixes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Jan 30, 2021
1 parent e1d9b7d commit 9376569
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ func Init(name string, version string) {
# Specify verb, header, and body shorthand
$ %s post :8888/users -H authorization:abc123 name: Kari, role: admin`, name, name),
Args: cobra.MinimumNArgs(1),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
settings := viper.AllSettings()
LogDebug("Configuration: %v", settings)

if viper.GetBool("rsh-insecure") {
if t, ok := http.DefaultTransport.(*http.Transport); ok {
LogWarning("Disabling TLS security checks")
if t.TLSClientConfig == nil {
t.TLSClientConfig = &tls.Config{}
}
t.TLSClientConfig.InsecureSkipVerify = true
}
}
},
Run: func(cmd *cobra.Command, args []string) {
generic(http.MethodGet, args[0], args[1:])
},
Expand Down Expand Up @@ -313,6 +327,7 @@ Not after (expires): %s (%s)
AddGlobalFlag("rsh-no-paginate", "", "Disable auto-pagination", false, false)
AddGlobalFlag("rsh-profile", "p", "API auth profile", "default", false)
AddGlobalFlag("rsh-no-cache", "", "Disable HTTP cache", false, false)
AddGlobalFlag("rsh-insecure", "", "Disable SSL verification", false, false)

initAPIConfig()
}
Expand Down Expand Up @@ -422,9 +437,6 @@ func Run() {
// Now that flags are parsed we can enable verbose mode if requested.
if enableVerbose || viper.GetBool("rsh-verbose") {
enableVerbose = true

settings := viper.AllSettings()
LogDebug("Configuration: %v", settings)
}

// Load the API commands if we can.
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The global options in addition to `--help` and `--version` are:
| --------------------------- | ------------------- | ----------------- | -------------------------------------------------------------------------------- |
| `-f`, `--rsh-filter` | `RSH_FILTER` | `body.users[].id` | [JMESPath Plus](https://github.com/danielgtaylor/go-jmespath-plus#readme) filter |
| `-H`, `--rsh-header` | `RSH_HEADER` | `Version:2020-05` | Set a header name/value |
| `--rsh-insecure` | `RSH_INSECURE` | | Disable TLS certificate checks |
| `--rsh-no-cache` | `RSH_NO_CACHE` | | Disable HTTP caching |
| `--rsh-no-paginate` | `RSH_NO_PAGINATE` | | Disable automatic `next` link pagination |
| `-o`, `--rsh-output-format` | `RSH_OUTPUT_FORMAT` | `json` | [Output format](/output.md), defaults to `auto` |
Expand Down

0 comments on commit 9376569

Please sign in to comment.