Skip to content

Commit c00172e

Browse files
committed
update: add the ability to specify a http-timeout
Previously the timeout was set to 2 mins which is usually plenty for most scenarios but some users want to be able to specify a custom timeout for more latent environments. This adds a --http-timeout flag to the `update` mode and sets it on the client used to request data from security sources. Signed-off-by: crozzy <joseph.crosland@gmail.com>
1 parent 8d04eb4 commit c00172e

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ inputs:
3838
description: 'Vulnerability database file created for mode `update` or DB file used for `report` mode'
3939
required: false
4040
default: ''
41+
updater-timeout:
42+
description: 'The http timeout for the requests made by the database update process'
43+
required: false
44+
default: '120s'
4145

4246
runs:
4347
using: "docker"
@@ -52,3 +56,4 @@ runs:
5256
- '-u ${{ inputs.docker-config-dir }}'
5357
- '-w ${{ inputs.mode }}'
5458
- '-b ${{ inputs.db-file }}'
59+
- '-t ${{ inputs.updater-timeout }}'

cmd/clair-action/update.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
"net/http"
66
"time"
77

8+
"github.com/quay/claircore"
89
"github.com/quay/claircore/libvuln"
10+
"github.com/quay/claircore/libvuln/driver"
11+
"github.com/quay/claircore/rhel/vex"
912
_ "github.com/quay/claircore/updater/defaults"
1013
"github.com/urfave/cli/v2"
1114

@@ -24,19 +27,32 @@ var updateCmd = &cli.Command{
2427
Usage: "where to look for the matcher DB",
2528
EnvVars: []string{"DB_PATH"},
2629
},
30+
&cli.DurationFlag{
31+
Name: "http-timeout",
32+
Value: 2 * time.Minute,
33+
Usage: "the timeout for HTTP requests",
34+
EnvVars: []string{"HTTP_TIMEOUT"},
35+
},
2736
},
2837
}
2938

3039
func update(c *cli.Context) error {
3140
ctx := c.Context
3241
dbPath := c.String("db-path")
42+
httpTimeout := c.Duration("http-timeout")
3343
matcherStore, err := datastore.NewSQLiteMatcherStore(dbPath, true)
3444
if err != nil {
3545
return fmt.Errorf("error creating sqlite backend: %v", err)
3646
}
3747

3848
cl := &http.Client{
39-
Timeout: 2 * time.Minute,
49+
Timeout: httpTimeout,
50+
}
51+
factoryConfigs := make(map[string]driver.ConfigUnmarshaler)
52+
factoryConfigs["rhel-vex"] = func(v interface{}) error {
53+
cfg := v.(*vex.FactoryConfig)
54+
cfg.CompressedFileTimeout = claircore.Duration(httpTimeout)
55+
return nil
4056
}
4157

4258
matcherOpts := &libvuln.Options{
@@ -45,6 +61,7 @@ func update(c *cli.Context) error {
4561
Locker: NewLocalLockSource(),
4662
DisableBackgroundUpdates: true,
4763
UpdateWorkers: 1,
64+
UpdaterConfigs: factoryConfigs,
4865
}
4966

5067
lv, err := libvuln.New(ctx, matcherOpts)

entrypoint.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
while getopts "r:p:f:o:c:d:u:w:b:" o; do
4+
while getopts "r:p:f:o:c:d:u:w:b:t:" o; do
55
case "${o}" in
66
r)
77
export imageRef="$(sed -e 's/^[ \t]*//'<<<"${OPTARG}")"
@@ -30,12 +30,15 @@ while getopts "r:p:f:o:c:d:u:w:b:" o; do
3030
b)
3131
export dbPath="$(sed -e 's/^[ \t]*//'<<<"${OPTARG}")"
3232
;;
33+
t)
34+
export httpTimeout="$(sed -e 's/^[ \t]*//'<<<"${OPTARG}")"
35+
;;
3336
esac
3437
done
3538

3639
if [[ ${mode} = "update" ]]
3740
then
38-
clair-action update --db-path=${dbPath}
41+
clair-action update --db-path=${dbPath} ${httpTimeout:+--http-timeout=${httpTimeout}}
3942
else
4043
clair-action report \
4144
--image-path=${GITHUB_WORKSPACE}/${imagePath} \

0 commit comments

Comments
 (0)