mirror of
https://github.com/thegeeklab/drone-plugin-lib.git
synced 2024-11-22 00:40:39 +00:00
Add SSL skip verify flag
This commit is contained in:
parent
537cb2c489
commit
0324ae7edb
@ -7,6 +7,7 @@ package urfave
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -31,15 +32,15 @@ type Network struct {
|
|||||||
Client *http.Client
|
Client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
const networkSSLVerifyFlag = "transport.ssl-verify"
|
const networkSkipVerifyFlag = "transport.skip-verify"
|
||||||
|
|
||||||
// networkFlags has the cli.Flags for the Transport.
|
// networkFlags has the cli.Flags for the Transport.
|
||||||
func networkFlags() []cli.Flag {
|
func networkFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
cli.BoolFlag{
|
cli.BoolTFlag{
|
||||||
Name: networkSSLVerifyFlag,
|
Name: networkSkipVerifyFlag,
|
||||||
Usage: "transport ssl verify",
|
Usage: "skip ssl verify",
|
||||||
EnvVar: "PLUGIN_SSL_VERIFY",
|
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,20 +48,25 @@ func networkFlags() []cli.Flag {
|
|||||||
// NetworkFromContext creates a Transport from the cli.Context.
|
// NetworkFromContext creates a Transport from the cli.Context.
|
||||||
func NetworkFromContext(ctx *cli.Context) Network {
|
func NetworkFromContext(ctx *cli.Context) Network {
|
||||||
// Create the client
|
// Create the client
|
||||||
client := &http.Client{
|
transport := &http.Transport{
|
||||||
Transport: &http.Transport{
|
Proxy: http.ProxyFromEnvironment,
|
||||||
Proxy: http.ProxyFromEnvironment,
|
DialContext: (&net.Dialer{
|
||||||
DialContext: (&net.Dialer{
|
Timeout: 30 * time.Second,
|
||||||
Timeout: 30 * time.Second,
|
KeepAlive: 30 * time.Second,
|
||||||
KeepAlive: 30 * time.Second,
|
DualStack: true,
|
||||||
DualStack: true,
|
}).DialContext,
|
||||||
}).DialContext,
|
ForceAttemptHTTP2: true,
|
||||||
ForceAttemptHTTP2: true,
|
MaxIdleConns: 100,
|
||||||
MaxIdleConns: 100,
|
IdleConnTimeout: 90 * time.Second,
|
||||||
IdleConnTimeout: 90 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
ExpectContinueTimeout: 1 * 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
|
// Create the context
|
||||||
@ -71,7 +77,9 @@ func NetworkFromContext(ctx *cli.Context) Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Network{
|
return Network{
|
||||||
Client: client,
|
Client: &http.Client{
|
||||||
|
Transport: transport,
|
||||||
|
},
|
||||||
Context: context,
|
Context: context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user