mirror of
https://github.com/genuinetools/reg.git
synced 2024-06-30 11:04:16 -04:00
Merge branch 'pr-46'
* pr-46: Add configurable timout for HTTP requests
This commit is contained in:
commit
3198679b1e
|
@ -27,7 +27,7 @@ func Log(format string, args ...interface{}) {
|
|||
}
|
||||
|
||||
// New creates a new Clair struct with the given URL and credentials.
|
||||
func New(url string, debug bool) (*Clair, error) {
|
||||
func New(url string, debug bool, timeout time.Duration) (*Clair, error) {
|
||||
transport := http.DefaultTransport
|
||||
|
||||
errorTransport := &ErrorTransport{
|
||||
|
@ -43,7 +43,7 @@ func New(url string, debug bool) (*Clair, error) {
|
|||
registry := &Clair{
|
||||
URL: url,
|
||||
Client: &http.Client{
|
||||
Timeout: 5 * time.Minute,
|
||||
Timeout: timeout,
|
||||
Transport: errorTransport,
|
||||
},
|
||||
Logf: logf,
|
||||
|
|
5
main.go
5
main.go
|
@ -53,6 +53,11 @@ func main() {
|
|||
Value: repoutils.DefaultDockerRegistry,
|
||||
EnvVar: "REG_REGISTRY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "timeout",
|
||||
Value: "1m",
|
||||
Usage: "timeout for HTTP requests",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-ping",
|
||||
Usage: "skip pinging the registry while establishing connection",
|
||||
|
|
|
@ -115,9 +115,15 @@ func main() {
|
|||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
// parse the timeout
|
||||
timeout, err := time.ParseDuration(c.GlobalString("timeout"))
|
||||
if err != nil {
|
||||
logrus.Fatalf("parsing %s as duration failed: %v", c.GlobalString("timeout"), err)
|
||||
}
|
||||
|
||||
// create a clair instance if needed
|
||||
if c.GlobalString("clair") != "" {
|
||||
cl, err = clair.New(c.GlobalString("clair"), c.GlobalBool("debug"))
|
||||
cl, err = clair.New(c.GlobalString("clair"), c.GlobalBool("debug"), timeout)
|
||||
if err != nil {
|
||||
logrus.Warnf("creation of clair failed: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue