resource

package
Version: v0.0.0-...-215933a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStatusCantChange is returned when an error is not set but the level is
	// StatusCantChange
	ErrStatusCantChange = errors.New("resource cannot change because of an error")

	// ErrStatusFatal is returned when an error is not set but the level is
	// StatusFatal
	ErrStatusFatal = errors.New("resource encountered an error")
)

error messages

Functions

func AddTextDiff

func AddTextDiff(m map[string]Diff, name, original, current, defaultVal string) map[string]Diff

AddTextDiff inserts a new TextDiff into a map of names to Diffs

func AnyChanges

func AnyChanges(diffs map[string]Diff) bool

AnyChanges takes a diff map and returns true if any of the diffs in the map have changes.

Types

type Diff

type Diff interface {
	Original() string
	Current() string
	Changes() bool
}

Diff represents a difference

type HealthStatus

type HealthStatus struct {
	TaskStatus
	WarningLevel HealthStatusCode
	DisplayLevel *HealthStatusCode
	FailingDeps  map[string]string
}

HealthStatus contains a status level, display threshold, and status message

func (*HealthStatus) Changes

func (h *HealthStatus) Changes() map[string]Diff

Changes returns changes from the underlying TaskStatus diffs

func (*HealthStatus) Error

func (h *HealthStatus) Error() error

Error returns nil on success. If the health checks or it's dedencies are failing an appropriate error is returned.

func (*HealthStatus) HasChanges

func (h *HealthStatus) HasChanges() bool

HasChanges returns true if the status indicates that there are changes

func (*HealthStatus) HasFailingDeps

func (h *HealthStatus) HasFailingDeps() bool

HasFailingDeps returns true of FailingDeps is not empty

func (*HealthStatus) IsError

func (h *HealthStatus) IsError() bool

IsError returns true if the warning level is StatusError

func (*HealthStatus) IsWarning

func (h *HealthStatus) IsWarning() bool

IsWarning returns true if the warning level is StatusWarning

func (*HealthStatus) Messages

func (h *HealthStatus) Messages() []string

Messages returns health status messages

func (*HealthStatus) ShouldDisplay

func (h *HealthStatus) ShouldDisplay() bool

ShouldDisplay returns true if the warning level is at least the display level

func (*HealthStatus) UpgradeWarning

func (h *HealthStatus) UpgradeWarning(level HealthStatusCode)

UpgradeWarning will increase the warning level to at least `level`, but will not decrease it if it's already higher.

type HealthStatusCode

type HealthStatusCode int

HealthStatusCode is a status indicator for health level. It should be one of:

StatusHealth
StatusWarning
StatusError
const (
	// StatusHealthy indicates a passing health check
	StatusHealthy HealthStatusCode = iota
	// StatusWarning indicates a change is needed
	StatusWarning
	// StatusError indicates that a module is non-functional
	StatusError
)

type Preparer

type Preparer struct {
	Source      map[string]interface{}
	Destination Resource
}

Preparer wraps and implements resource.Resource in order to deserialize into regular Preparers

func NewPreparer

func NewPreparer(r Resource) *Preparer

NewPreparer wraps a given resource in this preparer

func NewPreparerWithSource

func NewPreparerWithSource(r Resource, source map[string]interface{}) *Preparer

NewPreparerWithSource creates a new preparer with the source included

func (*Preparer) Prepare

func (p *Preparer) Prepare(r Renderer) (Task, error)

Prepare the destination to prepare itself.

type Renderer

type Renderer interface {
	GetID() string
	Value() (value string, present bool)
	Render(name, content string) (string, error)
}

Renderer is passed to resources

type Resource

type Resource interface {
	Prepare(Renderer) (Task, error)
}

Resource adds metadata about the executed tasks

type Status

type Status struct {
	// Differences contains the things that will change as a part of this
	// Status. This will be used almost exclusively in the Check phase of
	// operations on resources. Use `NewStatus` to get a Status with this
	// initialized properly.
	Differences map[string]Diff

	// Output is the human-consumable fields on this struct. Output will be
	// returned as the Status' messages
	Output []string

	// Level indicates the change level of the status. Level is a gradation (see
	// the Status* contsts above.)
	Level StatusLevel
	// contains filtered or unexported fields
}

Status is the default TaskStatus implementation

func NewStatus

func NewStatus() *Status

NewStatus returns a Status with all fields initialized

func (*Status) AddDifference

func (t *Status) AddDifference(name, original, current, defaultVal string)

AddDifference adds a TextDiff to the Differences map

func (*Status) AddMessage

func (t *Status) AddMessage(message ...string)

AddMessage adds a human-readable message(s) to the output

