Skip to content

Commit

Permalink
Small update to address issues after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Vui Lam <[email protected]>
  • Loading branch information
vuil committed Aug 29, 2024
1 parent 5d0bff2 commit 8b7729a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,6 @@ github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502eb
github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502ebf68/go.mod h1:e1Uef+Ux5BIHpYwqbeP2ZZmOzehBcez2vUEWXHe+xHE=
github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686 h1:VcuXqUXFxm5WDqWkzAlU/6cJXua0ozELnqD59fy7J6E=
github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686/go.mod h1:AFGOXZD4tH+KhpmtV0VjWjllXhr8y57MvOsIxTtywc4=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240808182155-de610f924174 h1:kWNCfWtzeltbFB0adAvIjuFq/27cH1duYktNSmpya3Y=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240808182155-de610f924174/go.mod h1:0fTB0rR9BX9kS+xGcwH9O0p97bn8rSdILwWCHgvXzkw=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240827202155-221feaade1a9 h1:C3XAyciRJTICEa4H0eUZJYprZvf6nCquSfZbBKNwH5w=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240827202155-221feaade1a9/go.mod h1:0fTB0rR9BX9kS+xGcwH9O0p97bn8rSdILwWCHgvXzkw=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240828225551-9dd9ce28e85e h1:WlMLdfI1PigZ/2X0GXv2s7uP+DpRBcdVxkSr9hYHnkU=
github.com/vmware-tanzu/tanzu-plugin-runtime v1.5.0-dev.0.20240828225551-9dd9ce28e85e/go.mod h1:0fTB0rR9BX9kS+xGcwH9O0p97bn8rSdILwWCHgvXzkw=
github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEGw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getString(data interface{}) string {
// pre-req orgName and endpoint is non-empty string
func prepareTanzuContextName(orgName, ucpEndpoint string, isStaging bool) string {
var contextName string
idpType := getIDPType(endpoint)
idpType := getIDPType(ucpEndpoint)
if idpType == config.UAAIdpType {
contextName = "tpsm"
} else {
Expand Down
17 changes: 12 additions & 5 deletions pkg/command/login_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ func configureTanzuPlatformServiceEndpointsForSM(tpEndpoint string) error {
// tanzu platform url used for UI directly. In this can remove `www.` prefix.
u.Host = strings.TrimPrefix(u.Host, "www.")

tanzuHubEndpoint = fmt.Sprintf("%s://%s/hub/hub", u.Scheme, u.Host)
tanzuTMCEndpoint = fmt.Sprintf("%s://%s/ops", u.Scheme, u.Host)
tanzuHubEndpoint = fmt.Sprintf("%s://%s/hub", u.Scheme, u.Host)
tanzuTMCEndpoint = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
tanzuUCPEndpoint = fmt.Sprintf("%s://%s/ucp", u.Scheme, u.Host)
tanzuAuthEndpoint = fmt.Sprintf("%s://%s/auth", u.Scheme, u.Host)
if strings.Contains(u.Host, "localhost") || strings.Contains(u.Host, "127.0.0.1") {
tanzuAuthEndpoint = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
}

return nil
}
Expand All @@ -112,8 +109,18 @@ func isTanzuPlatformSaaSEndpoint(tpEndpoint string) bool {
if tpEndpoint == "" {
return false
}

defaultSaaSEndpoints := []string{
"https://(www.)?platform(.)*.tanzu.broadcom.com",
"https://api.tanzu(.)*.cloud.vmware.com",
}
saasEndpointRegularExpressions, _ := centralconfig.DefaultCentralConfigReader.GetTanzuPlatformSaaSEndpointList()
saasEndpointRegularExpressions = append(saasEndpointRegularExpressions, defaultSaaSEndpoints...)

for _, endpointRegex := range saasEndpointRegularExpressions {
if endpointRegex == "" {
continue
}
// Create a regular expression pattern
re, err := regexp.Compile(endpointRegex)
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions pkg/command/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestPrepareTanzuContextName(t *testing.T) {
orgName string
endpoint string
isStaging bool
forceCSP bool
expected string
}{
// Test case for normal input with no staging environment and default endpoint.
Expand All @@ -29,23 +30,34 @@ func TestPrepareTanzuContextName(t *testing.T) {
isStaging: true,
expected: "MyOrg-staging",
},
// Test case for normal input with no staging environment and custom endpoint.
// Test case for normal input with no staging environment and custom SaaS endpoint.
{
orgName: "MyOrg",
endpoint: "https://custom-endpoint.com",
isStaging: false,
expected: "MyOrg-86fd8133",
forceCSP: true,
},
// Test case for normal input with staging environment and custom endpoint.
// Test case for normal input with staging environment and custom SaaS endpoint.
{
orgName: "MyOrg",
endpoint: "https://custom-endpoint.com",
isStaging: true,
expected: "MyOrg-staging-86fd8133",
forceCSP: true,
},
// Test case for normal input with no staging environment and custom SaaS endpoint.
{
// org and staging values are effectively ignored
orgName: "MyOrg",
isStaging: true,
endpoint: "https://custom-endpoint.com",
expected: "tpsm-86fd8133",
},
}

for _, tc := range testCases {
forceCSP = tc.forceCSP
actual := prepareTanzuContextName(tc.orgName, tc.endpoint, tc.isStaging)
if actual != tc.expected {
t.Errorf("orgName: %s, endpoint: %s, isStaging: %t - expected: %s, got: %s", tc.orgName, tc.endpoint, tc.isStaging, tc.expected, actual)
Expand Down

0 comments on commit 8b7729a

Please sign in to comment.