pulumi/pkg/backend/local/stack.go
joeduffy 2eb86b24c2 Make some updates based on CR feedback
This change implements some feedback from @ellismg.

* Make backend.Stack an interface and let backends implement it,
  enabling dynamic type testing/casting to access information
  specific to that backend.  For instance, the cloud.Stack conveys
  the cloud URL, org name, and PPC name, for each stack.

* Similarly expose specialized backend.Backend interfaces,
  local.Backend and cloud.Backend, to convey specific information.

* Redo a bunch of the commands in terms of these.

* Keeping with this theme, turn the CreateStack options into an
  opaque interface{}, and let the specific backends expose their
  own structures with their own settings (like PPC name in cloud).

* Show both the org and PPC names in the cloud column printed in
  the stack ls command, in addition to the Pulumi Cloud URL.

Unrelated, but useful:

* Special case the 401 HTTP response and make a friendly error,
  to tell the developer they must use `pulumi login`.  This is
  better than tossing raw "401: Unauthorized" errors in their face.

* Change the "Updating stack '..' in the Pulumi Cloud" message to
  use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 08:10:50 -08:00

64 lines
2.1 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package local
import (
"github.com/pulumi/pulumi/pkg/backend"
"github.com/pulumi/pulumi/pkg/engine"
"github.com/pulumi/pulumi/pkg/operations"
"github.com/pulumi/pulumi/pkg/resource/config"
"github.com/pulumi/pulumi/pkg/resource/deploy"
"github.com/pulumi/pulumi/pkg/tokens"
)
// Stack is a local stack. This simply adds some local-specific properties atop the standard backend stack interface.
type Stack interface {
backend.Stack
Path() string // a path to the stack's checkpoint file on disk.
}
// localStack is a local stack descriptor.
type localStack struct {
name tokens.QName // the stack's name.
path string // a path to the stack's checkpoint file on disk.
config config.Map // the stack's config bag.
snapshot *deploy.Snapshot // a snapshot representing the latest deployment state.
b *localBackend // a pointer to the backend this stack belongs to.
}
func newStack(name tokens.QName, path string, config config.Map,
snapshot *deploy.Snapshot, b *localBackend) Stack {
return &localStack{
name: name,
path: path,
config: config,
snapshot: snapshot,
b: b,
}
}
func (s *localStack) Name() tokens.QName { return s.name }
func (s *localStack) Config() config.Map { return s.config }
func (s *localStack) Snapshot() *deploy.Snapshot { return s.snapshot }
func (s *localStack) Backend() backend.Backend { return s.b }
func (s *localStack) Path() string { return s.path }
func (s *localStack) Remove(force bool) (bool, error) {
return backend.RemoveStack(s, force)
}
func (s *localStack) Preview(debug bool, opts engine.PreviewOptions) error {
return backend.PreviewStack(s, debug, opts)
}
func (s *localStack) Update(debug bool, opts engine.DeployOptions) error {
return backend.UpdateStack(s, debug, opts)
}
func (s *localStack) Destroy(debug bool, opts engine.DestroyOptions) error {
return backend.DestroyStack(s, debug, opts)
}
func (s *localStack) GetLogs(query operations.LogQuery) ([]operations.LogEntry, error) {
return backend.GetStackLogs(s, query)
}