mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 06:16:08 -04:00
config: dynamic attestation configuration through S3 backed API (#1808)
This commit is contained in:
parent
25211dc154
commit
0a6e5ec02e
92 changed files with 1020 additions and 302 deletions
95
internal/api/versionsapi/cliinfo.go
Normal file
95
internal/api/versionsapi/cliinfo.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
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 CLI.
|
||||
Ref string `json:"ref,omitempty"`
|
||||
// Stream is the stream name of the CLI.
|
||||
Stream string `json:"stream,omitempty"`
|
||||
// Version is the version of the CLI.
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue