Repository navigation
Add retry logic when fetching TUF content in gh attestation commands
#10943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
malancas
merged 16 commits into
cli:trunk
from
malancas:gh-attestation-tuf-client-retry
May 28, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fcd23dc
create fetcher with custom http client and retry options
malancas c5a2def
Merge branch 'trunk' into gh-attestation-tuf-client-retry
malancas 2b1ec2f
get latest go-tuf version
malancas d606882
get the latest go-tuf release
malancas 6b22675
pass http client for use with tuf
malancas 9092a43
set custom fetcher in options
malancas 874c1b9
fetch http client from factory
malancas 1c28a7a
move live inspect test to integration test file
malancas 456e641
alphabetize fields
malancas ec5f108
simplify test
malancas 3637f5a
add missing http client field in sigstoreConfig
malancas c0701c8
include http client in verifier setup
malancas 75f72bc
use constructor
malancas 3950e84
import sigstore-go at a more recent commit
malancas f2f769c
Merge branch 'trunk' into gh-attestation-tuf-client-retry
malancas 23382f4
Merge branch 'trunk' into gh-attestation-tuf-client-retry
malancas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //go:build integration | ||
|
|
||
| package inspect | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/cli/cli/v2/pkg/cmdutil" | ||
| "github.com/cli/cli/v2/pkg/iostreams" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestNewInspectCmd_PrintOutputJSONFormat(t *testing.T) { | ||
| testIO, _, _, _ := iostreams.Test() | ||
| f := &cmdutil.Factory{ | ||
| IOStreams: testIO, | ||
| HttpClient: func() (*http.Client, error) { | ||
| return http.DefaultClient, nil | ||
| }, | ||
| } | ||
|
|
||
| t.Run("Print output in JSON format", func(t *testing.T) { | ||
| var opts *Options | ||
| cmd := NewInspectCmd(f, func(o *Options) error { | ||
| opts = o | ||
| return nil | ||
| }) | ||
|
|
||
| argv := strings.Split(fmt.Sprintf("%s --format json", bundlePath), " ") | ||
| cmd.SetArgs(argv) | ||
| cmd.SetIn(&bytes.Buffer{}) | ||
| cmd.SetOut(&bytes.Buffer{}) | ||
| cmd.SetErr(&bytes.Buffer{}) | ||
| _, err := cmd.ExecuteC() | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.Equal(t, bundlePath, opts.BundlePath) | ||
| assert.NotNil(t, opts.Logger) | ||
| assert.NotNil(t, opts.exporter) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,7 @@ | ||
| package inspect | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" | ||
|
|
@@ -14,7 +10,6 @@ import ( | |
| "github.com/cli/cli/v2/pkg/cmd/attestation/verification" | ||
| "github.com/cli/cli/v2/pkg/cmdutil" | ||
|
|
||
| "github.com/cli/cli/v2/pkg/httpmock" | ||
| "github.com/cli/cli/v2/pkg/iostreams" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
@@ -26,66 +21,7 @@ const ( | |
| SigstoreSanRegex = "^https://github.com/sigstore/sigstore-js/" | ||
| ) | ||
|
|
||
| var ( | ||
| bundlePath = test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json") | ||
| ) | ||
|
|
||
| func TestNewInspectCmd(t *testing.T) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaned up this test and moved it to |
||
| testIO, _, _, _ := iostreams.Test() | ||
| f := &cmdutil.Factory{ | ||
| IOStreams: testIO, | ||
| HttpClient: func() (*http.Client, error) { | ||
| reg := &httpmock.Registry{} | ||
| client := &http.Client{} | ||
| httpmock.ReplaceTripper(client, reg) | ||
| return client, nil | ||
| }, | ||
| } | ||
|
|
||
| testcases := []struct { | ||
| name string | ||
| cli string | ||
| wants Options | ||
| wantsErr bool | ||
| wantsExporter bool | ||
| }{ | ||
| { | ||
| name: "Prints output in JSON format", | ||
| cli: fmt.Sprintf("%s --format json", bundlePath), | ||
| wants: Options{ | ||
| BundlePath: bundlePath, | ||
| SigstoreVerifier: verification.NewMockSigstoreVerifier(t), | ||
| }, | ||
| wantsExporter: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testcases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| var opts *Options | ||
| cmd := NewInspectCmd(f, func(o *Options) error { | ||
| opts = o | ||
| return nil | ||
| }) | ||
|
|
||
| argv := strings.Split(tc.cli, " ") | ||
| cmd.SetArgs(argv) | ||
| cmd.SetIn(&bytes.Buffer{}) | ||
| cmd.SetOut(&bytes.Buffer{}) | ||
| cmd.SetErr(&bytes.Buffer{}) | ||
| _, err := cmd.ExecuteC() | ||
| if tc.wantsErr { | ||
| assert.Error(t, err) | ||
| return | ||
| } | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.Equal(t, tc.wants.BundlePath, opts.BundlePath) | ||
| assert.NotNil(t, opts.Logger) | ||
| assert.Equal(t, tc.wantsExporter, opts.exporter != nil) | ||
| }) | ||
| } | ||
| } | ||
| var bundlePath = test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json") | ||
|
|
||
| func TestRunInspect(t *testing.T) { | ||
| opts := Options{ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if actually we need both of these