Skip to content

Commit

Permalink
Add validation for bucket providers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Sep 23, 2020
1 parent 83bd245 commit 34147d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
11 changes: 6 additions & 5 deletions cmd/gotk/create_source_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var (
)

func init() {
createSourceBucketCmd.Flags().StringVar(&sourceBucketProvider, "provider", "generic", "the S3 compatible storage provider name, can be 'generic' or 'aws'")
createSourceBucketCmd.Flags().StringVar(&sourceBucketProvider, "provider", sourcev1.GenericBucketProvider, "the S3 compatible storage provider name, can be 'generic' or 'aws'")
createSourceBucketCmd.Flags().StringVar(&sourceBucketName, "bucket-name", "", "the bucket name")
createSourceBucketCmd.Flags().StringVar(&sourceBucketEndpoint, "endpoint", "", "the bucket endpoint address")
createSourceBucketCmd.Flags().StringVar(&sourceBucketAccessKey, "access-key", "", "the bucket access key")
Expand All @@ -88,8 +88,9 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
name := args[0]
secretName := fmt.Sprintf("bucket-%s", name)

if sourceBucketProvider == "" {
return fmt.Errorf("provider is required")
if !utils.containsItemString(supportedSourceBucketProviders, sourceBucketProvider) {
return fmt.Errorf("bucket provider %s is not supported, can be %v",
sourceBucketProvider, supportedSourceBucketProviders)
}

if sourceBucketName == "" {
Expand Down Expand Up @@ -186,13 +187,13 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
}
err = kubeClient.Get(ctx, namespacedName, &bucket)
if err != nil {
return fmt.Errorf("helm index failed: %w", err)
return fmt.Errorf("could not retrieve bucket: %w", err)
}

if bucket.Status.Artifact != nil {
logger.Successf("fetched revision: %s", bucket.Status.Artifact.Revision)
} else {
return fmt.Errorf("index download failed, artifact not found")
return fmt.Errorf("download failed, artifact not found")
}

return nil
Expand Down
17 changes: 9 additions & 8 deletions cmd/gotk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ var (
)

var (
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest"
defaultNamespace = "gitops-system"
defaultNotification = "notification-controller"
supportedArch = []string{"amd64", "arm", "arm64"}
supportedDecryptionProviders = []string{"sops"}
supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind}
supportedLogLevels = []string{"debug", "info", "error"}
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest"
defaultNamespace = "gitops-system"
defaultNotification = "notification-controller"
supportedLogLevels = []string{"debug", "info", "error"}
supportedArch = []string{"amd64", "arm", "arm64"}
supportedDecryptionProviders = []string{"sops"}
supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind}
supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider}
)

func init() {
Expand Down

0 comments on commit 34147d7

Please sign in to comment.