mirror of
				https://github.com/edgelesssys/constellation.git
				synced 2025-11-03 20:24:16 -05:00 
			
		
		
		
	The cli now takes CSP and object kind as argument. Also made upload an explicit command and the report path/version an argument. Previously the report was a flag. The CSP was hardcoded. There was only one object kind (snp-report).
		
			
				
	
	
		
			53 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
/*
 | 
						|
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 {
 | 
						|
	return func(cmd *cobra.Command, args []string) error {
 | 
						|
		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 {
 | 
						|
	return func(cmd *cobra.Command, args []string) error {
 | 
						|
		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"
 | 
						|
	guestFirmware objectKind = "guest-firmware"
 | 
						|
)
 | 
						|
 | 
						|
func kindFromString(s string) objectKind {
 | 
						|
	lower := strings.ToLower(s)
 | 
						|
	switch objectKind(lower) {
 | 
						|
	case snpReport, guestFirmware:
 | 
						|
		return objectKind(lower)
 | 
						|
	default:
 | 
						|
		return unknown
 | 
						|
	}
 | 
						|
}
 |