func (*Status) Diffs

func (t *Status) Diffs() map[string]Diff

Diffs returns the internal differences

func (*Status) Error

func (t *Status) Error() error

Error returns an error, if set. If the level is StatusCantChange or StatusFatal and an error is not set, Error will generate an appropriate error message.

func (*Status) FailingDep

func (t *Status) FailingDep(id string, stat TaskStatus)

FailingDep tracks a new failing dependency

func (*Status) HasChanges

func (t *Status) HasChanges() bool

HasChanges returns the WillChange value

func (*Status) HealthCheck

func (t *Status) HealthCheck() (status *HealthStatus, err error)

HealthCheck provides a default health check implementation for statuses

func (*Status) Messages

func (t *Status) Messages() []string

Messages returns the current output slice

func (*Status) RaiseLevel

func (t *Status) RaiseLevel(level StatusLevel)

RaiseLevel raises the status level to the given level

func (*Status) SetError

func (t *Status) SetError(err error)

SetError sets an error on a status

func (*Status) StatusCode

func (t *Status) StatusCode() StatusLevel

StatusCode returns the current warning level

type StatusLevel

type StatusLevel uint32

StatusLevel will be used as a level in Status. It indicates if a resource needs to be changed, as well as fatal conditions.

const (
	// StatusNoChange means no changes are necessary. This status signals that
	// execution of dependent resources can continue.
	StatusNoChange StatusLevel = iota

	// StatusWontChange indicates an acceptable delta that wont be corrected.
	// This status signals that execution of dependent resources can continue.
	StatusWontChange

	// StatusWillChange indicates an unacceptable delta that will be corrected.
	// This status signals that execution of dependent resources can continue.
	StatusWillChange

	// StatusCantChange indicates an unacceptable delta that can't be corrected.
	// This is just like StatusFatal except the user will see that the resource
	// needs to change, but can't because of the condition specified in your
	// messaging. This status halts execution of dependent resources.
	StatusCantChange

	// StatusFatal indicates an error. This is just like StatusCantChange except
	// it does not imply that there are changes to be made. This status halts
	// execution of dependent resources.
	StatusFatal
)

func (StatusLevel) String

func (l StatusLevel) String() string

type Task

type Task interface {
	Check(Renderer) (TaskStatus, error)
	Apply() (TaskStatus, error)
}

Task controls checks and application inside the system. Check will be called first; if it indicates changes will be made then Apply will also be called. Check will be called again if Apply succeeds with no error to get the final status of the resource.

func ResolveTask

func ResolveTask(w interface{}) (Task, bool)

ResolveTask unwraps Tasker layers until it finds an underlying Task or fails

type TaskStatus

type TaskStatus interface {
	Diffs() map[string]Diff
	StatusCode() StatusLevel
	Messages() []string
	HasChanges() bool
	Error() error
}

TaskStatus represents the results of Check called during planning or application.

type TaskWrapper

type TaskWrapper struct {
	Task
}

TaskWrapper provides an implementation of render.Tasker for tasks

func WrapTask

func WrapTask(t Task) *TaskWrapper

WrapTask creates a new TaskWrapper

func (*TaskWrapper) GetTask

func (t *TaskWrapper) GetTask() (Task, bool)

GetTask provides Tasker.GetTask ontop of a task

type Tasker

type Tasker interface {
	GetTask() (Task, bool)
}

Tasker is a struct that is or contains an embedded resource.Task

type TextDiff

type TextDiff struct {
	Default string
	Values  [2]string
}

TextDiff is the default Diff implementation

func (TextDiff) Changes

func (t TextDiff) Changes() bool

Changes is true if the Original and Current values differ

func (TextDiff) Current

func (t TextDiff) Current() string

Current returns the modified value of the diff

func (TextDiff) Original

func (t TextDiff) Original() string

Original returns the unmodified value of the diff

type ThunkTask

type ThunkTask struct {
	Name        string
	ThunkedType Task
}

ThunkTask represents an abstract task over a thunk, used when we need to serialized a thunked value.

func NewThunkedTask

func NewThunkedTask(name string, thunkedType Task) *ThunkTask

NewThunkedTask generates a ThunkTask from a PrepareThunk

func (*ThunkTask) Apply

func (t *ThunkTask) Apply() (TaskStatus, error)

Apply returns a task status with thunk information

func (*ThunkTask) Check

func (t *ThunkTask) Check(Renderer) (TaskStatus, error)

Check returns a task status with thunk information

func (*ThunkTask) ToStatus

func (t *ThunkTask) ToStatus() *Status

ToStatus converts a ThunkStatus to a *Status

Directories

Path Synopsis
file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL