mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-07 06:22:17 -04:00
api: add functions to transparently handle signatures upon API interaction (#2142)
This commit is contained in:
parent
002c3a9a32
commit
dac690656e
45 changed files with 707 additions and 472 deletions
|
@ -61,14 +61,9 @@ func runAdd(cmd *cobra.Command, _ []string) (retErr error) {
|
|||
}
|
||||
|
||||
log.Debugf("Creating version struct")
|
||||
ver := versionsapi.Version{
|
||||
Ref: flags.ref,
|
||||
Stream: flags.stream,
|
||||
Version: flags.version,
|
||||
Kind: flags.kind,
|
||||
}
|
||||
if err := ver.Validate(); err != nil {
|
||||
return err
|
||||
ver, err := versionsapi.NewVersion(flags.ref, flags.stream, flags.version, flags.kind)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating version: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf("Creating versions API client")
|
||||
|
@ -108,8 +103,8 @@ func ensureVersion(ctx context.Context, client *versionsapi.Client, kind version
|
|||
log *logger.Logger,
|
||||
) error {
|
||||
verListReq := versionsapi.List{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Ref: ver.Ref(),
|
||||
Stream: ver.Stream(),
|
||||
Granularity: gran,
|
||||
Base: ver.WithGranularity(gran),
|
||||
Kind: kind,
|
||||
|
@ -146,28 +141,28 @@ func ensureVersion(ctx context.Context, client *versionsapi.Client, kind version
|
|||
|
||||
func updateLatest(ctx context.Context, client *versionsapi.Client, kind versionsapi.VersionKind, ver versionsapi.Version, log *logger.Logger) error {
|
||||
latest := versionsapi.Latest{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Ref: ver.Ref(),
|
||||
Stream: ver.Stream(),
|
||||
Kind: kind,
|
||||
}
|
||||
latest, err := client.FetchVersionLatest(ctx, latest)
|
||||
var notFoundErr *apiclient.NotFoundError
|
||||
if errors.As(err, ¬FoundErr) {
|
||||
log.Debugf("Latest version for ref %q and stream %q not found", ver.Ref, ver.Stream)
|
||||
log.Debugf("Latest version for ref %q and stream %q not found", ver.Ref(), ver.Stream())
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("fetching latest version: %w", err)
|
||||
}
|
||||
|
||||
if latest.Version == ver.Version {
|
||||
if latest.Version == ver.Version() {
|
||||
log.Infof("Version %q is already latest version", ver)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Infof("Setting %q as latest version", ver)
|
||||
latest = versionsapi.Latest{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Version: ver.Version,
|
||||
Ref: ver.Ref(),
|
||||
Stream: ver.Stream(),
|
||||
Version: ver.Version(),
|
||||
Kind: kind,
|
||||
}
|
||||
if err := client.UpdateVersionLatest(ctx, latest); err != nil {
|
||||
|
|
|
@ -91,7 +91,7 @@ func runList(cmd *cobra.Command, _ []string) error {
|
|||
log.Debugf("Printing versions as JSON")
|
||||
var vers []string
|
||||
for _, v := range patchVersions {
|
||||
vers = append(vers, v.Version)
|
||||
vers = append(vers, v.Version())
|
||||
}
|
||||
raw, err := json.Marshal(vers)
|
||||
if err != nil {
|
||||
|
|
|
@ -181,7 +181,7 @@ func deleteRef(ctx context.Context, clients rmImageClients, ref string, dryrun b
|
|||
|
||||
for _, ver := range vers {
|
||||
if err := deleteImage(ctx, clients, ver, dryrun, log); err != nil {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("deleting images for version %s: %w", ver.Version, err))
|
||||
retErr = errors.Join(retErr, fmt.Errorf("deleting images for version %s: %w", ver.Version(), err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,9 +197,9 @@ func deleteImage(ctx context.Context, clients rmImageClients, ver versionsapi.Ve
|
|||
var retErr error
|
||||
|
||||
imageInfo := versionsapi.ImageInfo{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Version: ver.Version,
|
||||
Ref: ver.Ref(),
|
||||
Stream: ver.Stream(),
|
||||
Version: ver.Version(),
|
||||
}
|
||||
imageInfo, err := clients.version.FetchImageInfo(ctx, imageInfo)
|
||||
var notFound *apiclient.NotFoundError
|
||||
|
@ -291,14 +291,9 @@ func (f *rmFlags) validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
ver := versionsapi.Version{
|
||||
Ref: f.ref,
|
||||
Stream: f.stream,
|
||||
Version: f.version,
|
||||
Kind: versionsapi.VersionKindImage,
|
||||
}
|
||||
if err := ver.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid version: %w", err)
|
||||
ver, err := versionsapi.NewVersion(f.ref, f.stream, f.version, versionsapi.VersionKindImage)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating version: %w", err)
|
||||
}
|
||||
f.ver = ver
|
||||
|
||||
|
|
|
@ -131,18 +131,18 @@ func (c *Client) DeleteRef(ctx context.Context, ref string) error {
|
|||
func (c *Client) DeleteVersion(ctx context.Context, ver Version) error {
|
||||
var retErr error
|
||||
|
||||
c.Client.Log.Debugf("Deleting version %s from minor version list", ver.Version)
|
||||
c.Client.Log.Debugf("Deleting version %s from minor version list", ver.version)
|
||||
possibleNewLatest, err := c.deleteVersionFromMinorVersionList(ctx, ver)
|
||||
if err != nil {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("removing from minor version list: %w", err))
|
||||
}
|
||||
|
||||
c.Client.Log.Debugf("Checking latest version for %s", ver.Version)
|
||||
c.Client.Log.Debugf("Checking latest version for %s", ver.version)
|
||||
if err := c.deleteVersionFromLatest(ctx, ver, possibleNewLatest); err != nil {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("updating latest version: %w", err))
|
||||
}
|
||||
|
||||
c.Client.Log.Debugf("Deleting artifact path %s for %s", ver.ArtifactPath(APIV1), ver.Version)
|
||||
c.Client.Log.Debugf("Deleting artifact path %s for %s", ver.ArtifactPath(APIV1), ver.version)
|
||||
if err := c.Client.DeletePath(ctx, ver.ArtifactPath(APIV1)); err != nil {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("deleting artifact path: %w", err))
|
||||
}
|
||||
|
@ -153,32 +153,32 @@ func (c *Client) DeleteVersion(ctx context.Context, ver Version) error {
|
|||
func (c *Client) deleteVersionFromMinorVersionList(ctx context.Context, ver Version,
|
||||
) (*Latest, error) {
|
||||
minorList := List{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Ref: ver.ref,
|
||||
Stream: ver.stream,
|
||||
Granularity: GranularityMinor,
|
||||
Base: ver.WithGranularity(GranularityMinor),
|
||||
Kind: VersionKindImage,
|
||||
}
|
||||
c.Client.Log.Debugf("Fetching minor version list for version %s", ver.Version)
|
||||
c.Client.Log.Debugf("Fetching minor version list for version %s", ver.version)
|
||||
minorList, err := c.FetchVersionList(ctx, minorList)
|
||||
var notFoundErr *apiclient.NotFoundError
|
||||
if errors.As(err, ¬FoundErr) {
|
||||
c.Client.Log.Warnf("Minor version list for version %s not found", ver.Version)
|
||||
c.Client.Log.Warnf("Minor version list for version %s not found", ver.version)
|
||||
c.Client.Log.Warnf("Skipping update of minor version list")
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("fetching minor version list for version %s: %w", ver.Version, err)
|
||||
return nil, fmt.Errorf("fetching minor version list for version %s: %w", ver.version, err)
|
||||
}
|
||||
|
||||
if !minorList.Contains(ver.Version) {
|
||||
c.Client.Log.Warnf("Version %s is not in minor version list %s", ver.Version, minorList.JSONPath())
|
||||
if !minorList.Contains(ver.version) {
|
||||
c.Client.Log.Warnf("Version %s is not in minor version list %s", ver.version, minorList.JSONPath())
|
||||
c.Client.Log.Warnf("Skipping update of minor version list")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
semver.Sort(minorList.Versions)
|
||||
for i, v := range minorList.Versions {
|
||||
if v == ver.Version {
|
||||
if v == ver.version {
|
||||
minorList.Versions = append(minorList.Versions[:i], minorList.Versions[i+1:]...)
|
||||
break
|
||||
}
|
||||
|
@ -187,8 +187,8 @@ func (c *Client) deleteVersionFromMinorVersionList(ctx context.Context, ver Vers
|
|||
var latest *Latest
|
||||
if len(minorList.Versions) != 0 {
|
||||
latest = &Latest{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Ref: ver.ref,
|
||||
Stream: ver.stream,
|
||||
Kind: VersionKindImage,
|
||||
Version: minorList.Versions[len(minorList.Versions)-1],
|
||||
}
|
||||
|
@ -205,15 +205,15 @@ func (c *Client) deleteVersionFromMinorVersionList(ctx context.Context, ver Vers
|
|||
return latest, fmt.Errorf("updating minor version list %s: %w", minorList.JSONPath(), err)
|
||||
}
|
||||
|
||||
c.Client.Log.Debugf("Removed version %s from minor version list %s", ver.Version, minorList.JSONPath())
|
||||
c.Client.Log.Debugf("Removed version %s from minor version list %s", ver.version, minorList.JSONPath())
|
||||
return latest, nil
|
||||
}
|
||||
|
||||
func (c *Client) deleteVersionFromLatest(ctx context.Context, ver Version, possibleNewLatest *Latest,
|
||||
) error {
|
||||
latest := Latest{
|
||||
Ref: ver.Ref,
|
||||
Stream: ver.Stream,
|
||||
Ref: ver.ref,
|
||||
Stream: ver.stream,
|
||||
Kind: VersionKindImage,
|
||||
}
|
||||
c.Client.Log.Debugf("Fetching latest version from %s", latest.JSONPath())
|
||||
|
@ -226,8 +226,8 @@ func (c *Client) deleteVersionFromLatest(ctx context.Context, ver Version, possi
|
|||
return fmt.Errorf("fetching latest version: %w", err)
|
||||
}
|
||||
|
||||
if latest.Version != ver.Version {
|
||||
c.Client.Log.Debugf("Latest version is %s, not the deleted version %s", latest.Version, ver.Version)
|
||||
if latest.Version != ver.version {
|
||||
c.Client.Log.Debugf("Latest version is %s, not the deleted version %s", latest.Version, ver.version)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -163,10 +163,10 @@ func (l List) StructuredVersions() []Version {
|
|||
versions := make([]Version, len(l.Versions))
|
||||
for i, v := range l.Versions {
|
||||
versions[i] = Version{
|
||||
Ref: l.Ref,
|
||||
Stream: l.Stream,
|
||||
Version: v,
|
||||
Kind: l.Kind,
|
||||
ref: l.Ref,
|
||||
stream: l.Stream,
|
||||
version: v,
|
||||
kind: l.Kind,
|
||||
}
|
||||
}
|
||||
return versions
|
||||
|
|
|
@ -344,10 +344,10 @@ func TestListStructuredVersions(t *testing.T) {
|
|||
|
||||
verStrs := make([]string, len(versions))
|
||||
for i, v := range versions {
|
||||
assert.Equal(list.Ref, v.Ref)
|
||||
assert.Equal(list.Stream, v.Stream)
|
||||
assert.Equal(list.Kind, v.Kind)
|
||||
verStrs[i] = v.Version
|
||||
assert.Equal(list.Ref, v.Ref())
|
||||
assert.Equal(list.Stream, v.Stream())
|
||||
assert.Equal(list.Kind, v.Kind())
|
||||
verStrs[i] = v.version
|
||||
}
|
||||
|
||||
assert.ElementsMatch(list.Versions, verStrs)
|
||||
|
|
|
@ -28,11 +28,30 @@ const ReleaseRef = "-"
|
|||
// Notice that version is a meta object to the versions API and there isn't an
|
||||
// actual corresponding object in the S3 bucket.
|
||||
// Therefore, the version object doesn't have a URL or JSON path.
|
||||
//
|
||||
// Versions fields are private so the type can be used in other packages by
|
||||
// defining private interfaces.
|
||||
type Version struct {
|
||||
Ref string
|
||||
Stream string
|
||||
Version string
|
||||
Kind VersionKind
|
||||
ref string
|
||||
stream string
|
||||
version string
|
||||
kind VersionKind
|
||||
}
|
||||
|
||||
// NewVersion creates a new Version object and validates it.
|
||||
func NewVersion(ref, stream, version string, kind VersionKind) (Version, error) {
|
||||
ver := Version{
|
||||
ref: ref,
|
||||
stream: stream,
|
||||
version: version,
|
||||
kind: kind,
|
||||
}
|
||||
|
||||
if err := ver.Validate(); err != nil {
|
||||
return Version{}, err
|
||||
}
|
||||
|
||||
return ver, nil
|
||||
}
|
||||
|
||||
// NewVersionFromShortPath creates a new Version from a version short path.
|
||||
|
@ -43,10 +62,10 @@ func NewVersionFromShortPath(shortPath string, kind VersionKind) (Version, error
|
|||
}
|
||||
|
||||
ver := Version{
|
||||
Ref: ref,
|
||||
Stream: stream,
|
||||
Version: version,
|
||||
Kind: kind,
|
||||
ref: ref,
|
||||
stream: stream,
|
||||
version: version,
|
||||
kind: kind,
|
||||
}
|
||||
|
||||
if err := ver.Validate(); err != nil {
|
||||
|
@ -56,27 +75,47 @@ func NewVersionFromShortPath(shortPath string, kind VersionKind) (Version, error
|
|||
return ver, nil
|
||||
}
|
||||
|
||||
// Ref returns the ref of the version.
|
||||
func (v Version) Ref() string {
|
||||
return v.ref
|
||||
}
|
||||
|
||||
// Stream returns the stream of the version.
|
||||
func (v Version) Stream() string {
|
||||
return v.stream
|
||||
}
|
||||
|
||||
// Version returns the version string of the version.
|
||||
func (v Version) Version() string {
|
||||
return v.version
|
||||
}
|
||||
|
||||
// Kind returns the kind of the version.
|
||||
func (v Version) Kind() VersionKind {
|
||||
return v.kind
|
||||
}
|
||||
|
||||
// ShortPath returns the short path of the version.
|
||||
func (v Version) ShortPath() string {
|
||||
return shortPath(v.Ref, v.Stream, v.Version)
|
||||
return shortPath(v.ref, v.stream, v.version)
|
||||
}
|
||||
|
||||
// Validate validates the version.
|
||||
func (v Version) Validate() error {
|
||||
var retErr error
|
||||
if err := ValidateRef(v.Ref); err != nil {
|
||||
if err := ValidateRef(v.ref); err != nil {
|
||||
retErr = errors.Join(retErr, err)
|
||||
}
|
||||
if err := ValidateStream(v.Ref, v.Stream); err != nil {
|
||||
if err := ValidateStream(v.ref, v.stream); err != nil {
|
||||
retErr = errors.Join(retErr, err)
|
||||
}
|
||||
if !semver.IsValid(v.Version) {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a valid semantic version", v.Version))
|
||||
if !semver.IsValid(v.version) {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a valid semantic version", v.version))
|
||||
}
|
||||
if semver.Canonical(v.Version) != v.Version {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a canonical semantic version", v.Version))
|
||||
if semver.Canonical(v.version) != v.version {
|
||||
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a canonical semantic version", v.version))
|
||||
}
|
||||
if v.Kind == VersionKindUnknown {
|
||||
if v.kind == VersionKindUnknown {
|
||||
retErr = errors.Join(retErr, errors.New("version kind is unknown"))
|
||||
}
|
||||
return retErr
|
||||
|
@ -84,29 +123,29 @@ func (v Version) Validate() error {
|
|||
|
||||
// Equal returns true if the versions are equal.
|
||||
func (v Version) Equal(other Version) bool {
|
||||
return v.Ref == other.Ref &&
|
||||
v.Stream == other.Stream &&
|
||||
v.Version == other.Version &&
|
||||
v.Kind == other.Kind
|
||||
return v.ref == other.ref &&
|
||||
v.stream == other.stream &&
|
||||
v.version == other.version &&
|
||||
v.kind == other.kind
|
||||
}
|
||||
|
||||
// Major returns the major version corresponding to the version.
|
||||
// For example, if the version is "v1.2.3", the major version is "v1".
|
||||
func (v Version) Major() string {
|
||||
return semver.Major(v.Version)
|
||||
return semver.Major(v.version)
|
||||
}
|
||||
|
||||
// MajorMinor returns the major and minor version corresponding to the version.
|
||||
// For example, if the version is "v1.2.3", the major and minor version is "v1.2".
|
||||
func (v Version) MajorMinor() string {
|
||||
return semver.MajorMinor(v.Version)
|
||||
return semver.MajorMinor(v.version)
|
||||
}
|
||||
|
||||
// WithGranularity returns the version with the given granularity.
|
||||
//
|
||||
// For example, if the version is "v1.2.3" and the granularity is GranularityMajor,
|
||||
// the returned version is "v1".
|
||||
// This is a helper function for Major() and MajorMinor() and v.Version.
|
||||
// This is a helper function for Major() and MajorMinor() and v.version.
|
||||
// In case of an unknown granularity, an empty string is returned.
|
||||
func (v Version) WithGranularity(gran Granularity) string {
|
||||
switch gran {
|
||||
|
@ -115,7 +154,7 @@ func (v Version) WithGranularity(gran Granularity) string {
|
|||
case GranularityMinor:
|
||||
return v.MajorMinor()
|
||||
case GranularityPatch:
|
||||
return v.Version
|
||||
return v.version
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
@ -144,11 +183,11 @@ func (v Version) ListPath(gran Granularity) string {
|
|||
}
|
||||
return path.Join(
|
||||
constants.CDNAPIPrefix,
|
||||
"ref", v.Ref,
|
||||
"stream", v.Stream,
|
||||
"ref", v.ref,
|
||||
"stream", v.stream,
|
||||
"versions",
|
||||
gran.String(), v.WithGranularity(gran),
|
||||
v.Kind.String()+".json",
|
||||
v.kind.String()+".json",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -164,9 +203,9 @@ func (v Version) ArtifactPath(apiVer apiVersion) string {
|
|||
return path.Join(
|
||||
constants.CDNAPIBase,
|
||||
apiVer.String(),
|
||||
"ref", v.Ref,
|
||||
"stream", v.Stream,
|
||||
v.Version,
|
||||
"ref", v.ref,
|
||||
"stream", v.stream,
|
||||
v.version,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -336,8 +375,8 @@ func ValidateStream(ref, stream string) error {
|
|||
|
||||
// MeasurementURL builds the measurement and signature URLs for the given version.
|
||||
func MeasurementURL(version Version) (measurementURL, signatureURL *url.URL, err error) {
|
||||
if version.Kind != VersionKindImage {
|
||||
return &url.URL{}, &url.URL{}, fmt.Errorf("kind %q is not supported", version.Kind)
|
||||
if version.kind != VersionKindImage {
|
||||
return &url.URL{}, &url.URL{}, fmt.Errorf("kind %q is not supported", version.kind)
|
||||
}
|
||||
|
||||
measurementPath, err := url.JoinPath(version.ArtifactsURL(APIV2), "image", constants.CDNMeasurementsFile)
|
||||
|
|
|
@ -27,40 +27,40 @@ func TestNewVersionFromShortPath(t *testing.T) {
|
|||
path: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
wantVer: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
},
|
||||
"release debug image": {
|
||||
path: "stream/debug/v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
wantVer: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
},
|
||||
"stable release cli": {
|
||||
path: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
wantVer: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
},
|
||||
"release debug cli": {
|
||||
path: "stream/debug/v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
wantVer: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
},
|
||||
"unknown kind": {
|
||||
|
@ -102,55 +102,55 @@ func TestVersionShortPath(t *testing.T) {
|
|||
}{
|
||||
"stable release image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
want: "v9.9.9",
|
||||
},
|
||||
"release debug image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
want: "stream/debug/v9.9.9",
|
||||
},
|
||||
"branch image": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
want: "ref/foo/stream/debug/v9.9.9",
|
||||
},
|
||||
"stable release cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
want: "v9.9.9",
|
||||
},
|
||||
"release debug cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
want: "stream/debug/v9.9.9",
|
||||
},
|
||||
"branch cli": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
want: "ref/foo/stream/debug/v9.9.9",
|
||||
},
|
||||
|
@ -173,71 +173,71 @@ func TestVersionValidate(t *testing.T) {
|
|||
}{
|
||||
"valid image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
},
|
||||
"invalid ref image": {
|
||||
ver: Version{
|
||||
Ref: "foo/bar",
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: "foo/bar",
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid stream image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "foo/bar",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "foo/bar",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid version image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9/foo",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9/foo",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"valid cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
},
|
||||
"invalid ref cli": {
|
||||
ver: Version{
|
||||
Ref: "foo/bar",
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: "foo/bar",
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid stream cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "foo/bar",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "foo/bar",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid version cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9/foo",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9/foo",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
|
@ -268,7 +268,7 @@ func TestVersionMajor(t *testing.T) {
|
|||
t.Run(version, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ver := Version{Version: version}
|
||||
ver := Version{version: version}
|
||||
assert.Equal(major, ver.Major())
|
||||
})
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ func TestVersionMajorMinor(t *testing.T) {
|
|||
t.Run(version, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ver := Version{Version: version}
|
||||
ver := Version{version: version}
|
||||
assert.Equal(major, ver.MajorMinor())
|
||||
})
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ func TestVersionWithGranularity(t *testing.T) {
|
|||
t.Run(tc.ver, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ver := Version{Version: tc.ver}
|
||||
ver := Version{version: tc.ver}
|
||||
assert.Equal(tc.want, ver.WithGranularity(tc.gran))
|
||||
})
|
||||
}
|
||||
|
@ -348,10 +348,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
}{
|
||||
"release image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMajor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/stable/versions/major/v9/image.json",
|
||||
|
@ -359,10 +359,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"release with minor image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMinor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/stable/versions/minor/v9.9/image.json",
|
||||
|
@ -370,10 +370,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"release with patch image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityPatch,
|
||||
wantPath: "",
|
||||
|
@ -381,10 +381,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"release with unknown image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityUnknown,
|
||||
wantPath: "",
|
||||
|
@ -392,10 +392,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"release debug stream image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMajor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/debug/versions/major/v9/image.json",
|
||||
|
@ -403,10 +403,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"release debug stream with minor image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMinor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/debug/versions/minor/v9.9/image.json",
|
||||
|
@ -414,10 +414,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"branch ref image": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMajor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/foo/stream/debug/versions/major/v9/image.json",
|
||||
|
@ -425,10 +425,10 @@ func TestVersionListPathURL(t *testing.T) {
|
|||
},
|
||||
"branch ref with minor image": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
gran: GranularityMinor,
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/foo/stream/debug/versions/minor/v9.9/image.json",
|
||||
|
@ -463,10 +463,10 @@ func TestVersionArtifactURL(t *testing.T) {
|
|||
}{
|
||||
"nightly-feature": {
|
||||
ver: Version{
|
||||
Ref: "feat-some-feature",
|
||||
Stream: "nightly",
|
||||
Version: "v2.6.0-pre.0.20230217095603-193dd48ca19f",
|
||||
Kind: VersionKindImage,
|
||||
ref: "feat-some-feature",
|
||||
stream: "nightly",
|
||||
version: "v2.6.0-pre.0.20230217095603-193dd48ca19f",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
csp: cloudprovider.GCP,
|
||||
wantMeasurementURL: constants.CDNRepositoryURL + "/" + constants.CDNAPIPrefixV2 + "/ref/feat-some-feature/stream/nightly/v2.6.0-pre.0.20230217095603-193dd48ca19f/image/measurements.json",
|
||||
|
@ -474,7 +474,7 @@ func TestVersionArtifactURL(t *testing.T) {
|
|||
},
|
||||
"fail for wrong kind": {
|
||||
ver: Version{
|
||||
Kind: VersionKindCLI,
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
|
@ -503,55 +503,55 @@ func TestVersionArtifactPathURL(t *testing.T) {
|
|||
}{
|
||||
"release image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/stable/v9.9.9",
|
||||
},
|
||||
"release debug stream image": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/debug/v9.9.9",
|
||||
},
|
||||
"branch ref image": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindImage,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindImage,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/foo/stream/debug/v9.9.9",
|
||||
},
|
||||
"release cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "stable",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/stable/v9.9.9",
|
||||
},
|
||||
"release debug stream cli": {
|
||||
ver: Version{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: ReleaseRef,
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/" + ReleaseRef + "/stream/debug/v9.9.9",
|
||||
},
|
||||
"branch ref cli": {
|
||||
ver: Version{
|
||||
Ref: "foo",
|
||||
Stream: "debug",
|
||||
Version: "v9.9.9",
|
||||
Kind: VersionKindCLI,
|
||||
ref: "foo",
|
||||
stream: "debug",
|
||||
version: "v9.9.9",
|
||||
kind: VersionKindCLI,
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/foo/stream/debug/v9.9.9",
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue