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

Fix cloudBackendReference.String #9240

Merged
merged 6 commits into from Mar 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG_PENDING.md
Expand Up @@ -39,6 +39,9 @@

- [cli/engine] - Fix a panic due to passing `""` as the ID for a resource read.
[#9243](https://github.com/pulumi/pulumi/pull/9243)

- [cli/engine] - Fix a panic due to `Check` failing while using update plans.
[#9254](https://github.com/pulumi/pulumi/pull/9254)
[#9254](https://github.com/pulumi/pulumi/pull/9254)

- [cli] - Stack names correctly take `org set-default` into account when printing.
[#9240](https://github.com/pulumi/pulumi/pull/9240)
21 changes: 14 additions & 7 deletions pkg/backend/httpstate/stack.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
)

// Stack is a cloud stack. This simply adds some cloud-specific properties atop the standard backend stack interface.
Expand All @@ -48,15 +49,21 @@ type cloudBackendReference struct {
}

func (c cloudBackendReference) String() string {
curUser, err := c.b.CurrentUser()
if err != nil {
curUser = ""
}

// If the project names match, we can elide them.
if c.b.currentProject != nil && c.project == string(c.b.currentProject.Name) {
if c.owner == curUser {
return string(c.name) // Elide owner too, if it is the current user.

// Elide owner too, if it is the default owner.
defaultOrg, err := workspace.GetBackendConfigDefaultOrg()
if err == nil && defaultOrg != "" {
// The default owner is the org
if c.owner == defaultOrg {
return string(c.name)
}
} else {
currentUser, userErr := c.b.CurrentUser()
if userErr == nil && c.owner == currentUser {
return string(c.name)
}
}
return fmt.Sprintf("%s/%s", c.owner, c.name)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/org.go
Expand Up @@ -46,7 +46,7 @@ func newOrgCmd() *cobra.Command {

fmt.Printf("Current Backend: %s\n", cloudURL)
if defaultOrg != "" {
fmt.Printf("Default Org: %s", defaultOrg)
fmt.Printf("Default Org: %s\n", defaultOrg)
} else {
fmt.Println("No Default Org Specified")
}
Expand Down