mirror of https://github.com/fluxcd/flux2.git
Merge pull request #356 from StupidScience/custom-flags
Implement custom flags for options with validation rulespull/350/head
commit
4eaf72fa3e
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedArchs = []string{"amd64", "arm", "arm64"}
|
||||
|
||||
type Arch string
|
||||
|
||||
func (a *Arch) String() string {
|
||||
return string(*a)
|
||||
}
|
||||
|
||||
func (a *Arch) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no arch given, must be one of: %s",
|
||||
strings.Join(supportedArchs, ", "))
|
||||
}
|
||||
if !utils.ContainsItemString(supportedArchs, str) {
|
||||
return fmt.Errorf("unsupported arch '%s', must be one of: %s",
|
||||
str, strings.Join(supportedArchs, ", "))
|
||||
|
||||
}
|
||||
*a = Arch(str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Arch) Type() string {
|
||||
return "arch"
|
||||
}
|
||||
|
||||
func (a *Arch) Description() string {
|
||||
return fmt.Sprintf("cluster architecture, available options are: (%s)", strings.Join(supportedArchs, ", "))
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedDecryptionProviders = []string{"sops"}
|
||||
|
||||
type DecryptionProvider string
|
||||
|
||||
func (d *DecryptionProvider) String() string {
|
||||
return string(*d)
|
||||
}
|
||||
|
||||
func (d *DecryptionProvider) Set(str string) error {
|
||||
if !utils.ContainsItemString(supportedDecryptionProviders, str) {
|
||||
return fmt.Errorf("unsupported decryption provider '%s', must be one of: %s",
|
||||
str, strings.Join(supportedDecryptionProviders, ", "))
|
||||
|
||||
}
|
||||
*d = DecryptionProvider(str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DecryptionProvider) Type() string {
|
||||
return "decryptionProvider"
|
||||
}
|
||||
|
||||
func (d *DecryptionProvider) Description() string {
|
||||
return fmt.Sprintf("decryption provider, available options are: (%s)", strings.Join(supportedDecryptionProviders, ", "))
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind, sourcev1.BucketKind}
|
||||
|
||||
type HelmChartSource struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (h *HelmChartSource) String() string {
|
||||
if h.Name == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", h.Kind, h.Name)
|
||||
}
|
||||
|
||||
func (h *HelmChartSource) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no helm chart source given, please specify %s",
|
||||
h.Description())
|
||||
}
|
||||
|
||||
sourceKind, sourceName := utils.ParseObjectKindName(str)
|
||||
if sourceKind == "" {
|
||||
return fmt.Errorf("invalid helm chart source '%s', must be in format <kind>/<name>", str)
|
||||
}
|
||||
if !utils.ContainsItemString(supportedHelmChartSourceKinds, sourceKind) {
|
||||
return fmt.Errorf("source kind '%s' is not supported, can be one of: %s",
|
||||
sourceKind, strings.Join(supportedHelmChartSourceKinds, ", "))
|
||||
}
|
||||
|
||||
h.Name = sourceName
|
||||
h.Kind = sourceKind
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HelmChartSource) Type() string {
|
||||
return "helmChartSource"
|
||||
}
|
||||
|
||||
func (h *HelmChartSource) Description() string {
|
||||
return fmt.Sprintf(
|
||||
"source that contains the chart in the format '<kind>/<name>',"+
|
||||
"where kind can be one of: (%s)",
|
||||
strings.Join(supportedHelmChartSourceKinds, ", "),
|
||||
)
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedKustomizationSourceKinds = []string{sourcev1.GitRepositoryKind, sourcev1.BucketKind}
|
||||
|
||||
type KustomizationSource struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (k *KustomizationSource) String() string {
|
||||
if k.Name == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", k.Kind, k.Name)
|
||||
}
|
||||
|
||||
func (k *KustomizationSource) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no kustomization source given, please specify %s",
|
||||
k.Description())
|
||||
}
|
||||
|
||||
sourceKind, sourceName := utils.ParseObjectKindName(str)
|
||||
if sourceKind == "" {
|
||||
sourceKind = sourcev1.GitRepositoryKind
|
||||
}
|
||||
if !utils.ContainsItemString(supportedKustomizationSourceKinds, sourceKind) {
|
||||
return fmt.Errorf("source kind '%s' is not supported, can be one of: %s",
|
||||
sourceKind, strings.Join(supportedKustomizationSourceKinds, ", "))
|
||||
}
|
||||
|
||||
k.Name = sourceName
|
||||
k.Kind = sourceKind
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *KustomizationSource) Type() string {
|
||||
return "kustomizationSource"
|
||||
}
|
||||
|
||||
func (k *KustomizationSource) Description() string {
|
||||
return fmt.Sprintf(
|
||||
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>',"+
|
||||
"where kind can be one of: (%s), if kind is not specified it defaults to GitRepository",
|
||||
strings.Join(supportedKustomizationSourceKinds, ", "),
|
||||
)
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedLogLevels = []string{"debug", "info", "error"}
|
||||
|
||||
type LogLevel string
|
||||
|
||||
func (l *LogLevel) String() string {
|
||||
return string(*l)
|
||||
}
|
||||
|
||||
func (l *LogLevel) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no log level given, must be one of: %s",
|
||||
strings.Join(supportedLogLevels, ", "))
|
||||
}
|
||||
if !utils.ContainsItemString(supportedLogLevels, str) {
|
||||
return fmt.Errorf("unsupported log level '%s', must be one of: %s",
|
||||
str, strings.Join(supportedLogLevels, ", "))
|
||||
|
||||
}
|
||||
*l = LogLevel(str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LogLevel) Type() string {
|
||||
return "logLevel"
|
||||
}
|
||||
|
||||
func (l *LogLevel) Description() string {
|
||||
return fmt.Sprintf("log level, available options are: (%s)", strings.Join(supportedLogLevels, ", "))
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var supportedPublicKeyAlgorithms = []string{"rsa", "ecdsa", "ed25519"}
|
||||
|
||||
type PublicKeyAlgorithm string
|
||||
|
||||
func (a *PublicKeyAlgorithm) String() string {
|
||||
return string(*a)
|
||||
}
|
||||
|
||||
func (a *PublicKeyAlgorithm) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no public key algorithm given, must be one of: %s",
|
||||
strings.Join(supportedPublicKeyAlgorithms, ", "))
|
||||
}
|
||||
for _, v := range supportedPublicKeyAlgorithms {
|
||||
if str == v {
|
||||
*a = PublicKeyAlgorithm(str)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("unsupported public key algorithm '%s', must be one of: %s",
|
||||
str, strings.Join(supportedPublicKeyAlgorithms, ", "))
|
||||
}
|
||||
|
||||
func (a *PublicKeyAlgorithm) Type() string {
|
||||
return "publicKeyAlgorithm"
|
||||
}
|
||||
|
||||
func (a *PublicKeyAlgorithm) Description() string {
|
||||
return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", "))
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var defaultRSAKeyBits = 2048
|
||||
|
||||
type RSAKeyBits int
|
||||
|
||||
func (b *RSAKeyBits) String() string {
|
||||
return strconv.Itoa(int(*b))
|
||||
}
|
||||
|
||||
func (b *RSAKeyBits) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
*b = RSAKeyBits(defaultRSAKeyBits)
|
||||
return nil
|
||||
}
|
||||
bits, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if bits%8 != 0 {
|
||||
return fmt.Errorf("RSA key bit size should be a multiples of 8")
|
||||
}
|
||||
*b = RSAKeyBits(bits)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *RSAKeyBits) Type() string {
|
||||
return "rsaKeyBits"
|
||||
}
|
||||
|
||||
func (b *RSAKeyBits) Description() string {
|
||||
return "SSH RSA public key bit size (multiplies of 8)"
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2020 The Flux CD contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/fluxcd/toolkit/internal/utils"
|
||||
)
|
||||
|
||||
var supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider}
|
||||
|
||||
type SourceBucketProvider string
|
||||
|
||||
func (s *SourceBucketProvider) String() string {
|
||||
return string(*s)
|
||||
}
|
||||
|
||||
func (s *SourceBucketProvider) Set(str string) error {
|
||||
if strings.TrimSpace(str) == "" {
|
||||
return fmt.Errorf("no source bucket provider given, please specify %s",
|
||||
s.Description())
|
||||
}
|
||||
|
||||
if !utils.ContainsItemString(supportedSourceBucketProviders, str) {
|
||||
return fmt.Errorf("source bucket provider '%s' is not supported, can be one of: %v",
|
||||
str, strings.Join(supportedSourceBucketProviders, ", "))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SourceBucketProvider) Type() string {
|
||||
return "sourceBucketProvider"
|
||||
}
|
||||
|
||||
func (s *SourceBucketProvider) Description() string {
|
||||
return fmt.Sprintf(
|
||||
"the S3 compatible storage provider name, available options are: (%s)",
|
||||
strings.Join(supportedSourceBucketProviders, ", "),
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue