2023-11-09 03:59:19 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func isCloudProvider(arg int) cobra.PositionalArgs {
|
2024-02-21 07:30:31 -05:00
|
|
|
return func(_ *cobra.Command, args []string) error {
|
2023-11-09 03:59:19 -05:00
|
|
|
if provider := cloudprovider.FromString(args[arg]); provider == cloudprovider.Unknown {
|
|
|
|
return fmt.Errorf("argument %s isn't a valid cloud provider", args[arg])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func isValidKind(arg int) cobra.PositionalArgs {
|
2024-02-21 07:30:31 -05:00
|
|
|
return func(_ *cobra.Command, args []string) error {
|
2023-11-09 03:59:19 -05:00
|
|
|
if kind := kindFromString(args[arg]); kind == unknown {
|
|
|
|
return fmt.Errorf("argument %s isn't a valid kind", args[arg])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// objectKind encodes the available actions.
|
|
|
|
type objectKind string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// unknown is the default objectKind and does nothing.
|
|
|
|
unknown objectKind = "unknown-kind"
|
|
|
|
snpReport objectKind = "snp-report"
|
2024-06-11 08:50:38 -04:00
|
|
|
tdxReport objectKind = "tdx-report"
|
2023-11-09 03:59:19 -05:00
|
|
|
guestFirmware objectKind = "guest-firmware"
|
|
|
|
)
|
|
|
|
|
|
|
|
func kindFromString(s string) objectKind {
|
|
|
|
lower := strings.ToLower(s)
|
|
|
|
switch objectKind(lower) {
|
2024-06-11 08:50:38 -04:00
|
|
|
case snpReport, guestFirmware, tdxReport:
|
2023-11-09 03:59:19 -05:00
|
|
|
return objectKind(lower)
|
|
|
|
default:
|
|
|
|
return unknown
|
|
|
|
}
|
|
|
|
}
|