diff --git a/.changelog/122.txt b/.changelog/122.txt new file mode 100644 index 00000000..89e6ae7a --- /dev/null +++ b/.changelog/122.txt @@ -0,0 +1,3 @@ +```release-note:improvement +Run auto-detection of organization ID even if project ID is configured in the profile. +``` diff --git a/main.go b/main.go index 6710240e..678094d9 100644 --- a/main.go +++ b/main.go @@ -188,10 +188,10 @@ func loadProfile(ctx context.Context, iam iam_service.ClientService, tokenSource } } - // If the profile has an org/project, or we don't have a valid access + // If the profile has an org, or we don't have a valid access // token, skip trying to infer the organization and project. tkn, err := tokenSource.Token() - if p.OrganizationID != "" || p.ProjectID != "" || err != nil || !tkn.Expiry.After(time.Now()) { + if p.OrganizationID != "" || err != nil || !tkn.Expiry.After(time.Now()) { return p, nil } @@ -210,9 +210,13 @@ func loadProfile(ctx context.Context, iam iam_service.ClientService, tokenSource return p, nil } - // Set the organization and project. Project may be empty. + // Set the organization. p.OrganizationID = ident.Payload.Principal.Service.OrganizationID - p.ProjectID = ident.Payload.Principal.Service.ProjectID + + // Only set the project if it is not already set. + if p.ProjectID == "" { + p.ProjectID = ident.Payload.Principal.Service.ProjectID + } // Save the profile. if err := p.Write(); err != nil {