Skip to content

Commit

Permalink
Enable customization of org id and name when connecting to uaa-based …
Browse files Browse the repository at this point in the history
…endpoint

Also: update the ucp url to the correct one for uaa-based endpoints

Signed-off-by: Vui Lam <[email protected]>
  • Loading branch information
vuil committed Sep 4, 2024
1 parent 48d2e12 commit aa76610
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
17 changes: 15 additions & 2 deletions pkg/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,21 @@ func globalTanzuLoginUAA(c *configtypes.Context, generateContextNameFunc func(or
return err
}

// UAA-based authentication does not provide org id or name yet
orgName := ""
// UAA-based authentication does not provide org id or name yet.
// Note: org id/name may be discoverable in UAA-based auth in the future.
var orgID string
orgName := "self-managed"
uaaOrgIDValue, ok := os.LookupEnv(constants.UAALoginOrgID)
if ok {
orgID = uaaOrgIDValue
}
claims.OrgID = orgID
uaaOrgNameValue, ok := os.LookupEnv(constants.UAALoginOrgName)
if ok {
orgName = uaaOrgNameValue
} else if orgID != "" {
orgName = orgID
}

if err := updateContextOnTanzuLogin(c, generateContextNameFunc, claims, orgName); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions pkg/command/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ var _ = Describe("create new context", func() {
fakeTanzuEndpoint = "https://fake.tanzu.cloud.vmware.com"
fakeAlternateTanzuEndpoint = "https://fake.acme.com"
expectedAlternateTanzuHubEndpoint = "https://fake.acme.com/hub"
expectedAlternateTanzuUCPEndpoint = "https://fake.acme.com/ucp"
expectedAlternateTanzuUCPEndpoint = "https://fake.acme.com"
expectedAlternateTanzuTMCEndpoint = "https://fake.acme.com"

expectedTanzuHubEndpoint = "https://api.fake.tanzu.cloud.vmware.com/hub"
Expand Down Expand Up @@ -1156,7 +1156,6 @@ var _ = Describe("create new context", func() {
Expect(string(idpType)).To(ContainSubstring("uaa"))
})
})

Context("context name already exists", func() {
It("should return error", func() {
endpoint = fakeTanzuEndpoint
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/login_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func configureTanzuPlatformServiceEndpointsForSM(tpEndpoint string) error {

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)
tanzuUCPEndpoint = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
tanzuAuthEndpoint = fmt.Sprintf("%s://%s/auth", u.Scheme, u.Host)

return nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/constants/env_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ const (
// https://docs.vmware.com/en/VMware-Cloud-services/services/Using-VMware-Cloud-Services/GUID-CF9E9318-B811-48CF-8499-9419997DC1F8.html
CSPLoginOrgID = "TANZU_CLI_CLOUD_SERVICES_ORGANIZATION_ID"

// UaaLoginOrgID overrides OrgID associated with the UAA based endpoint
// This may not be necessary or could be discoverable in the future, at which point this will be ignored.
UAALoginOrgID = "TANZU_CLI_SM_ORGANIZATION_ID"

// UaaLoginOrgName overrides name of the Org associated with the UAA based endpoint
// This may not be necessary or could be discoverable in the future, at which point this will be ignored.
UAALoginOrgName = "TANZU_CLI_SM_ORGANIZATION_NAME"

// TanzuCLIOAuthLocalListenerPort is the port to be used by local listener for OAuth authorization flow
TanzuCLIOAuthLocalListenerPort = "TANZU_CLI_OAUTH_LOCAL_LISTENER_PORT"

Expand Down

0 comments on commit aa76610

Please sign in to comment.