Skip to content
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

Fix shadowed trustedroot #178

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions pkg/tuf/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,9 @@ func ClientFromRemote(_ context.Context, mirror string, rootJSON []byte, targets
}

var (
mu sync.RWMutex
singletonRootError error
timestamp time.Time
trustedRoot *root.TrustedRoot
mu sync.RWMutex
timestamp time.Time
trustedRoot *root.TrustedRoot
)

// GetTrustedRoot returns the trusted root for the TUF repository.
Expand All @@ -311,19 +310,16 @@ func GetTrustedRoot(ctx context.Context) (*root.TrustedRoot, error) {

tufClient, err := tuf.NewFromEnv(context.Background())
if err != nil {
singletonRootError = fmt.Errorf("initializing tuf: %w", err)
return nil, singletonRootError
return nil, fmt.Errorf("initializing tuf: %w", err)
}
// TODO: add support for custom trusted root path
targetBytes, err := tufClient.GetTarget("trusted_root.json")
if err != nil {
singletonRootError = fmt.Errorf("error getting targets: %w", err)
return nil, singletonRootError
return nil, fmt.Errorf("error getting targets: %w", err)
}
trustedRoot, err := root.NewTrustedRootFromJSON(targetBytes)
trustedRoot, err = root.NewTrustedRootFromJSON(targetBytes)
if err != nil {
singletonRootError = fmt.Errorf("error creating trusted root: %w", err)
return nil, singletonRootError
return nil, fmt.Errorf("error creating trusted root: %w", err)
}

timestamp = now
Expand Down
Loading