From 2b7dc3458887374a9da4b3e9647212d870cf69fa Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 17 Sep 2024 17:29:34 -0400 Subject: [PATCH] Remove unused singleton `singletonRootError` was never returned without being overwritten, so it was essentially unused. I think it's wise to always retry the TUF call on future invocations in case of network errors. Signed-off-by: Cody Soyland --- pkg/tuf/repo.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/tuf/repo.go b/pkg/tuf/repo.go index e5230212..b4da37e3 100644 --- a/pkg/tuf/repo.go +++ b/pkg/tuf/repo.go @@ -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. @@ -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) 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