diff --git a/cmd/cli/app/artifact/artifact_get.go b/cmd/cli/app/artifact/artifact_get.go index 44dc8cd783..945f25d5b4 100644 --- a/cmd/cli/app/artifact/artifact_get.go +++ b/cmd/cli/app/artifact/artifact_get.go @@ -17,12 +17,14 @@ package artifact import ( "context" + "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" @@ -45,6 +47,11 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) artifactID := viper.GetString("id") latestVersions := viper.GetInt32("versions") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // check artifact by name art, err := client.GetArtifactById(ctx, &minderv1.GetArtifactByIdRequest{ Context: &minderv1.Context{Provider: &provider, Project: &project}, diff --git a/cmd/cli/app/profile/apply.go b/cmd/cli/app/profile/apply.go index 9b14f09d1c..95553b5b1c 100644 --- a/cmd/cli/app/profile/apply.go +++ b/cmd/cli/app/profile/apply.go @@ -26,6 +26,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -46,6 +47,11 @@ func applyCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") f := viper.GetString("file") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + table := NewProfileTable() applyFunc := func(ctx context.Context, f string, p *minderv1.Profile) (*minderv1.Profile, error) { diff --git a/cmd/cli/app/profile/create.go b/cmd/cli/app/profile/create.go index 508a41c20a..7c12a65fa5 100644 --- a/cmd/cli/app/profile/create.go +++ b/cmd/cli/app/profile/create.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -44,6 +45,11 @@ func createCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") f := viper.GetString("file") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + table := NewProfileTable() createFunc := func(ctx context.Context, f string, p *minderv1.Profile) (*minderv1.Profile, error) { diff --git a/cmd/cli/app/profile/delete.go b/cmd/cli/app/profile/delete.go index b907b4ab48..a35a9d8feb 100644 --- a/cmd/cli/app/profile/delete.go +++ b/cmd/cli/app/profile/delete.go @@ -17,12 +17,14 @@ package profile import ( "context" + "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -42,6 +44,11 @@ func deleteCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientCon project := viper.GetString("project") id := viper.GetString("id") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Delete profile _, err := client.DeleteProfile(ctx, &minderv1.DeleteProfileRequest{ Context: &minderv1.Context{Provider: &provider, Project: &project}, diff --git a/cmd/cli/app/profile/get.go b/cmd/cli/app/profile/get.go index f6904eeaa4..610ef6e7ff 100644 --- a/cmd/cli/app/profile/get.go +++ b/cmd/cli/app/profile/get.go @@ -47,6 +47,11 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) format := viper.GetString("output") id := viper.GetString("id") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/profile/list.go b/cmd/cli/app/profile/list.go index 7e63c10077..f353308254 100644 --- a/cmd/cli/app/profile/list.go +++ b/cmd/cli/app/profile/list.go @@ -45,6 +45,11 @@ func listCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") format := viper.GetString("output") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/profile/status/status_get.go b/cmd/cli/app/profile/status/status_get.go index 708a924933..e76afc5ec5 100644 --- a/cmd/cli/app/profile/status/status_get.go +++ b/cmd/cli/app/profile/status/status_get.go @@ -50,6 +50,11 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) entityType := viper.GetString("entity-type") format := viper.GetString("output") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/profile/status/status_list.go b/cmd/cli/app/profile/status/status_list.go index 6838b5c049..1b793c0437 100644 --- a/cmd/cli/app/profile/status/status_list.go +++ b/cmd/cli/app/profile/status/status_list.go @@ -48,6 +48,11 @@ func listCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) all := viper.GetBool("detailed") rule := viper.GetString("rule") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/provider/provider_enroll.go b/cmd/cli/app/provider/provider_enroll.go index 14b60235db..1254443a90 100644 --- a/cmd/cli/app/provider/provider_enroll.go +++ b/cmd/cli/app/provider/provider_enroll.go @@ -35,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/protobuf/types/known/timestamppb" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" "github.com/stacklok/minder/internal/util/rand" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" @@ -67,6 +68,11 @@ func EnrollProviderCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.C owner := viper.GetString("owner") yesFlag := viper.GetBool("yes") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ask for confirmation if an owner is set on purpose ownerPromptStr := "your personal account" if owner != "" { diff --git a/cmd/cli/app/quickstart/quickstart.go b/cmd/cli/app/quickstart/quickstart.go index d91b8ac708..c506c1f00a 100644 --- a/cmd/cli/app/quickstart/quickstart.go +++ b/cmd/cli/app/quickstart/quickstart.go @@ -141,6 +141,11 @@ func quickstartCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientC project := viper.GetString("project") provider := viper.GetString("provider") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Confirm user wants to go through the quickstart process yes := cli.PrintYesNoPrompt(cmd, stepPromptMsgWelcome, diff --git a/cmd/cli/app/repo/repo_delete.go b/cmd/cli/app/repo/repo_delete.go index c83b9e5601..7747c63323 100644 --- a/cmd/cli/app/repo/repo_delete.go +++ b/cmd/cli/app/repo/repo_delete.go @@ -17,11 +17,13 @@ package repo import ( "context" + "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -42,6 +44,11 @@ func deleteCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientCon repoID := viper.GetString("id") name := viper.GetString("name") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // delete repo by id if repoID != "" { resp, err := client.DeleteRepositoryById(ctx, &minderv1.DeleteRepositoryByIdRequest{ diff --git a/cmd/cli/app/repo/repo_get.go b/cmd/cli/app/repo/repo_get.go index 1004eafe75..c1a09ad0c0 100644 --- a/cmd/cli/app/repo/repo_get.go +++ b/cmd/cli/app/repo/repo_get.go @@ -47,6 +47,11 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) repoid := viper.GetString("id") name := viper.GetString("name") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) || format == app.Table { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/repo/repo_list.go b/cmd/cli/app/repo/repo_list.go index 572aeaa966..7c0641febc 100644 --- a/cmd/cli/app/repo/repo_list.go +++ b/cmd/cli/app/repo/repo_list.go @@ -46,6 +46,11 @@ func listCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") format := viper.GetString("output") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/repo/repo_register.go b/cmd/cli/app/repo/repo_register.go index ed91404839..75c410d54e 100644 --- a/cmd/cli/app/repo/repo_register.go +++ b/cmd/cli/app/repo/repo_register.go @@ -33,6 +33,7 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" "github.com/stacklok/minder/internal/util/cli/table" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" @@ -63,6 +64,11 @@ func RegisterCmd(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") repoList := viper.GetString("name") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return nil, fmt.Sprintf("provider %s is not supported yet", provider), fmt.Errorf("invalid argument") + } + // Get the list of repos listResp, err := client.ListRepositories(ctx, &minderv1.ListRepositoriesRequest{ Context: &minderv1.Context{Provider: &provider, Project: &project}, diff --git a/cmd/cli/app/root.go b/cmd/cli/app/root.go index 7d1a71eb29..0d245fd310 100644 --- a/cmd/cli/app/root.go +++ b/cmd/cli/app/root.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/viper" "github.com/stacklok/minder/internal/constants" + ghclient "github.com/stacklok/minder/internal/providers/github" "github.com/stacklok/minder/internal/util/cli" ) @@ -125,3 +126,18 @@ func IsOutputFormatSupported(output string) bool { func SupportedOutputFormats() []string { return []string{JSON, YAML, Table} } + +// IsProviderSupported returns true if the provider is supported +func IsProviderSupported(provider string) bool { + for _, p := range SupportedProviders() { + if provider == p { + return true + } + } + return false +} + +// SupportedProviders returns the supported providers list +func SupportedProviders() []string { + return []string{ghclient.Github} +} diff --git a/cmd/cli/app/ruletype/ruletype_apply.go b/cmd/cli/app/ruletype/ruletype_apply.go index e3a6c5fe9b..8486aa1e31 100644 --- a/cmd/cli/app/ruletype/ruletype_apply.go +++ b/cmd/cli/app/ruletype/ruletype_apply.go @@ -26,6 +26,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" @@ -45,6 +46,11 @@ func applyCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn) provider := viper.GetString("provider") project := viper.GetString("project") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + fileFlag, err := cmd.Flags().GetStringArray("file") if err != nil { return cli.MessageAndError("Error parsing file flag", err) diff --git a/cmd/cli/app/ruletype/ruletype_create.go b/cmd/cli/app/ruletype/ruletype_create.go index dd44bed67f..720f5b4f69 100644 --- a/cmd/cli/app/ruletype/ruletype_create.go +++ b/cmd/cli/app/ruletype/ruletype_create.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" @@ -44,6 +45,11 @@ func createCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn) provider := viper.GetString("provider") project := viper.GetString("project") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + fileFlag, err := cmd.Flags().GetStringArray("file") if err != nil { return cli.MessageAndError("Error parsing file flag", err) diff --git a/cmd/cli/app/ruletype/ruletype_delete.go b/cmd/cli/app/ruletype/ruletype_delete.go index 45f657be82..2008c2d727 100644 --- a/cmd/cli/app/ruletype/ruletype_delete.go +++ b/cmd/cli/app/ruletype/ruletype_delete.go @@ -17,11 +17,13 @@ package ruletype import ( "context" + "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" "google.golang.org/grpc" + "github.com/stacklok/minder/cmd/cli/app" "github.com/stacklok/minder/internal/util/cli" minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -43,6 +45,11 @@ func deleteCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientCon deleteAll := viper.GetBool("all") yesFlag := viper.GetBool("yes") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + if deleteAll && !yesFlag { // Ask for confirmation if deleteAll is set on purpose yes := cli.PrintYesNoPrompt(cmd, diff --git a/cmd/cli/app/ruletype/ruletype_get.go b/cmd/cli/app/ruletype/ruletype_get.go index b9087f9303..ab4deacbc7 100644 --- a/cmd/cli/app/ruletype/ruletype_get.go +++ b/cmd/cli/app/ruletype/ruletype_get.go @@ -47,6 +47,11 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) format := viper.GetString("output") id := viper.GetString("id") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument")) diff --git a/cmd/cli/app/ruletype/ruletype_list.go b/cmd/cli/app/ruletype/ruletype_list.go index c1bad79f5e..c6e8ebe5a2 100644 --- a/cmd/cli/app/ruletype/ruletype_list.go +++ b/cmd/cli/app/ruletype/ruletype_list.go @@ -45,6 +45,11 @@ func listCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) project := viper.GetString("project") format := viper.GetString("output") + // Ensure provider is supported + if !app.IsProviderSupported(provider) { + return cli.MessageAndError(fmt.Sprintf("Provider %s is not supported yet", provider), fmt.Errorf("invalid argument")) + } + // Ensure the output format is supported if !app.IsOutputFormatSupported(format) { return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument"))