mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-25 17:21:24 -05:00
use variant interface instead of fmt.Stringer
This commit is contained in:
parent
d094d80807
commit
2d19273797
@ -18,9 +18,31 @@ import (
|
|||||||
|
|
||||||
const cosignPublicKey = constants.CosignPublicKeyReleases
|
const cosignPublicKey = constants.CosignPublicKeyReleases
|
||||||
|
|
||||||
|
var (
|
||||||
|
// AzureSEVSNP is the Azure SEV-SNP variant.
|
||||||
|
AzureSEVSNP Variant = attestationVariant{variant: variant.AzureSEVSNP{}}
|
||||||
|
// AWSSEVSNP is the AWS SEV-SNP variant.
|
||||||
|
AWSSEVSNP Variant = attestationVariant{variant: variant.AWSSEVSNP{}}
|
||||||
|
// GCPSEVSNP is the GCP SEV-SNP variant.
|
||||||
|
GCPSEVSNP Variant = attestationVariant{variant: variant.GCPSEVSNP{}}
|
||||||
|
)
|
||||||
|
|
||||||
|
type attestationVariant struct {
|
||||||
|
variant Variant
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v attestationVariant) String() string {
|
||||||
|
return v.variant.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variant is a cloud provider specific attestation variant.
|
||||||
|
type Variant interface {
|
||||||
|
String() string
|
||||||
|
}
|
||||||
|
|
||||||
// Fetcher fetches config API resources without authentication.
|
// Fetcher fetches config API resources without authentication.
|
||||||
type Fetcher interface {
|
type Fetcher interface {
|
||||||
FetchLatestVersion(ctx context.Context, attestation fmt.Stringer) (Entry, error)
|
FetchLatestVersion(ctx context.Context, attestation Variant) (Entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetcher fetches AttestationCfg API resources without authentication.
|
// fetcher fetches AttestationCfg API resources without authentication.
|
||||||
@ -60,7 +82,7 @@ func newFetcherWithClientAndVerifier(client apifetcher.HTTPClient, cosignVerifie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FetchLatestVersion returns the latest versions of the given type.
|
// FetchLatestVersion returns the latest versions of the given type.
|
||||||
func (f *fetcher) FetchLatestVersion(ctx context.Context, variant fmt.Stringer) (Entry, error) {
|
func (f *fetcher) FetchLatestVersion(ctx context.Context, variant Variant) (Entry, error) {
|
||||||
list, err := f.fetchVersionList(ctx, variant)
|
list, err := f.fetchVersionList(ctx, variant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Entry{}, err
|
return Entry{}, err
|
||||||
@ -71,7 +93,7 @@ func (f *fetcher) FetchLatestVersion(ctx context.Context, variant fmt.Stringer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchVersionList fetches the version list information from the config API.
|
// fetchVersionList fetches the version list information from the config API.
|
||||||
func (f *fetcher) fetchVersionList(ctx context.Context, attestationVariant fmt.Stringer) (List, error) {
|
func (f *fetcher) fetchVersionList(ctx context.Context, attestationVariant Variant) (List, error) {
|
||||||
parsedVariant, err := variant.FromString(attestationVariant.String())
|
parsedVariant, err := variant.FromString(attestationVariant.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return List{}, fmt.Errorf("parsing variant: %w", err)
|
return List{}, fmt.Errorf("parsing variant: %w", err)
|
||||||
@ -88,7 +110,7 @@ func (f *fetcher) fetchVersionList(ctx context.Context, attestationVariant fmt.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchVersion fetches the version information from the config API.
|
// fetchVersion fetches the version information from the config API.
|
||||||
func (f *fetcher) fetchVersion(ctx context.Context, version string, attestationVariant fmt.Stringer) (Entry, error) {
|
func (f *fetcher) fetchVersion(ctx context.Context, version string, attestationVariant Variant) (Entry, error) {
|
||||||
parsedVariant, err := variant.FromString(attestationVariant.String())
|
parsedVariant, err := variant.FromString(attestationVariant.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Entry{}, fmt.Errorf("parsing variant: %w", err)
|
return Entry{}, fmt.Errorf("parsing variant: %w", err)
|
||||||
|
@ -8,7 +8,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
@ -205,7 +204,7 @@ func (f stubVerifyFetcher) FetchAndVerifyMeasurements(_ context.Context, _ strin
|
|||||||
|
|
||||||
type stubAttestationFetcher struct{}
|
type stubAttestationFetcher struct{}
|
||||||
|
|
||||||
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ fmt.Stringer) (attestationconfigapi.Entry, error) {
|
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ attestationconfigapi.Variant) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{
|
return attestationconfigapi.Entry{
|
||||||
SEVSNPVersion: testCfg,
|
SEVSNPVersion: testCfg,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -7,7 +7,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -171,6 +170,6 @@ type stubConfigFetcher struct {
|
|||||||
fetchLatestErr error
|
fetchLatestErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubConfigFetcher) FetchLatestVersion(context.Context, fmt.Stringer) (attestationconfigapi.Entry, error) {
|
func (s *stubConfigFetcher) FetchLatestVersion(context.Context, attestationconfigapi.Variant) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{}, s.fetchLatestErr
|
return attestationconfigapi.Entry{}, s.fetchLatestErr
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -1052,7 +1051,7 @@ func getConfigAsMap(conf *Config, t *testing.T) (res configMap) {
|
|||||||
|
|
||||||
type stubAttestationFetcher struct{}
|
type stubAttestationFetcher struct{}
|
||||||
|
|
||||||
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ fmt.Stringer) (attestationconfigapi.Entry, error) {
|
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ attestationconfigapi.Variant) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{
|
return attestationconfigapi.Entry{
|
||||||
SEVSNPVersion: testCfg,
|
SEVSNPVersion: testCfg,
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user