Skip to content

Commit fcd23dc

Browse files
committed
create fetcher with custom http client and retry options
Signed-off-by: Meredith Lancaster <[email protected]>
1 parent c378b18 commit fcd23dc

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ require (
4848
github.com/spf13/cobra v1.9.1
4949
github.com/spf13/pflag v1.0.6
5050
github.com/stretchr/testify v1.10.0
51+
github.com/theupdateframework/go-tuf/v2 v2.0.2
5152
github.com/zalando/go-keyring v0.2.5
5253
golang.org/x/crypto v0.37.0
5354
golang.org/x/sync v0.13.0
@@ -59,6 +60,8 @@ require (
5960
gopkg.in/yaml.v3 v3.0.1
6061
)
6162

63+
replace github.com/theupdateframework/go-tuf/v2 => github.com/theupdateframework/go-tuf/v2 e9e0d485966d571ea6870670d1e42553f1b3b2db
64+
6265
require (
6366
dario.cat/mergo v1.0.1 // indirect
6467
github.com/Masterminds/goutils v1.1.1 // indirect
@@ -165,7 +168,6 @@ require (
165168
github.com/stretchr/objx v0.5.2 // indirect
166169
github.com/subosito/gotenv v1.6.0 // indirect
167170
github.com/theupdateframework/go-tuf v0.7.0 // indirect
168-
github.com/theupdateframework/go-tuf/v2 v2.0.2 // indirect
169171
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
170172
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
171173
github.com/transparency-dev/merkle v0.0.2 // indirect

pkg/cmd/attestation/verification/sigstore.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/x509"
77
"errors"
88
"fmt"
9+
"net/http"
910
"os"
1011

1112
"github.com/cli/cli/v2/pkg/cmd/attestation/api"
@@ -33,6 +34,7 @@ type SigstoreConfig struct {
3334
TrustedRoot string
3435
Logger *io.Handler
3536
NoPublicGood bool
37+
HttpClient *http.Client
3638
// If tenancy mode is not used, trust domain is empty
3739
TrustDomain string
3840
// TUFMetadataDir
@@ -77,7 +79,7 @@ func NewLiveSigstoreVerifier(config SigstoreConfig) (*LiveSigstoreVerifier, erro
7779
}
7880
liveVerifier.PublicGood = publicGoodVerifier
7981
}
80-
github, err := newGitHubVerifier(config.TrustDomain, config.TUFMetadataDir)
82+
github, err := newGitHubVerifier(config.TrustDomain, config.TUFMetadataDir, config.HttpClient)
8183
if err != nil {
8284
return nil, err
8385
}
@@ -314,10 +316,10 @@ func newCustomVerifier(trustedRoot *root.TrustedRoot) (*verify.SignedEntityVerif
314316
return gv, nil
315317
}
316318

317-
func newGitHubVerifier(trustDomain string, tufMetadataDir o.Option[string]) (*verify.SignedEntityVerifier, error) {
319+
func newGitHubVerifier(trustDomain string, tufMetadataDir o.Option[string], hc *http.Client) (*verify.SignedEntityVerifier, error) {
318320
var tr string
319321

320-
opts := GitHubTUFOptions(tufMetadataDir)
322+
opts := GitHubTUFOptions(tufMetadataDir, hc)
321323
client, err := tuf.New(opts)
322324
if err != nil {
323325
return nil, fmt.Errorf("failed to create TUF client: %v", err)

pkg/cmd/attestation/verification/tuf.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
o "github.com/cli/cli/v2/pkg/option"
99
"github.com/cli/go-gh/v2/pkg/config"
1010
"github.com/sigstore/sigstore-go/pkg/tuf"
11+
"github.com/theupdateframework/go-tuf/v2/metadata/fetcher"
1112
)
1213

1314
//go:embed embed/tuf-repo.github.com/root.json
1415
var githubRoot []byte
1516

1617
const GitHubTUFMirror = "https://tuf-repo.github.com"
1718

18-
func DefaultOptionsWithCacheSetting(tufMetadataDir o.Option[string]) *tuf.Options {
19+
func DefaultOptionsWithCacheSetting(tufMetadataDir o.Option[string], hc *http.Client) *tuf.Options {
1920
opts := tuf.DefaultOptions()
2021

2122
// The CODESPACES environment variable will be set to true in a Codespaces workspace
@@ -32,10 +33,16 @@ func DefaultOptionsWithCacheSetting(tufMetadataDir o.Option[string]) *tuf.Option
3233
// Allow TUF cache for 1 day
3334
opts.CacheValidity = 1
3435

36+
// configure fetcher timeout and retry
37+
f := fetcher.DefaultFetcher{}
38+
f.SetHTTPClient(hc)
39+
retryOptions := []backoff.RetryOption{backoff.WithMaxTries(3)}
40+
f.SetRetryOptions(retryOptions...)
41+
3542
return opts
3643
}
3744

38-
func GitHubTUFOptions(tufMetadataDir o.Option[string]) *tuf.Options {
45+
func GitHubTUFOptions(tufMetadataDir o.Option[string], hc *http.Client) *tuf.Options {
3946
opts := DefaultOptionsWithCacheSetting(tufMetadataDir)
4047

4148
opts.Root = githubRoot

0 commit comments

Comments
 (0)