Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable customization of org id and name when connecting to uaa-base endpoint #804

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
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
Loading