mirror of
https://github.com/mayflower/docker-ls.git
synced 2025-11-28 00:01:09 +03:00
Add an option for ignoring SSL cert errors.
This commit is contained in:
@@ -34,6 +34,7 @@ type Config struct {
|
|||||||
pageSize uint
|
pageSize uint
|
||||||
maxConcurrentRequests uint
|
maxConcurrentRequests uint
|
||||||
basicAuth bool
|
basicAuth bool
|
||||||
|
allowInsecure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *urlValue) String() string {
|
func (u *urlValue) String() string {
|
||||||
@@ -47,6 +48,7 @@ func (c *Config) BindToFlags(flags *flag.FlagSet) {
|
|||||||
flags.UintVar(&c.pageSize, "page-size", c.pageSize, "page size for paginated requests")
|
flags.UintVar(&c.pageSize, "page-size", c.pageSize, "page size for paginated requests")
|
||||||
flags.UintVar(&c.maxConcurrentRequests, "max-requests", c.maxConcurrentRequests, "concurrent API request limit")
|
flags.UintVar(&c.maxConcurrentRequests, "max-requests", c.maxConcurrentRequests, "concurrent API request limit")
|
||||||
flags.BoolVar(&c.basicAuth, "basic-auth", c.basicAuth, "use basic auth instead of token auth")
|
flags.BoolVar(&c.basicAuth, "basic-auth", c.basicAuth, "use basic auth instead of token auth")
|
||||||
|
flags.BoolVar(&c.allowInsecure, "allow-insecure", c.allowInsecure, "ignore SSL certificate validation errors")
|
||||||
|
|
||||||
c.credentials.BindToFlags(flags)
|
c.credentials.BindToFlags(flags)
|
||||||
}
|
}
|
||||||
@@ -59,6 +61,10 @@ func (c *Config) Credentials() auth.RegistryCredentials {
|
|||||||
return &c.credentials
|
return &c.credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) AllowInsecure() bool {
|
||||||
|
return c.allowInsecure
|
||||||
|
}
|
||||||
|
|
||||||
func NewConfig() Config {
|
func NewConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
registryUrl: DEFAULT_REGISTRY_URL,
|
registryUrl: DEFAULT_REGISTRY_URL,
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (r *basicAuthConnector) Request(method string, url *url.URL, hint string) (
|
|||||||
func NewBasicAuthConnector(cfg Config) Connector {
|
func NewBasicAuthConnector(cfg Config) Connector {
|
||||||
return &basicAuthConnector{
|
return &basicAuthConnector{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
httpClient: http.DefaultClient,
|
httpClient: createHttpClient(cfg),
|
||||||
semaphore: newSemaphore(cfg.MaxConcurrentRequests()),
|
semaphore: newSemaphore(cfg.MaxConcurrentRequests()),
|
||||||
stat: new(statistics),
|
stat: new(statistics),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ import (
|
|||||||
type Config interface {
|
type Config interface {
|
||||||
MaxConcurrentRequests() uint
|
MaxConcurrentRequests() uint
|
||||||
Credentials() auth.RegistryCredentials
|
Credentials() auth.RegistryCredentials
|
||||||
|
AllowInsecure() bool
|
||||||
}
|
}
|
||||||
21
lib/connector/http_client_factory.go
Normal file
21
lib/connector/http_client_factory.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createHttpClient(cfg Config) *http.Client {
|
||||||
|
var tlsConfig *tls.Config
|
||||||
|
if cfg.AllowInsecure() {
|
||||||
|
tlsConfig = &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,7 +124,7 @@ func (r *tokenAuthConnector) GetStatistics() Statistics {
|
|||||||
func NewTokenAuthConnector(cfg Config) Connector {
|
func NewTokenAuthConnector(cfg Config) Connector {
|
||||||
connector := tokenAuthConnector{
|
connector := tokenAuthConnector{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
httpClient: http.DefaultClient,
|
httpClient: createHttpClient(cfg),
|
||||||
semaphore: newSemaphore(cfg.MaxConcurrentRequests()),
|
semaphore: newSemaphore(cfg.MaxConcurrentRequests()),
|
||||||
tokenCache: newTokenCache(),
|
tokenCache: newTokenCache(),
|
||||||
stat: new(statistics),
|
stat: new(statistics),
|
||||||
|
|||||||
Reference in New Issue
Block a user