Skip to content

Commit

Permalink
Merge branch 'main' into cdong-csfle-ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
channingdong committed Dec 14, 2024
2 parents 92944c4 + dcbab11 commit 09f21d9
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 6 deletions.
6 changes: 4 additions & 2 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"fmt"
"os"
"runtime/debug"
"strings"

shell "github.com/brianstrauch/cobra-shell"
Expand Down Expand Up @@ -54,6 +55,7 @@ import (
"github.com/confluentinc/cli/v4/pkg/form"
"github.com/confluentinc/cli/v4/pkg/help"
"github.com/confluentinc/cli/v4/pkg/jwt"
"github.com/confluentinc/cli/v4/pkg/log"
"github.com/confluentinc/cli/v4/pkg/output"
ppanic "github.com/confluentinc/cli/v4/pkg/panic-recovery"
pplugin "github.com/confluentinc/cli/v4/pkg/plugin"
Expand Down Expand Up @@ -151,8 +153,8 @@ func NewConfluentCommand(cfg *config.Config) *cobra.Command {
func Execute(cmd *cobra.Command, args []string, cfg *config.Config) error {
defer func() {
if r := recover(); r != nil {
if !cfg.Version.IsReleased() {
panic(r)
if !cfg.IsCloudLogin() || cfg.HasGovHostname() || !cfg.Version.IsReleased() {
log.CliLogger.Trace(string(debug.Stack()))
}
u := ppanic.CollectPanic(cmd, args, cfg)
if err := reportUsage(cmd, cfg, u); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/flink/command_artifact_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (c *command) createArtifact(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil {
return fmt.Errorf("environment '%s' not found", environment)
}
runtimeLanguage, err := cmd.Flags().GetString("runtime-language")
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions internal/flink/command_artifact_delete.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flink

import (
"fmt"

"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
Expand Down Expand Up @@ -52,6 +54,9 @@ func (c *command) delete(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil {
return fmt.Errorf("environment '%s' not found", environment)
}

existenceFunc := func(id string) bool {
artifactIdToName, err := c.mapArtifactIdToName(cloud, region, environment)
Expand Down
5 changes: 5 additions & 0 deletions internal/flink/command_artifact_describe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flink

import (
"fmt"

"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
Expand Down Expand Up @@ -48,6 +50,9 @@ func (c *command) describe(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil {
return fmt.Errorf("environment '%s' not found", environment)
}

artifact, err := c.V2Client.DescribeFlinkArtifact(cloud, region, environment, args[0])
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/flink/command_artifact_list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flink

import (
"fmt"

"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
Expand Down Expand Up @@ -57,6 +59,9 @@ func (c *command) list(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil {
return fmt.Errorf("environment '%s' not found", environment)
}

artifacts, err := c.V2Client.ListFlinkArtifacts(cloud, region, environment)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/flink/command_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/confluentinc/cli/v4/pkg/utils"
)

const envNotFoundErrorMsg = "Failed to get environment '%s'. List available environments with `confluent environment list`."

type connectionOut struct {
CreationDate time.Time `human:"Creation Date" serialized:"creation_date"`
Name string `human:"Name" serialized:"name"`
Expand Down
2 changes: 1 addition & 1 deletion internal/flink/command_connection_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *command) connectionCreate(cmd *cobra.Command, args []string) error {
}

if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil {
return errors.NewErrorWithSuggestions(err.Error(), "List available environments with `confluent environment list`.")
return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId))
}

client, err := c.GetFlinkGatewayClient(false)
Expand Down
7 changes: 7 additions & 0 deletions internal/flink/command_connection_delete.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package flink

import (
"fmt"

"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/deletion"
"github.com/confluentinc/cli/v4/pkg/errors"
"github.com/confluentinc/cli/v4/pkg/resource"
)

Expand Down Expand Up @@ -35,6 +38,10 @@ func (c *command) connectionDelete(cmd *cobra.Command, args []string) error {
return err
}

if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil {
return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId))
}

client, err := c.GetFlinkGatewayClient(false)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions internal/flink/command_connection_describe.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package flink

import (
"fmt"

"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/errors"
"github.com/confluentinc/cli/v4/pkg/output"
)

Expand Down Expand Up @@ -33,6 +36,10 @@ func (c *command) connectionDescribe(cmd *cobra.Command, args []string) error {
return err
}

if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil {
return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId))
}

client, err := c.GetFlinkGatewayClient(false)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions internal/flink/command_connection_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/errors"
"github.com/confluentinc/cli/v4/pkg/flink"
"github.com/confluentinc/cli/v4/pkg/output"
"github.com/confluentinc/cli/v4/pkg/utils"
Expand Down Expand Up @@ -43,6 +44,10 @@ func (c *command) connectionList(cmd *cobra.Command, _ []string) error {
return err
}

if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil {
return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId))
}

connectionType, err := cmd.Flags().GetString("type")
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions internal/flink/command_connection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package flink

import (
"encoding/json"
"fmt"
"strings"

"github.com/spf13/cobra"

flinkgatewayv1 "github.com/confluentinc/ccloud-sdk-go-v2/flink-gateway/v1"

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/errors"
"github.com/confluentinc/cli/v4/pkg/examples"
"github.com/confluentinc/cli/v4/pkg/output"
)
Expand Down Expand Up @@ -46,6 +48,10 @@ func (c *command) connectionUpdate(cmd *cobra.Command, args []string) error {
return err
}

if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil {
return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId))
}

client, err := c.GetFlinkGatewayClient(false)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/auth/auth_token_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package auth
import (
"context"
"fmt"
"strings"
"time"

"github.com/pkg/browser"
Expand Down Expand Up @@ -230,7 +231,7 @@ func (a *AuthTokenHandlerImpl) checkSSOEmailMatchesLogin(client *ccloudv1.Client
if err != nil {
return err
}
if getMeReply.GetUser().GetEmail() != loginEmail {
if !strings.EqualFold(getMeReply.GetUser().GetEmail(), loginEmail) {
return errors.NewErrorWithSuggestions(
fmt.Sprintf("expected SSO credentials for %s but got credentials for %s", loginEmail, getMeReply.GetUser().GetEmail()),
"Please re-login and use the same email at the prompt and in the SSO portal.",
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/api_key_pair.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"runtime"
"strings"

"github.com/confluentinc/cli/v4/pkg/secret"
Expand All @@ -16,7 +15,7 @@ type APIKeyPair struct {
}

func (c *APIKeyPair) DecryptSecret() error {
if (strings.HasPrefix(c.Secret, secret.AesGcm) && c.Salt != nil) || runtime.GOOS == "windows" {
if (strings.HasPrefix(c.Secret, secret.AesGcm) && c.Salt != nil) || strings.HasPrefix(c.Secret, secret.Dpapi) {
decryptedSecret, err := secret.Decrypt(c.Key, c.Secret, c.Salt, c.Nonce)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error: 404 Not Found

Suggestions:
Failed to get environment 'env-dne'. List available environments with `confluent environment list`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error: 404 Not Found

Suggestions:
Failed to get environment 'env-dne'. List available environments with `confluent environment list`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error: 404 Not Found

Suggestions:
Failed to get environment 'env-dne'. List available environments with `confluent environment list`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error: 404 Not Found

Suggestions:
Failed to get environment 'env-dne'. List available environments with `confluent environment list`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error: 404 Not Found

Suggestions:
Failed to get environment 'env-dne'. List available environments with `confluent environment list`.
15 changes: 15 additions & 0 deletions test/flink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ func (s *CLITestSuite) TestFlinkConnection() {
}
}

func (s *CLITestSuite) TestFlinkConnectionWrongEnv() {
tests := []CLITest{
{args: "flink connection create my-connection --cloud aws --region eu-west-1 --type openai --endpoint https://api.openai.com/v1/chat/completions --api-key 0000000000000000 --environment env-dne", fixture: "flink/connection/create/create-wrong-env.golden", exitCode: 1},
{args: "flink connection describe my-connection --cloud aws --region eu-west-1 --environment env-dne", fixture: "flink/connection/describe/describe-wrong-env.golden", exitCode: 1},
{args: "flink connection list --cloud aws --region eu-west-1 --environment env-dne", fixture: "flink/connection/list/list-wrong-env.golden", exitCode: 1},
{args: "flink connection update my-connection --cloud aws --region eu-west-1 --api-key 0000000000000000 --environment env-dne", fixture: "flink/connection/update/update-wrong-env.golden", exitCode: 1},
{args: "flink connection delete my-connection --force --cloud aws --region eu-west-1 --environment env-dne", fixture: "flink/connection/delete/delete-wrong-env.golden", exitCode: 1},
}

for _, test := range tests {
test.login = "cloud"
s.runIntegrationTest(test)
}
}

func (s *CLITestSuite) TestFlinkConnectionDelete() {
tests := []CLITest{
{args: "flink connection delete my-connection --force --cloud aws --region eu-west-1", fixture: "flink/connection/delete/delete.golden"},
Expand Down

0 comments on commit 09f21d9

Please sign in to comment.