From a8a4f88fd8c645191a87c74b435169e6315692b6 Mon Sep 17 00:00:00 2001 From: Aaron Friel Date: Wed, 16 Nov 2022 16:14:50 -0800 Subject: [PATCH 1/5] cli: Add fully qualified stack reference to pulumi about --- pkg/backend/backend.go | 3 +++ pkg/backend/filestate/backend.go | 5 ++++ pkg/backend/httpstate/stack.go | 4 +++ pkg/cmd/pulumi/about.go | 43 +++++++++++++++++++------------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/pkg/backend/backend.go b/pkg/backend/backend.go index de5c154fb4e6..ce2c82957e66 100644 --- a/pkg/backend/backend.go +++ b/pkg/backend/backend.go @@ -75,6 +75,9 @@ type StackReference interface { // name may not uniquely identify the stack (e.g. the cloud backend embeds owner information in the StackReference // but that information is not part of the StackName() we pass to the engine. Name() tokens.Name + + // Fully qualified name is the name + FullyQualifiedName() tokens.Name } // PolicyPackReference is an opaque type that refers to a PolicyPack managed by a backend. The CLI diff --git a/pkg/backend/filestate/backend.go b/pkg/backend/filestate/backend.go index 22d0f01652f1..f020f8288509 100644 --- a/pkg/backend/filestate/backend.go +++ b/pkg/backend/filestate/backend.go @@ -99,6 +99,11 @@ func (r localBackendReference) Name() tokens.Name { return r.name } +func (c localBackendReference) FullyQualifiedName() tokens.Name { + // TODO[pulumi/pulumi#11390]: Unable to provide this value until we solve this issue. + return tokens.Name("") +} + func IsFileStateBackendURL(urlstr string) bool { u, err := url.Parse(urlstr) if err != nil { diff --git a/pkg/backend/httpstate/stack.go b/pkg/backend/httpstate/stack.go index f9b97318dc20..0743f00caa16 100644 --- a/pkg/backend/httpstate/stack.go +++ b/pkg/backend/httpstate/stack.go @@ -74,6 +74,10 @@ func (c cloudBackendReference) Name() tokens.Name { return c.name } +func (c cloudBackendReference) FullyQualifiedName() tokens.Name { + return tokens.Name(fmt.Sprintf("%v/%v/%v", c.owner, c.project, c.name.String())) +} + // cloudStack is a cloud stack descriptor. type cloudStack struct { // ref is the stack's unique name. diff --git a/pkg/cmd/pulumi/about.go b/pkg/cmd/pulumi/about.go index 22156583d3ba..2f2d4c222dc9 100644 --- a/pkg/cmd/pulumi/about.go +++ b/pkg/cmd/pulumi/about.go @@ -86,16 +86,17 @@ type summaryAbout struct { // We use pointers here to allow the field to be nullable. When // constructing, we either fill in a field or add an error. We still // indicate that the field should be present when we serialize the struct. - Plugins []pluginAbout `json:"plugins"` - Host *hostAbout `json:"host"` - Backend *backendAbout `json:"backend"` - CurrentStack *currentStackAbout `json:"currentStack"` - CLI *cliAbout `json:"cliAbout"` - Runtime *projectRuntimeAbout `json:"runtime"` - Dependencies []programDependencyAbout `json:"dependencies"` - ErrorMessages []string `json:"errors"` - Errors []error `json:"-"` - LogMessage string `json:"-"` + Plugins []pluginAbout `json:"plugins"` + Host *hostAbout `json:"host"` + Backend *backendAbout `json:"backend"` + CurrentStack *currentStackAbout `json:"currentStack"` + CLI *cliAbout `json:"cliAbout"` + Runtime *projectRuntimeAbout `json:"runtime"` + Dependencies []programDependencyAbout `json:"dependencies"` + ErrorMessages []string `json:"errors"` + StackReference string `json:"stackReference"` + Errors []error `json:"-"` + LogMessage string `json:"-"` } func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedStack string) summaryAbout { @@ -188,6 +189,7 @@ func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedS tmp := getBackendAbout(backend) result.Backend = &tmp } + return result } @@ -330,9 +332,10 @@ func (b backendAbout) String() string { } type currentStackAbout struct { - Name string `json:"name"` - Resources []aboutState `json:"resources"` - PendingOps []aboutState `json:"pendingOps"` + Name string `json:"name"` + FullyQualifiedName string `json:"fullyQualifiedName"` + Resources []aboutState `json:"resources"` + PendingOps []aboutState `json:"pendingOps"` } type aboutState struct { @@ -386,9 +389,10 @@ func getCurrentStackAbout(ctx context.Context, b backend.Backend, selectedStack } } return currentStackAbout{ - Name: name, - Resources: aboutResources, - PendingOps: aboutPending, + Name: name, + FullyQualifiedName: stack.Ref().FullyQualifiedName().String(), + Resources: aboutResources, + PendingOps: aboutPending, }, nil } @@ -423,7 +427,12 @@ func (current currentStackAbout) String() string { Rows: rows, }.String() + "\n" } - return fmt.Sprintf("Current Stack: %s\n\n%s\n%s", current.Name, resources, pending) + return fmt.Sprintf(`Current Stack: %s + +Fully qualified stack name: %s + +%s +%s`, current.Name, current.FullyQualifiedName, resources, pending) } func simpleTableRows(arr [][]string) []cmdutil.TableRow { From 13139413d4dd46419a263a334109edb39d0c1ba5 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Thu, 17 Nov 2022 17:23:46 -0800 Subject: [PATCH 2/5] Add FQN for filestate and simply output --- pkg/backend/filestate/backend.go | 5 ++--- pkg/cmd/pulumi/about.go | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pkg/backend/filestate/backend.go b/pkg/backend/filestate/backend.go index f020f8288509..37e5283c0b89 100644 --- a/pkg/backend/filestate/backend.go +++ b/pkg/backend/filestate/backend.go @@ -99,9 +99,8 @@ func (r localBackendReference) Name() tokens.Name { return r.name } -func (c localBackendReference) FullyQualifiedName() tokens.Name { - // TODO[pulumi/pulumi#11390]: Unable to provide this value until we solve this issue. - return tokens.Name("") +func (r localBackendReference) FullyQualifiedName() tokens.Name { + return r.Name() } func IsFileStateBackendURL(urlstr string) bool { diff --git a/pkg/cmd/pulumi/about.go b/pkg/cmd/pulumi/about.go index 2f2d4c222dc9..754be9509273 100644 --- a/pkg/cmd/pulumi/about.go +++ b/pkg/cmd/pulumi/about.go @@ -86,17 +86,16 @@ type summaryAbout struct { // We use pointers here to allow the field to be nullable. When // constructing, we either fill in a field or add an error. We still // indicate that the field should be present when we serialize the struct. - Plugins []pluginAbout `json:"plugins"` - Host *hostAbout `json:"host"` - Backend *backendAbout `json:"backend"` - CurrentStack *currentStackAbout `json:"currentStack"` - CLI *cliAbout `json:"cliAbout"` - Runtime *projectRuntimeAbout `json:"runtime"` - Dependencies []programDependencyAbout `json:"dependencies"` - ErrorMessages []string `json:"errors"` - StackReference string `json:"stackReference"` - Errors []error `json:"-"` - LogMessage string `json:"-"` + Plugins []pluginAbout `json:"plugins"` + Host *hostAbout `json:"host"` + Backend *backendAbout `json:"backend"` + CurrentStack *currentStackAbout `json:"currentStack"` + CLI *cliAbout `json:"cliAbout"` + Runtime *projectRuntimeAbout `json:"runtime"` + Dependencies []programDependencyAbout `json:"dependencies"` + ErrorMessages []string `json:"errors"` + Errors []error `json:"-"` + LogMessage string `json:"-"` } func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedStack string) summaryAbout { @@ -427,12 +426,11 @@ func (current currentStackAbout) String() string { Rows: rows, }.String() + "\n" } - return fmt.Sprintf(`Current Stack: %s - -Fully qualified stack name: %s - -%s -%s`, current.Name, current.FullyQualifiedName, resources, pending) + stackName := current.Name + if stackName != current.FullyQualifiedName { + stackName += fmt.Sprintf(" (fully qualified to %q)", current.FullyQualifiedName) + } + return fmt.Sprintf("Current Stack: %s\n\n%s\n%s", stackName, resources, pending) } func simpleTableRows(arr [][]string) []cmdutil.TableRow { From 9f42366c89ba4661d929367e6ea3f3032f05d71f Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Thu, 17 Nov 2022 17:26:55 -0800 Subject: [PATCH 3/5] CL --- ...bout--add-fully-qualified-stack-name-to-current-stack.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/pending/20221118--cli-about--add-fully-qualified-stack-name-to-current-stack.yaml diff --git a/changelog/pending/20221118--cli-about--add-fully-qualified-stack-name-to-current-stack.yaml b/changelog/pending/20221118--cli-about--add-fully-qualified-stack-name-to-current-stack.yaml new file mode 100644 index 000000000000..0eb5cbba99a0 --- /dev/null +++ b/changelog/pending/20221118--cli-about--add-fully-qualified-stack-name-to-current-stack.yaml @@ -0,0 +1,4 @@ +changes: +- type: feat + scope: cli/about + description: Add fully qualified stack name to current stack. From f56c25c9335afe132c09d427df7ab1405ada8975 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Thu, 17 Nov 2022 17:29:16 -0800 Subject: [PATCH 4/5] Fix test --- pkg/cmd/pulumi/stack_ls_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/pulumi/stack_ls_test.go b/pkg/cmd/pulumi/stack_ls_test.go index 42c3a1dabd54..85f94f8a4933 100644 --- a/pkg/cmd/pulumi/stack_ls_test.go +++ b/pkg/cmd/pulumi/stack_ls_test.go @@ -82,6 +82,10 @@ func (msr *mockStackReference) Name() tokens.Name { return tokens.Name(msr.name) } +func (msr *mockStackReference) FullyQualifiedName() tokens.Name { + return msr.Name() +} + func (msr *mockStackReference) String() string { return msr.name } From 23608c2069b473599fbe1a4ae555cf2c6de6ab56 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Tue, 29 Nov 2022 14:07:03 -0800 Subject: [PATCH 5/5] Qualify name --- pkg/backend/backend.go | 4 ++-- pkg/backend/filestate/backend.go | 4 ++-- pkg/backend/httpstate/stack.go | 4 ++-- pkg/cmd/pulumi/about.go | 5 ++--- pkg/cmd/pulumi/stack_ls_test.go | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/backend/backend.go b/pkg/backend/backend.go index ce2c82957e66..495f7fa5a770 100644 --- a/pkg/backend/backend.go +++ b/pkg/backend/backend.go @@ -76,8 +76,8 @@ type StackReference interface { // but that information is not part of the StackName() we pass to the engine. Name() tokens.Name - // Fully qualified name is the name - FullyQualifiedName() tokens.Name + // Fully qualified name of the stack. + FullyQualifiedName() tokens.QName } // PolicyPackReference is an opaque type that refers to a PolicyPack managed by a backend. The CLI diff --git a/pkg/backend/filestate/backend.go b/pkg/backend/filestate/backend.go index 37e5283c0b89..a1abc41ad25a 100644 --- a/pkg/backend/filestate/backend.go +++ b/pkg/backend/filestate/backend.go @@ -99,8 +99,8 @@ func (r localBackendReference) Name() tokens.Name { return r.name } -func (r localBackendReference) FullyQualifiedName() tokens.Name { - return r.Name() +func (r localBackendReference) FullyQualifiedName() tokens.QName { + return r.Name().Q() } func IsFileStateBackendURL(urlstr string) bool { diff --git a/pkg/backend/httpstate/stack.go b/pkg/backend/httpstate/stack.go index 0743f00caa16..c2542915a764 100644 --- a/pkg/backend/httpstate/stack.go +++ b/pkg/backend/httpstate/stack.go @@ -74,8 +74,8 @@ func (c cloudBackendReference) Name() tokens.Name { return c.name } -func (c cloudBackendReference) FullyQualifiedName() tokens.Name { - return tokens.Name(fmt.Sprintf("%v/%v/%v", c.owner, c.project, c.name.String())) +func (c cloudBackendReference) FullyQualifiedName() tokens.QName { + return tokens.IntoQName(fmt.Sprintf("%v/%v/%v", c.owner, c.project, c.name.String())) } // cloudStack is a cloud stack descriptor. diff --git a/pkg/cmd/pulumi/about.go b/pkg/cmd/pulumi/about.go index 754be9509273..676fac6808bc 100644 --- a/pkg/cmd/pulumi/about.go +++ b/pkg/cmd/pulumi/about.go @@ -188,7 +188,6 @@ func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedS tmp := getBackendAbout(backend) result.Backend = &tmp } - return result } @@ -427,8 +426,8 @@ func (current currentStackAbout) String() string { }.String() + "\n" } stackName := current.Name - if stackName != current.FullyQualifiedName { - stackName += fmt.Sprintf(" (fully qualified to %q)", current.FullyQualifiedName) + if current.FullyQualifiedName != "" { + stackName = current.FullyQualifiedName } return fmt.Sprintf("Current Stack: %s\n\n%s\n%s", stackName, resources, pending) } diff --git a/pkg/cmd/pulumi/stack_ls_test.go b/pkg/cmd/pulumi/stack_ls_test.go index 85f94f8a4933..2152a2281535 100644 --- a/pkg/cmd/pulumi/stack_ls_test.go +++ b/pkg/cmd/pulumi/stack_ls_test.go @@ -82,8 +82,8 @@ func (msr *mockStackReference) Name() tokens.Name { return tokens.Name(msr.name) } -func (msr *mockStackReference) FullyQualifiedName() tokens.Name { - return msr.Name() +func (msr *mockStackReference) FullyQualifiedName() tokens.QName { + return msr.Name().Q() } func (msr *mockStackReference) String() string {