Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
// Generate documentation for both subsets of commands: cloud and on-prem
configs := []*config.Config{
{CurrentContext: "Cloud", Contexts: map[string]*config.Context{"Cloud": {PlatformName: "https://confluent.cloud"}}},
{CurrentContext: "On-Premises", Contexts: map[string]*config.Context{"On-Premises": {PlatformName: "https://example.com"}}},
{CurrentContext: "Confluent Platform", Contexts: map[string]*config.Context{"Confluent Platform": {PlatformName: "https://example.com"}}},
}

tabs := make([]docs.Tab, len(configs))
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.26.5

require (
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.54.15
github.com/aws/aws-sdk-go-v2 v1.26.1
github.com/billgraziano/dpapi v0.5.0
github.com/bradleyjkemp/cupaloy/v2 v2.8.0
github.com/brianstrauch/cobra-shell v0.5.0
Expand Down Expand Up @@ -145,7 +145,6 @@ require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.10 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.54.15 h1:ErgCEVbzuSfuZl9nR+g8FFnzjgeJ/AqAGOEWn6tgAHo=
github.com/aws/aws-sdk-go v1.54.15/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/config v1.27.10 h1:PS+65jThT0T/snC5WjyfHHyUgG+eBoupSDV+f838cro=
Expand Down
2 changes: 1 addition & 1 deletion internal/byok/command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/spf13/cobra"

byokv1 "github.com/confluentinc/ccloud-sdk-go-v2/byok/v1"
Expand Down
29 changes: 29 additions & 0 deletions internal/byok/command_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ import (
"github.com/stretchr/testify/require"
)

func TestIsAWSKey(t *testing.T) {
tests := []struct {
name string
input string
expected bool
}{
{
name: "valid AWS KMS key ARN",
input: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
expected: true,
},
{
name: "valid ARN for a non-KMS service",
input: "arn:aws:iam::111122223333:user/David",
expected: false,
},
{
name: "not an ARN at all",
input: "projects/my-project/locations/global/keyRings/my-key-ring/cryptoKeys/my-key",
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.expected, isAWSKey(test.input))
})
}
}

func TestRemoveKeyVersionFromAzureKeyId(t *testing.T) {
tests := []struct {
name string
Expand Down
18 changes: 12 additions & 6 deletions internal/login/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,23 @@ func validateURL(url string, isCCloud bool) (string, string, error) {
msg = append(msg, "default MDS port 8090")
}

var pattern *regexp.Regexp
if isCCloud {
pattern = regexp.MustCompile(`^\w+://[^/ ]+`)
} else {
pattern = regexp.MustCompile(`^\w+://[^/ ]+:\d+(?:\/|$)`)
pattern := regexp.MustCompile(`^\w+://[^/ ]+`)
if !pattern.MatchString(url) {
return "", "", fmt.Errorf(errors.InvalidLoginURLErrorMsg)
}
return url, strings.Join(msg, " and "), nil
}
if !pattern.MatchString(url) {

// discard any path after the host:port, so a trailing path (e.g. copied from a browser address
// bar) doesn't get baked into the base URL used for every subsequent request
pattern := regexp.MustCompile(`^(\w+://[^/ ]+:\d+)(?:/|$)`)
matches := pattern.FindStringSubmatch(url)
if matches == nil {
return "", "", fmt.Errorf(errors.InvalidLoginURLErrorMsg)
}

return url, strings.Join(msg, " and "), nil
return matches[1], strings.Join(msg, " and "), nil
}

func (c *command) getOrganizationId(cmd *cobra.Command) string {
Expand Down
12 changes: 12 additions & 0 deletions internal/login/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,18 @@ func TestValidateUrl(t *testing.T) {
urlOut: "https://127.0.0.1:8090",
warningMsg: "",
},
{
// trailing path must be stripped, not baked into the base URL
urlIn: "https://infra.confluentgov.internal.com:8090/login",
urlOut: "https://infra.confluentgov.internal.com:8090",
warningMsg: "",
},
{
urlIn: "infra.confluentgov.internal.com/login",
urlOut: "",
warningMsg: "https protocol and default MDS port 8090",
errMsg: errors.InvalidLoginURLErrorMsg,
},
{
urlIn: "127.0.0.1",
urlOut: "https://127.0.0.1:8090",
Expand Down