mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 16:39:38 -05:00
a274ac8a7c
* add cli k8s compatibility api to ci * extend versionsapi package * rework cli info upload via ci * join errors natively * fix semver * upload from hack file * fix ci checks * add distributionid * setup go before running hack file * setup go after repo checkout * use logger instead of panic, invalidate cache * use provided ctx Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --------- Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package versionsapi
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
"golang.org/x/mod/semver"
|
|
)
|
|
|
|
// CLIInfo contains information about a specific CLI version (i.e. it's compatibility with Kubernetes versions).
|
|
type CLIInfo struct {
|
|
// Ref is the reference name of the image.
|
|
Ref string `json:"ref,omitempty"`
|
|
// Stream is the stream name of the image.
|
|
Stream string `json:"stream,omitempty"`
|
|
// Version is the version of the image.
|
|
Version string `json:"version,omitempty"`
|
|
// Kubernetes contains all compatible Kubernetes versions.
|
|
Kubernetes []string `json:"kubernetes,omitempty"`
|
|
}
|
|
|
|
// JSONPath returns the S3 JSON path for this object.
|
|
func (c CLIInfo) JSONPath() string {
|
|
return path.Join(
|
|
constants.CDNAPIPrefix,
|
|
"ref", c.Ref,
|
|
"stream", c.Stream,
|
|
c.Version,
|
|
"cli",
|
|
"info.json",
|
|
)
|
|
}
|
|
|
|
// URL returns the URL to the JSON file for this object.
|
|
func (c CLIInfo) URL() (string, error) {
|
|
url, err := url.Parse(constants.CDNRepositoryURL)
|
|
if err != nil {
|
|
return "", fmt.Errorf("parsing CDN URL: %w", err)
|
|
}
|
|
url.Path = c.JSONPath()
|
|
return url.String(), nil
|
|
}
|
|
|
|
// ValidateRequest validates the request parameters of the list.
|
|
// The Kubernetes slice must be empty.
|
|
func (c CLIInfo) ValidateRequest() error {
|
|
var retErr error
|
|
if err := ValidateRef(c.Ref); err != nil {
|
|
retErr = errors.Join(retErr, err)
|
|
}
|
|
if err := ValidateStream(c.Ref, c.Stream); err != nil {
|
|
retErr = errors.Join(retErr, err)
|
|
}
|
|
if !semver.IsValid(c.Version) {
|
|
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a valid semver", c.Version))
|
|
}
|
|
if len(c.Kubernetes) != 0 {
|
|
retErr = errors.Join(retErr, errors.New("Kubernetes slice must be empty for request"))
|
|
}
|
|
|
|
return retErr
|
|
}
|
|
|
|
// Validate checks if the CLI info is valid.
|
|
func (c CLIInfo) Validate() error {
|
|
var retErr error
|
|
if err := ValidateRef(c.Ref); err != nil {
|
|
retErr = errors.Join(retErr, err)
|
|
}
|
|
if err := ValidateStream(c.Ref, c.Stream); err != nil {
|
|
retErr = errors.Join(retErr, err)
|
|
}
|
|
if !semver.IsValid(c.Version) {
|
|
retErr = errors.Join(retErr, fmt.Errorf("version %q is not a valid semver", c.Version))
|
|
}
|
|
if len(c.Kubernetes) == 0 {
|
|
retErr = errors.Join(retErr, errors.New("Kubernetes slice must not be empty"))
|
|
}
|
|
for _, k := range c.Kubernetes {
|
|
if !semver.IsValid(k) {
|
|
retErr = errors.Join(retErr, fmt.Errorf("Kubernetes version %q is not a valid semver", k))
|
|
}
|
|
}
|
|
|
|
return retErr
|
|
}
|