mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-22 14:04:53 -04:00
versionsapi: replace shortname pkg
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
f17b40b44a
commit
66f2c446a4
6 changed files with 27 additions and 168 deletions
|
@ -20,8 +20,8 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/edgelesssys/constellation/v2/internal/shortname"
|
||||
"github.com/edgelesssys/constellation/v2/internal/sigstore"
|
||||
"github.com/edgelesssys/constellation/v2/internal/versionsapi"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -187,14 +187,15 @@ func (f *fetchMeasurementsFlags) updateURLs(conf *config.Config) error {
|
|||
}
|
||||
|
||||
func measurementURL(provider cloudprovider.Provider, image, file string) (*url.URL, error) {
|
||||
ref, stream, version, err := shortname.ToParts(image)
|
||||
ver, err := versionsapi.NewVersionFromShortPath(image, versionsapi.VersionKindImage)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing image name: %w", err)
|
||||
return nil, fmt.Errorf("creating version from image name: %w", err)
|
||||
}
|
||||
url, err := url.Parse(constants.CDNRepositoryURL)
|
||||
artifactBaseURL := ver.ArtifactURL()
|
||||
url, err := url.Parse(artifactBaseURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing image version repository URL: %w", err)
|
||||
return nil, fmt.Errorf("parsing artifact base URL %s: %w", artifactBaseURL, err)
|
||||
}
|
||||
url.Path = path.Join(constants.CDNAPIPrefix, "ref", ref, "stream", stream, version, "image", "csp", strings.ToLower(provider.String()), file)
|
||||
url.Path = path.Join(url.Path, "image", "csp", strings.ToLower(provider.String()), file)
|
||||
return url, nil
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/edgelesssys/constellation/v2/internal/versionsapi"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -96,6 +97,12 @@ func TestParseFetchMeasurementsFlags(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateURLs(t *testing.T) {
|
||||
ver := versionsapi.Version{
|
||||
Ref: "foo",
|
||||
Stream: "nightly",
|
||||
Version: "v7.7.7",
|
||||
Kind: versionsapi.VersionKindImage,
|
||||
}
|
||||
testCases := map[string]struct {
|
||||
conf *config.Config
|
||||
flags *fetchMeasurementsFlags
|
||||
|
@ -104,14 +111,14 @@ func TestUpdateURLs(t *testing.T) {
|
|||
}{
|
||||
"both values nil": {
|
||||
conf: &config.Config{
|
||||
Image: "someImageVersion",
|
||||
Image: ver.ShortPath(),
|
||||
Provider: config.ProviderConfig{
|
||||
GCP: &config.GCPConfig{},
|
||||
},
|
||||
},
|
||||
flags: &fetchMeasurementsFlags{},
|
||||
wantMeasurementsURL: constants.CDNRepositoryURL + "/" + constants.CDNAPIPrefix + "/ref/-/stream/stable/someImageVersion/image/csp/gcp/measurements.json",
|
||||
wantMeasurementsSigURL: constants.CDNRepositoryURL + "/" + constants.CDNAPIPrefix + "/ref/-/stream/stable/someImageVersion/image/csp/gcp/measurements.json.sig",
|
||||
wantMeasurementsURL: ver.ArtifactURL() + "/image/csp/gcp/measurements.json",
|
||||
wantMeasurementsSigURL: ver.ArtifactURL() + "/image/csp/gcp/measurements.json.sig",
|
||||
},
|
||||
"both set by user": {
|
||||
conf: &config.Config{},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue