From 3b3323f79ce0f2c73055f44198e69328c3635ddd Mon Sep 17 00:00:00 2001 From: sunguroku <65516095+sunguroku@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:49:50 -0400 Subject: [PATCH] kubectl for v1 users (#4552) Co-authored-by: sunguroku Co-authored-by: Porter Support <93286801+portersupport@users.noreply.github.com> --- cli/cmd/commands/kubectl.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/cmd/commands/kubectl.go b/cli/cmd/commands/kubectl.go index 26b763ab74..bdadd6be10 100644 --- a/cli/cmd/commands/kubectl.go +++ b/cli/cmd/commands/kubectl.go @@ -38,11 +38,21 @@ func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command { func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { // this will never error because it just ran user, _ := client.AuthCheck(ctx) - if !strings.HasSuffix(user.Email, "@porter.run") { + + project, err := client.GetProject(ctx, cliConf.Project) + if err != nil { + return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run: %w", err) + } + + if project == nil { + return fmt.Errorf("project [%d] not found", cliConf.Project) + } + + if !strings.HasSuffix(user.Email, "@porter.run") && project.ValidateApplyV2 { return fmt.Errorf("Forbidden") } - _, err := exec.LookPath("kubectl") + _, err = exec.LookPath("kubectl") if err != nil { return fmt.Errorf("error finding kubectl: %w", err) }