mirror of
https://github.com/thegeeklab/wp-plugin-go.git
synced 2024-11-22 00:20:38 +00:00
Add SSL skip verify flag
This commit is contained in:
parent
537cb2c489
commit
0324ae7edb
@ -7,6 +7,7 @@ package urfave
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
@ -31,15 +32,15 @@ type Network struct {
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
const networkSSLVerifyFlag = "transport.ssl-verify"
|
||||
const networkSkipVerifyFlag = "transport.skip-verify"
|
||||
|
||||
// networkFlags has the cli.Flags for the Transport.
|
||||
func networkFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: networkSSLVerifyFlag,
|
||||
Usage: "transport ssl verify",
|
||||
EnvVar: "PLUGIN_SSL_VERIFY",
|
||||
cli.BoolTFlag{
|
||||
Name: networkSkipVerifyFlag,
|
||||
Usage: "skip ssl verify",
|
||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -47,8 +48,7 @@ func networkFlags() []cli.Flag {
|
||||
// NetworkFromContext creates a Transport from the cli.Context.
|
||||
func NetworkFromContext(ctx *cli.Context) Network {
|
||||
// Create the client
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
@ -60,7 +60,13 @@ func NetworkFromContext(ctx *cli.Context) Network {
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
if ctx.Bool(networkSkipVerifyFlag) {
|
||||
logrus.Warning("ssl verification is turned off")
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Create the context
|
||||
@ -71,7 +77,9 @@ func NetworkFromContext(ctx *cli.Context) Network {
|
||||
}
|
||||
|
||||
return Network{
|
||||
Client: client,
|
||||
Client: &http.Client{
|
||||
Transport: transport,
|
||||
},
|
||||
Context: context,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user