handler

package
v0.1.0-techpreview1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const TerraformProviderFake = "fake-sync"

TerraformProviderFake is the name of a fake Terraform provider

View Source
const (
	// TerraformProviderPanos is the name of a Palo Alto PANOS Terraform provider.
	TerraformProviderPanos = "panos"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake is the handler for out-of-band actions for a fake Terraform provider. Intended to be used for testing and examples.

func NewFake

func NewFake(config map[string]interface{}) (*Fake, error)

NewFake configures and returns a new fake handler

func (*Fake) Do

func (h *Fake) Do(prevErr error) error

Do executes fake handler, which fmt.Print-s the fake handler's name which is the output inspected by handler example. It returns an error if configured to do so.

func (*Fake) SetNext

func (h *Fake) SetNext(next Handler)

SetNext sets the next handler that should be called

type Handler

type Handler interface {

	// Do executes the handler. Receives previous error and returns previous
	// error wrapped in any new errors.
	Do(error) error

	// SetNext sets the next handler that should be called
	SetNext(Handler)
}

Handler handles additional actions that need to be executed. These can be at any level. Handlers can be chained such that they execute and continue to the next handler. A chain of handlers will return an aggregate of any errors after the handlers are all executed.

func TerraformProviderHandler

func TerraformProviderHandler(providerName string, config interface{}) (Handler, error)

TerraformProviderHandler returns the handler for providers that require post-Apply, out-of-band actions for a Terraform driver.

Returned handler may be nil even if returned err is nil. This happens when no providers have a handler.

Example
providers := make([]map[string]interface{}, 0)

fourth := make(map[string]interface{})
fourth[TerraformProviderFake] = map[string]interface{}{
	"name": "4",
	"err":  true,
}
providers = append(providers, fourth)

third := make(map[string]interface{})
third[TerraformProviderFake] = map[string]interface{}{
	"name": "3",
}
providers = append(providers, third)

second := make(map[string]interface{})
second[TerraformProviderFake] = map[string]interface{}{
	"name": "2",
	"err":  true,
}
providers = append(providers, second)

first := make(map[string]interface{})
first[TerraformProviderFake] = map[string]interface{}{
	"name": "1",
}
providers = append(providers, first)

var next Handler = nil
for _, p := range providers {
	for k, v := range p {
		h, err := TerraformProviderHandler(k, v)
		if err != nil {
			fmt.Println(err)
			return
		}
		if h != nil {
			h.SetNext(next)
			next = h
		}
	}
}
fmt.Println("Handler Errors:", next.Do(nil))
Output:

FakeHandler: '1'
FakeHandler: '2'
FakeHandler: '3'
FakeHandler: '4'
Handler Errors: error 4: error 2

type Panos

type Panos struct {
	// contains filtered or unexported fields
}

Panos is the post-apply handler for the panos Terraform Provider. It performs the out-of-band Commit API request needed after a Terraform apply.

See https://registry.terraform.io/providers/PaloAltoNetworks/panos/latest/docs for details on Commit and panos provider (outdated use of SDK at the time). See https://github.com/PaloAltoNetworks/pango for latest version of SDK.

func NewPanos

func NewPanos(c map[string]interface{}) (*Panos, error)

NewPanos configures and returns a new panos handler

func (*Panos) Do

func (h *Panos) Do(prevErr error) error

Do executes panos' out-of-band Commit API and calls next handler while passing on relevant errors

func (*Panos) SetNext

func (h *Panos) SetNext(next Handler)

SetNext sets the next handler that should be called.

Jump to

Keyboard shortcuts

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