Skip to content

Commit d4c8de3

Browse files
authored
Fix an issue where otterize-cli login would fail on users belonging to multiple organizations (#176)
1 parent 1d0ead2 commit d4c8de3

File tree

5 files changed

+118
-31
lines changed

5 files changed

+118
-31
lines changed

src/pkg/cloudclient/graphql/schema.graphql

Lines changed: 36 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pkg/cloudclient/login/userlogin/userlogin.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (loginCtx *LoginContext) EnsureUserRegistered() error {
6363
}
6464

6565
func (loginCtx *LoginContext) SelectOrg(preSelectedOrgId string, switchOrg bool) (string, error) {
66-
organizations := loginCtx.me.Organizations
66+
organizations := loginCtx.me.UserOrganizations
6767
selectedOrg := ""
6868
if len(organizations) == 0 {
6969
orgId, err := loginCtx.createOrJoinOrgFromUserInput()
@@ -73,7 +73,7 @@ func (loginCtx *LoginContext) SelectOrg(preSelectedOrgId string, switchOrg bool)
7373
selectedOrg = orgId
7474
} else if len(organizations) == 1 {
7575
prints.PrintCliStderr("Only 1 organization found - auto-selecting this organization for use.")
76-
selectedOrg = organizations[0].Id
76+
selectedOrg = organizations[0].Org.Id
7777
} else {
7878
orgId, err := loginCtx.interactiveSelectOrg(preSelectedOrgId, switchOrg)
7979
if err != nil {
@@ -161,7 +161,9 @@ func (loginCtx *LoginContext) createNewOrg() (string, error) {
161161
}
162162

163163
func (loginCtx *LoginContext) interactiveSelectOrg(preSelectedOrgId string, switchOrg bool) (string, error) {
164-
organizations := loginCtx.me.Organizations
164+
organizations := lo.Map(loginCtx.me.UserOrganizations, func(userOrg cloudapi.UserOrganizationAssociation, _ int) cloudapi.Organization {
165+
return userOrg.Org
166+
})
165167

166168
prints.PrintCliStderr("You belong to the following organizations:")
167169
output.FormatOrganizations(organizations)

src/pkg/cloudclient/restapi/cloudapi/api.gen.go

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pkg/cloudclient/restapi/cloudapi/openapi.json

Lines changed: 25 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pkg/mapperclient/schema.graphql

Lines changed: 49 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)