api: rename /api/versions to versionsapi and /api/attestationcfig to attestationconfigapi (#1876)

* rename to attestationconfigapi + put client and fetcher inside pkg

* rename api/version to versionsapi and put fetcher + client inside pkg

* rename AttestationConfigAPIFetcher to Fetcher
This commit is contained in:
Adrian Stobbe 2023-06-07 16:16:32 +02:00 committed by GitHub
parent 25037026e1
commit 4284f892ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
98 changed files with 385 additions and 490 deletions

View file

@ -10,9 +10,7 @@ go_library(
importpath = "github.com/edgelesssys/constellation/v2/hack/configapi/cmd",
visibility = ["//visibility:public"],
deps = [
"//internal/api/attestationconfig",
"//internal/api/attestationconfig/client",
"//internal/api/attestationconfig/fetcher",
"//internal/api/attestationconfigapi",
"//internal/logger",
"//internal/staticupload",
"@com_github_spf13_cobra//:cobra",
@ -28,7 +26,7 @@ go_test(
],
embed = [":cmd"],
deps = [
"//internal/api/attestationconfig",
"//internal/api/attestationconfigapi",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],

View file

@ -9,7 +9,7 @@ import (
"context"
"fmt"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/client"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
"github.com/edgelesssys/constellation/v2/internal/staticupload"
"github.com/spf13/cobra"
)
@ -47,7 +47,7 @@ func runDelete(cmd *cobra.Command, _ []string) error {
Bucket: awsBucket,
Region: awsRegion,
}
repo, closefn, err := client.New(cmd.Context(), cfg, []byte(cosignPwd), []byte(privateKey), false, log())
repo, closefn, err := attestationconfigapi.NewClient(cmd.Context(), cfg, []byte(cosignPwd), []byte(privateKey), false, log())
if err != nil {
return fmt.Errorf("create attestation client: %w", err)
}

View file

@ -13,9 +13,7 @@ import (
"reflect"
"time"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfig"
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/api/attestationconfigapi"
"github.com/edgelesssys/constellation/v2/internal/logger"
"go.uber.org/zap"
@ -82,12 +80,12 @@ func runCmd(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("reading version file: %w", err)
}
var inputVersion attestationconfig.AzureSEVSNPVersion
var inputVersion attestationconfigapi.AzureSEVSNPVersion
if err = json.Unmarshal(versionBytes, &inputVersion); err != nil {
return fmt.Errorf("unmarshalling version file: %w", err)
}
latestAPIVersion, err := attestationconfigapifetcher.New().FetchAzureSEVSNPVersionLatest(ctx)
latestAPIVersion, err := attestationconfigapi.NewFetcher().FetchAzureSEVSNPVersionLatest(ctx)
if err != nil {
return fmt.Errorf("fetching latest version: %w", err)
}
@ -102,7 +100,7 @@ func runCmd(cmd *cobra.Command, _ []string) error {
} 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())
sut, sutClose, err := attestationconfigapi.NewClient(ctx, cfg, []byte(cosignPwd), []byte(privateKey), false, log())
defer func() {
if err := sutClose(ctx); err != nil {
cmd.Printf("closing repo: %v\n", err)
@ -123,7 +121,7 @@ func runCmd(cmd *cobra.Command, _ []string) error {
}
// isInputNewerThanLatestAPI compares all version fields with the latest API version and returns true if any input field is newer.
func isInputNewerThanLatestAPI(input, latest attestationconfig.AzureSEVSNPVersion) (bool, error) {
func isInputNewerThanLatestAPI(input, latest attestationconfigapi.AzureSEVSNPVersion) (bool, error) {
inputValues := reflect.ValueOf(input)
latestValues := reflect.ValueOf(latest)
fields := reflect.TypeOf(input)
@ -166,5 +164,5 @@ func must(err error) {
}
func log() *logger.Logger {
return logger.New(logger.PlainLog, zap.DebugLevel).Named("attestationconfig")
return logger.New(logger.PlainLog, zap.DebugLevel).Named("attestationconfigapi")
}

View file

@ -9,11 +9,11 @@ package cmd
import (
"testing"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfig"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
"github.com/stretchr/testify/assert"
)
var testCfg = attestationconfig.AzureSEVSNPVersion{
var testCfg = attestationconfigapi.AzureSEVSNPVersion{
Microcode: 93,
TEE: 0,
SNP: 6,
@ -22,13 +22,13 @@ var testCfg = attestationconfig.AzureSEVSNPVersion{
func TestIsInputNewerThanLatestAPI(t *testing.T) {
testCases := map[string]struct {
latest attestationconfig.AzureSEVSNPVersion
input attestationconfig.AzureSEVSNPVersion
latest attestationconfigapi.AzureSEVSNPVersion
input attestationconfigapi.AzureSEVSNPVersion
expect bool
errMsg string
}{
"input is older than latest": {
input: func(c attestationconfig.AzureSEVSNPVersion) attestationconfig.AzureSEVSNPVersion {
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
c.Microcode--
return c
}(testCfg),
@ -37,7 +37,7 @@ func TestIsInputNewerThanLatestAPI(t *testing.T) {
errMsg: "input Microcode version: 92 is older than latest API version: 93",
},
"input has greater and smaller version field than latest": {
input: func(c attestationconfig.AzureSEVSNPVersion) attestationconfig.AzureSEVSNPVersion {
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
c.Microcode++
c.Bootloader--
return c
@ -47,7 +47,7 @@ func TestIsInputNewerThanLatestAPI(t *testing.T) {
errMsg: "input Bootloader version: 1 is older than latest API version: 2",
},
"input is newer than latest": {
input: func(c attestationconfig.AzureSEVSNPVersion) attestationconfig.AzureSEVSNPVersion {
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
c.TEE++
return c
}(testCfg),