Skip to content

Commit

Permalink
Allow to specify a tanzu endpoint with no scheme (#811)
Browse files Browse the repository at this point in the history
tanzu login --endpoint api.tanzu.cloud.vmware.com
tanzu context create --endpoint api.tanzu.cloud.vmware.com

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam authored Sep 13, 2024
1 parent 0d8192a commit 565f847
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/command/login_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func isTanzuPlatformSaaSEndpoint(tpEndpoint string) bool {
return false
}

// If the url scheme is not provided by the user, default to using `https`
if !strings.HasPrefix(tpEndpoint, "http://") && !strings.HasPrefix(tpEndpoint, "https://") {
tpEndpoint = "https://" + tpEndpoint
}

saasEndpointRegularExpressions := centralconfig.DefaultCentralConfigReader.GetTanzuPlatformSaaSEndpointList()
for _, endpointRegex := range saasEndpointRegularExpressions {
// Create a regular expression pattern
Expand Down
6 changes: 6 additions & 0 deletions pkg/command/login_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ func TestIsTanzuPlatformSaaSEndpoint(t *testing.T) {
saasEndpointListInCentralConfig: []string{"https://tanzu.vmware.com"},
expected: true,
},
{
name: "valid SaaS endpoint without scheme",
tpEndpoint: "tanzu.vmware.com",
saasEndpointListInCentralConfig: []string{"https://tanzu.vmware.com"},
expected: true,
},
{
name: "invalid SaaS endpoint",
tpEndpoint: "https://example.com",
Expand Down

0 comments on commit 565f847

Please sign in to comment.