Skip to content

Commit

Permalink
Remove type test from pulumi console (#9101)
Browse files Browse the repository at this point in the history
* Remove type test from `pulumi console`

Move ConsoleURL to just httpstate.Backend and don't type test on httpstate.Stack.

* Fix stack command

* Remove unused CloudURL on httpstate.Stack
  • Loading branch information
Frassle committed Apr 19, 2022
1 parent c850122 commit f629d53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
10 changes: 0 additions & 10 deletions pkg/backend/httpstate/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import (
// Stack is a cloud stack. This simply adds some cloud-specific properties atop the standard backend stack interface.
type Stack interface {
backend.Stack
CloudURL() string // the URL to the cloud containing this stack.
OrgName() string // the organization that owns this stack.
ConsoleURL() (string, error) // the URL to view the stack's information on Pulumi.com.
CurrentOperation() *apitype.OperationStatus // in progress operation, if applicable.
StackIdentifier() client.StackIdentifier
}
Expand Down Expand Up @@ -79,8 +77,6 @@ func (c cloudBackendReference) Name() tokens.Name {
type cloudStack struct {
// ref is the stack's unique name.
ref cloudBackendReference
// cloudURL is the URl to the cloud containing this stack.
cloudURL string
// orgName is the organization that owns this stack.
orgName string
// currentOperation contains information about any current operation being performed on the stack, as applicable.
Expand All @@ -102,7 +98,6 @@ func newStack(apistack apitype.Stack, b *cloudBackend) Stack {
name: tokens.Name(apistack.StackName.String()),
b: b,
},
cloudURL: b.CloudURL(),
orgName: apistack.OrgName,
currentOperation: apistack.CurrentOperation,
snapshot: nil, // We explicitly allocate the snapshot on first use, since it is expensive to compute.
Expand All @@ -112,7 +107,6 @@ func newStack(apistack apitype.Stack, b *cloudBackend) Stack {
}
func (s *cloudStack) Ref() backend.StackReference { return s.ref }
func (s *cloudStack) Backend() backend.Backend { return s.b }
func (s *cloudStack) CloudURL() string { return s.cloudURL }
func (s *cloudStack) OrgName() string { return s.orgName }
func (s *cloudStack) CurrentOperation() *apitype.OperationStatus { return s.currentOperation }
func (s *cloudStack) Tags() map[apitype.StackTagName]string { return s.tags }
Expand Down Expand Up @@ -187,10 +181,6 @@ func (s *cloudStack) ImportDeployment(ctx context.Context, deployment *apitype.U
return backend.ImportStackDeployment(ctx, s, deployment)
}

func (s *cloudStack) ConsoleURL() (string, error) {
return s.b.StackConsoleURL(s.ref)
}

// cloudStackSummary implements the backend.StackSummary interface, by wrapping
// an apitype.StackSummary struct.
type cloudStackSummary struct {
Expand Down
20 changes: 8 additions & 12 deletions pkg/cmd/pulumi/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func newConsoleCmd() *cobra.Command {
return err
}

ctx := commandContext()

// Do a type assertion in order to determine if this is a cloud backend based on whether the assertion
// succeeds or not.
cloudBackend, isCloud := currentBackend.(httpstate.Backend)
Expand All @@ -53,31 +55,25 @@ func newConsoleCmd() *cobra.Command {
if err != nil {
return err
}
selectedStack, err := currentBackend.GetStack(commandContext(), ref)
stack, err = currentBackend.GetStack(ctx, ref)
if err != nil {
return err
}
stack = selectedStack
} else {
currentStack, err := state.CurrentStack(commandContext(), currentBackend)
stack, err = state.CurrentStack(ctx, currentBackend)
if err != nil {
return err
}
stack = currentStack
}

// Open the stack specific URL (e.g. app.pulumi.com/{org}/{project}/{stack}) for this
// stack if a stack is selected and is a cloud stack, else open the cloud backend URL
// home page, e.g. app.pulumi.com.
if s, ok := stack.(httpstate.Stack); ok {
if consoleURL, err := s.ConsoleURL(); err == nil {
launchConsole(consoleURL)
} else {
// Open the cloud backend home page if retrieving the stack
// console URL fails.
launchConsole(cloudBackend.URL())
}
if consoleURL, err := cloudBackend.StackConsoleURL(stack.Ref()); err != nil {
launchConsole(consoleURL)
} else {
// Open the cloud backend home page if retrieving the stack
// console URL fails.
launchConsole(cloudBackend.URL())
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pulumi/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func newStackCmd() *cobra.Command {
}

// Add a link to the pulumi.com console page for this stack, if it has one.
if cs, ok := s.(httpstate.Stack); ok {
if consoleURL, err := cs.ConsoleURL(); err == nil {
if isCloud {
if consoleURL, err := cloudBe.StackConsoleURL(s.Ref()); err == nil {
fmt.Printf("\n")
fmt.Printf("More information at: %s\n", consoleURL)
}
Expand Down

0 comments on commit f629d53

Please sign in to comment.