Skip to content

Commit

Permalink
Revert "Address feedback and remove provider checks from CLI"
Browse files Browse the repository at this point in the history
This reverts commit acdbdaa.
  • Loading branch information
rdimitrov committed Dec 19, 2023
1 parent a981b0b commit dd281fd
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/cli/app/artifact/artifact_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/app/profile/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/app/profile/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions cmd/cli/app/profile/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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},
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/profile/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/profile/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/profile/status/status_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/profile/status/status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/app/provider/provider_enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 != "" {
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/quickstart/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions cmd/cli/app/repo/repo_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/repo/repo_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/app/repo/repo_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
16 changes: 16 additions & 0 deletions cmd/cli/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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}
}
6 changes: 6 additions & 0 deletions cmd/cli/app/ruletype/ruletype_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/app/ruletype/ruletype_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions cmd/cli/app/ruletype/ruletype_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/ruletype/ruletype_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/app/ruletype/ruletype_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit dd281fd

Please sign in to comment.