From 7fd1c5b3ccdb43a519d60b2b530f802b838c5d06 Mon Sep 17 00:00:00 2001 From: Adrian Stobbe Date: Fri, 22 Sep 2023 15:55:09 +0200 Subject: [PATCH] fixup! otto feedback --- internal/api/attestationconfigapi/cli/main.go | 13 +++++++------ internal/api/attestationconfigapi/client.go | 2 +- internal/api/attestationconfigapi/reporter.go | 8 -------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/api/attestationconfigapi/cli/main.go b/internal/api/attestationconfigapi/cli/main.go index 8c149ac6eb..9279e068c3 100644 --- a/internal/api/attestationconfigapi/cli/main.go +++ b/internal/api/attestationconfigapi/cli/main.go @@ -37,6 +37,8 @@ const ( distributionID = constants.CDNDefaultDistributionID envCosignPwd = "COSIGN_PASSWORD" envCosignPrivateKey = "COSIGN_PRIVATE_KEY" + // versionWindowSize defines the number of versions to be considered for the latest version. Each week 5 versions are uploaded for each node of the verify cluster. + versionWindowSize = 15 ) var ( @@ -70,7 +72,7 @@ func newRootCmd() *cobra.Command { rootCmd.Flags().StringP("upload-date", "d", "", "upload a version with this date as version name.") rootCmd.Flags().BoolP("force", "f", false, "Use force to manually push a new latest version."+ " The version gets saved to the cache but the version selection logic is skipped.") - rootCmd.Flags().IntP("cache-window-size", "s", 0, "Number of versions to be considered for the latest version.") + rootCmd.Flags().IntP("cache-window-size", "s", versionWindowSize, "Number of versions to be considered for the latest version.") rootCmd.PersistentFlags().StringP("region", "r", awsRegion, "region of the targeted bucket.") rootCmd.PersistentFlags().StringP("bucket", "b", awsBucket, "bucket targeted by all operations.") rootCmd.PersistentFlags().StringP("distribution", "i", distributionID, "cloudflare distribution used.") @@ -115,22 +117,21 @@ func runCmd(cmd *cobra.Command, _ []string) (retErr error) { inputVersion := maaTCB.ToAzureSEVSNPVersion() log.Infof("Input version: %+v", inputVersion) - client, clientClose, err := attestationconfigapi.NewClient(ctx, cfg, []byte(cosignPwd), []byte(privateKey), false, log) + client, clientClose, err := attestationconfigapi.NewClient(ctx, cfg, + []byte(cosignPwd), []byte(privateKey), false, flags.cacheWindowSize, log) defer func() { err := clientClose(cmd.Context()) if err != nil { retErr = errors.Join(retErr, fmt.Errorf("failed to invalidate cache: %w", err)) } }() - if flags.cacheWindowSize != 0 { - client.SetCacheWindowSize(flags.cacheWindowSize) - } if err != nil { return fmt.Errorf("creating client: %w", err) } - latestAPIVersionAPI, err := attestationconfigapi.NewFetcherWithCustomCDN("https://d33dzgxuwsgbpw.cloudfront.net").FetchAzureSEVSNPVersionLatest(ctx) + url := "https://d33dzgxuwsgbpw.cloudfront.net" + latestAPIVersionAPI, err := attestationconfigapi.NewFetcherWithCustomCDN(url).FetchAzureSEVSNPVersionLatest(ctx) if err != nil { if errors.Is(err, attestationconfigapi.ErrNoVersionsFound) && flags.force { log.Infof("No versions found in API, but assuming that we are uploading the first version.\n") diff --git a/internal/api/attestationconfigapi/client.go b/internal/api/attestationconfigapi/client.go index d406a6dbf8..f6ecf96d6f 100644 --- a/internal/api/attestationconfigapi/client.go +++ b/internal/api/attestationconfigapi/client.go @@ -32,7 +32,7 @@ type Client struct { } // NewClient returns a new Client. -func NewClient(ctx context.Context, cfg staticupload.Config, cosignPwd, privateKey []byte, dryRun bool, log *logger.Logger) (*Client, apiclient.CloseFunc, error) { +func NewClient(ctx context.Context, cfg staticupload.Config, cosignPwd, privateKey []byte, dryRun bool, versionWindowSize int, log *logger.Logger) (*Client, apiclient.CloseFunc, error) { s3Client, clientClose, err := apiclient.NewClient(ctx, cfg.Region, cfg.Bucket, cfg.DistributionID, dryRun, log) if err != nil { return nil, nil, fmt.Errorf("failed to create s3 storage: %w", err) diff --git a/internal/api/attestationconfigapi/reporter.go b/internal/api/attestationconfigapi/reporter.go index b8a15c17b2..d9452d7b59 100644 --- a/internal/api/attestationconfigapi/reporter.go +++ b/internal/api/attestationconfigapi/reporter.go @@ -28,9 +28,6 @@ import ( // cachedVersionsSubDir is the subdirectory in the bucket where the cached versions are stored. const cachedVersionsSubDir = "cached-versions" -// versionWindowSize defines the number of versions to be considered for the latest version. Each week 5 versions are uploaded for each node of the verify cluster. -const versionWindowSize = 15 - var reportVersionDir = path.Join(attestationURLPath, variant.AzureSEVSNP{}.String(), cachedVersionsSubDir) // ErrNoNewerVersion is returned if the input version is not newer than the latest API version. @@ -82,11 +79,6 @@ func (c Client) UploadAzureSEVSNPVersionLatest(ctx context.Context, inputVersion return nil } -// SetCacheWindowSize sets a custom number of versions to be considered for the latest version. -func (c *Client) SetCacheWindowSize(size int) { - c.cacheWindowSize = size -} - // cacheAzureSEVSNPVersion uploads the latest observed version numbers of the Azure SEVSNP. This version is used to later report the latest version numbers to the API. func (c Client) cacheAzureSEVSNPVersion(ctx context.Context, version AzureSEVSNPVersion, date time.Time) error { dateStr := date.Format(VersionFormat) + ".json"