mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-04-21 23:59:09 -04:00
parse tags
flag
This commit is contained in:
parent
f60c133724
commit
d25a12f6c7
@ -37,6 +37,7 @@ func newConfigGenerateCmd() *cobra.Command {
|
||||
}
|
||||
cmd.Flags().StringP("kubernetes", "k", semver.MajorMinor(string(config.Default().KubernetesVersion)), "Kubernetes version to use in format MAJOR.MINOR")
|
||||
cmd.Flags().StringP("attestation", "a", "", fmt.Sprintf("attestation variant to use %s. If not specified, the default for the cloud provider is used", printFormattedSlice(variant.GetAvailableAttestationVariants())))
|
||||
cmd.Flags().StringP("tags", "t", "", "Additional tags for created resources.")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -45,6 +46,7 @@ type generateFlags struct {
|
||||
rootFlags
|
||||
k8sVersion versions.ValidK8sVersion
|
||||
attestationVariant variant.Variant
|
||||
tags cloudprovider.Tags
|
||||
}
|
||||
|
||||
func (f *generateFlags) parse(flags *pflag.FlagSet) error {
|
||||
@ -64,6 +66,12 @@ func (f *generateFlags) parse(flags *pflag.FlagSet) error {
|
||||
}
|
||||
f.attestationVariant = variant
|
||||
|
||||
tags, err := parseTagsFlags(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.tags = tags
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -221,3 +229,24 @@ func parseAttestationFlag(flags *pflag.FlagSet) (variant.Variant, error) {
|
||||
|
||||
return attestationVariant, nil
|
||||
}
|
||||
|
||||
func parseTagsFlags(flags *pflag.FlagSet) (cloudprovider.Tags, error) {
|
||||
tagsString, err := flags.GetString("tags")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting tags flag: %w", err)
|
||||
}
|
||||
tagsString = strings.ReplaceAll(tagsString, " ", "")
|
||||
tagsStringSplit := strings.Split(tagsString, ",")
|
||||
|
||||
tags := make(cloudprovider.Tags)
|
||||
for _, tag := range tagsStringSplit {
|
||||
tagSplit := strings.Split(tag, "=")
|
||||
if len(tagSplit) != 2 {
|
||||
return nil, fmt.Errorf("wrong format of tags")
|
||||
}
|
||||
|
||||
tags[tagSplit[0]] = tagSplit[1]
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ import (
|
||||
// Provider is cloud provider used by the CLI.
|
||||
type Provider uint32
|
||||
|
||||
// Tags is the type that holds additional tags for cloud resources.
|
||||
type Tags map[string]string
|
||||
|
||||
const (
|
||||
// Unknown is default value for Provider.
|
||||
Unknown Provider = iota
|
||||
|
Loading…
x
Reference in New Issue
Block a user