mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-13 01:44:22 -05:00
weaken interface
This commit is contained in:
parent
665cff0071
commit
3b416224ca
@ -8,6 +8,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
@ -204,7 +205,7 @@ func (f stubVerifyFetcher) FetchAndVerifyMeasurements(_ context.Context, _ strin
|
|||||||
|
|
||||||
type stubAttestationFetcher struct{}
|
type stubAttestationFetcher struct{}
|
||||||
|
|
||||||
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ variant.Variant) (attestationconfigapi.Entry, error) {
|
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ fmt.Stringer) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{
|
return attestationconfigapi.Entry{
|
||||||
SEVSNPVersion: testCfg,
|
SEVSNPVersion: testCfg,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -7,6 +7,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -14,7 +15,6 @@ import (
|
|||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/cli/internal/terraform"
|
"github.com/edgelesssys/constellation/v2/cli/internal/terraform"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
|
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
@ -171,6 +171,6 @@ type stubConfigFetcher struct {
|
|||||||
fetchLatestErr error
|
fetchLatestErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubConfigFetcher) FetchLatestVersion(context.Context, variant.Variant) (attestationconfigapi.Entry, error) {
|
func (s *stubConfigFetcher) FetchLatestVersion(context.Context, fmt.Stringer) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{}, s.fetchLatestErr
|
return attestationconfigapi.Entry{}, s.fetchLatestErr
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ const cosignPublicKey = constants.CosignPublicKeyReleases
|
|||||||
|
|
||||||
// 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 variant.Variant) (Entry, error)
|
FetchLatestVersion(ctx context.Context, attestation fmt.Stringer) (Entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetcher fetches AttestationCfg API resources without authentication.
|
// fetcher fetches AttestationCfg API resources without authentication.
|
||||||
@ -60,7 +60,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 variant.Variant) (Entry, error) {
|
func (f *fetcher) FetchLatestVersion(ctx context.Context, variant fmt.Stringer) (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,23 +71,31 @@ func (f *fetcher) FetchLatestVersion(ctx context.Context, variant variant.Varian
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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, variant variant.Variant) (List, error) {
|
func (f *fetcher) fetchVersionList(ctx context.Context, attestationVariant fmt.Stringer) (List, error) {
|
||||||
fetchedList, err := apifetcher.FetchAndVerify(ctx, f.HTTPClient, f.cdnURL, List{Variant: variant}, f.verifier)
|
parsedVariant, err := variant.FromString(attestationVariant.String())
|
||||||
|
if err != nil {
|
||||||
|
return List{}, fmt.Errorf("parsing variant: %w", err)
|
||||||
|
}
|
||||||
|
fetchedList, err := apifetcher.FetchAndVerify(ctx, f.HTTPClient, f.cdnURL, List{Variant: parsedVariant}, f.verifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return List{}, fmt.Errorf("fetching version list: %w", err)
|
return List{}, fmt.Errorf("fetching version list: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the attestation variant of the list as it is not part of the marshalled JSON retrieved by Fetch
|
// Set the attestation variant of the list as it is not part of the marshalled JSON retrieved by Fetch
|
||||||
fetchedList.Variant = variant
|
fetchedList.Variant = parsedVariant
|
||||||
|
|
||||||
return fetchedList, nil
|
return fetchedList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, variant variant.Variant) (Entry, error) {
|
func (f *fetcher) fetchVersion(ctx context.Context, version string, attestationVariant fmt.Stringer) (Entry, error) {
|
||||||
|
parsedVariant, err := variant.FromString(attestationVariant.String())
|
||||||
|
if err != nil {
|
||||||
|
return Entry{}, fmt.Errorf("parsing variant: %w", err)
|
||||||
|
}
|
||||||
obj := Entry{
|
obj := Entry{
|
||||||
Version: version,
|
Version: version,
|
||||||
Variant: variant,
|
Variant: parsedVariant,
|
||||||
}
|
}
|
||||||
fetchedVersion, err := apifetcher.FetchAndVerify(ctx, f.HTTPClient, f.cdnURL, obj, f.verifier)
|
fetchedVersion, err := apifetcher.FetchAndVerify(ctx, f.HTTPClient, f.cdnURL, obj, f.verifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,7 +103,7 @@ func (f *fetcher) fetchVersion(ctx context.Context, version string, variant vari
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the attestation variant of the list as it is not part of the marshalled JSON retrieved by FetchAndVerify
|
// Set the attestation variant of the list as it is not part of the marshalled JSON retrieved by FetchAndVerify
|
||||||
fetchedVersion.Variant = variant
|
fetchedVersion.Variant = parsedVariant
|
||||||
|
|
||||||
return fetchedVersion, nil
|
return fetchedVersion, nil
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -1051,7 +1052,7 @@ func getConfigAsMap(conf *Config, t *testing.T) (res configMap) {
|
|||||||
|
|
||||||
type stubAttestationFetcher struct{}
|
type stubAttestationFetcher struct{}
|
||||||
|
|
||||||
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ variant.Variant) (attestationconfigapi.Entry, error) {
|
func (f stubAttestationFetcher) FetchLatestVersion(_ context.Context, _ fmt.Stringer) (attestationconfigapi.Entry, error) {
|
||||||
return attestationconfigapi.Entry{
|
return attestationconfigapi.Entry{
|
||||||
SEVSNPVersion: testCfg,
|
SEVSNPVersion: testCfg,
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user