api: use new signature JSON format (#1872)

* use new impl for client.UploadAzureSEVSNP

* fix: fetcher must parse new signature format

* version-file is not persistentflag

* fix fetcher tests
This commit is contained in:
Adrian Stobbe 2023-06-05 16:10:44 +02:00 committed by GitHub
parent fa01569cc6
commit 99a88c033c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 143 deletions

View file

@ -14,8 +14,8 @@ import (
"time"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfig"
attestationconfigclient "github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/client"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/fetcher"
attestationconfigapiclient "github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/client"
attestationconfigapifetcher "github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/fetcher"
"github.com/edgelesssys/constellation/v2/internal/logger"
"go.uber.org/zap"
@ -35,6 +35,7 @@ const (
var (
versionFilePath string
force bool
// Cosign credentials.
cosignPwd string
privateKey string
@ -55,8 +56,9 @@ func newRootCmd() *cobra.Command {
PreRunE: envCheck,
RunE: runCmd,
}
rootCmd.PersistentFlags().StringVarP(&versionFilePath, "version-file", "f", "", "File path to the version json file.")
must(enforcePersistentRequiredFlags(rootCmd, "version-file"))
rootCmd.Flags().StringVarP(&versionFilePath, "version-file", "f", "", "File path to the version json file.")
rootCmd.Flags().BoolVar(&force, "force", false, "force to upload version regardless of comparison to latest API value.")
must(enforceRequiredFlags(rootCmd, "version-file"))
rootCmd.AddCommand(newDeleteCmd())
return rootCmd
}
@ -85,7 +87,7 @@ func runCmd(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("unmarshalling version file: %w", err)
}
latestAPIVersion, err := fetcher.New().FetchAzureSEVSNPVersionLatest(ctx)
latestAPIVersion, err := attestationconfigapifetcher.New().FetchAzureSEVSNPVersionLatest(ctx)
if err != nil {
return fmt.Errorf("fetching latest version: %w", err)
}
@ -94,9 +96,13 @@ func runCmd(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("comparing versions: %w", err)
}
if isNewer {
cmd.Printf("Input version: %+v is newer than latest API version: %+v\n", inputVersion, latestAPIVersion)
sut, sutClose, err := attestationconfigclient.New(ctx, cfg, []byte(cosignPwd), []byte(privateKey), false, log())
if isNewer || force {
if force {
cmd.Println("Forcing upload of new version")
} else {
cmd.Printf("Input version: %+v is newer than latest API version: %+v\n", inputVersion, latestAPIVersion)
}
sut, sutClose, err := attestationconfigapiclient.New(ctx, cfg, []byte(cosignPwd), []byte(privateKey), false, log())
defer func() {
if err := sutClose(ctx); err != nil {
cmd.Printf("closing repo: %v\n", err)
@ -153,15 +159,6 @@ func enforceRequiredFlags(cmd *cobra.Command, flags ...string) error {
return nil
}
func enforcePersistentRequiredFlags(cmd *cobra.Command, flags ...string) error {
for _, flag := range flags {
if err := cmd.MarkPersistentFlagRequired(flag); err != nil {
return err
}
}
return nil
}
func must(err error) {
if err != nil {
panic(err)