Skip to content

Commit

Permalink
Fix cloudBackendReference.String (#9240)
Browse files Browse the repository at this point in the history
* Fix new line

* Match default owner logic in String and Parse

* Add to CHANGELOG
  • Loading branch information
Frassle committed Mar 24, 2022
1 parent fadfac0 commit 7576c0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
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

0 comments on commit 7576c0a

Please sign in to comment.