dependency

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthAny      = "any"
	HealthPassing  = "passing"
	HealthWarning  = "warning"
	HealthUnknown  = "unknown"
	HealthCritical = "critical"
	HealthMaint    = "maintenance"

	NodeMaint    = "_node_maintenance"
	ServiceMaint = "_service_maintenance:"
)

Variables

View Source
var ErrStopped = errors.New("dependency stopped")

ErrStopped is a special error that is returned when a dependency is prematurely stopped, usually due to a configuration reload or a process interrupt.

Functions

This section is empty.

Types

type CatalogNode added in v0.10.0

type CatalogNode struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CatalogNode represents a single node from the Consul catalog.

func ParseCatalogNode added in v0.10.0

func ParseCatalogNode(s ...string) (*CatalogNode, error)

ParseCatalogNode parses a name name and optional datacenter value. If the name is empty or not provided then the current agent is used.

func (*CatalogNode) CanShare added in v0.12.0

func (d *CatalogNode) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*CatalogNode) Display added in v0.10.0

func (d *CatalogNode) Display() string

Display prints the human-friendly output.

func (*CatalogNode) Fetch added in v0.10.0

func (d *CatalogNode) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a of NodeDetail object.

func (*CatalogNode) HashCode added in v0.10.0

func (d *CatalogNode) HashCode() string

HashCode returns a unique identifier.

func (*CatalogNode) Stop added in v0.14.0

func (d *CatalogNode) Stop()

Stop halts the dependency's fetch function.

type CatalogNodes

type CatalogNodes struct {
	sync.Mutex

	DataCenter string
	// contains filtered or unexported fields
}

CatalogNodes is the representation of all registered nodes in Consul.

func ParseCatalogNodes

func ParseCatalogNodes(s ...string) (*CatalogNodes, error)

ParseCatalogNodes parses a string of the format @dc.

func (*CatalogNodes) CanShare added in v0.12.0

func (d *CatalogNodes) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*CatalogNodes) Display

func (d *CatalogNodes) Display() string

Display prints the human-friendly output.

func (*CatalogNodes) Fetch

func (d *CatalogNodes) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a slice of Node objects

func (*CatalogNodes) HashCode

func (d *CatalogNodes) HashCode() string

HashCode returns a unique identifier.

func (*CatalogNodes) Stop added in v0.14.0

func (d *CatalogNodes) Stop()

Stop halts the dependency's fetch function.

type CatalogService

type CatalogService struct {
	Name string
	Tags ServiceTags
}

CatalogService is a catalog entry in Consul.

type CatalogServices

type CatalogServices struct {
	sync.Mutex

	Name       string
	Tags       []string
	DataCenter string
	// contains filtered or unexported fields
}

CatalogServices is the representation of a requested catalog service dependency from inside a template.

func ParseCatalogServices

func ParseCatalogServices(s ...string) (*CatalogServices, error)

ParseCatalogServices parses a string of the format @dc.

func (*CatalogServices) CanShare added in v0.12.0

func (d *CatalogServices) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*CatalogServices) Display

func (d *CatalogServices) Display() string

Display prints the human-friendly output.

func (*CatalogServices) Fetch

func (d *CatalogServices) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a slice of CatalogService objects.

func (*CatalogServices) HashCode

func (d *CatalogServices) HashCode() string

HashCode returns a unique identifier.

func (*CatalogServices) Stop added in v0.14.0

func (d *CatalogServices) Stop()

Stop halts the dependency's fetch function.

type CatalogServicesList

type CatalogServicesList []*CatalogService

CatalogServicesList is a sortable slice of CatalogService structs.

func (CatalogServicesList) Len

func (s CatalogServicesList) Len() int

func (CatalogServicesList) Less

func (s CatalogServicesList) Less(i, j int) bool

func (CatalogServicesList) Swap

func (s CatalogServicesList) Swap(i, j int)

type ClientSet added in v0.9.0

type ClientSet struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ClientSet is a collection of clients that dependencies use to communicate with remote services like Consul or Vault.

func NewClientSet added in v0.9.0

func NewClientSet() *ClientSet

NewClientSet creates a new client set that is ready to accept clients.

func (*ClientSet) Consul added in v0.9.0

func (c *ClientSet) Consul() (*consulapi.Client, error)

Consul returns the Consul client for this clientset, or an error if no Consul client has been set.

func (*ClientSet) CreateConsulClient added in v0.15.0

func (c *ClientSet) CreateConsulClient(i *CreateConsulClientInput) error

CreateConsulClient creates a new Consul API client from the given input.

func (*ClientSet) CreateVaultClient added in v0.15.0

func (c *ClientSet) CreateVaultClient(i *CreateVaultClientInput) error

func (*ClientSet) Stop added in v0.15.0

func (c *ClientSet) Stop()

Stop closes all idle connections for any attached clients.

func (*ClientSet) Vault added in v0.9.0

func (c *ClientSet) Vault() (*vaultapi.Client, error)

Vault returns the Vault client for this clientset, or an error if no Vault client has been set.

type CreateConsulClientInput added in v0.15.0

type CreateConsulClientInput struct {
	Address      string
	Token        string
	AuthEnabled  bool
	AuthUsername string
	AuthPassword string
	SSLEnabled   bool
	SSLVerify    bool
	SSLCert      string
	SSLKey       string
	SSLCACert    string
	SSLCAPath    string
	ServerName   string
}

CreateConsulClientInput is used as input to the CreateConsulClient function.

type CreateVaultClientInput added in v0.15.0

type CreateVaultClientInput struct {
	Address     string
	Token       string
	UnwrapToken bool
	SSLEnabled  bool
	SSLVerify   bool
	SSLCert     string
	SSLKey      string
	SSLCACert   string
	SSLCAPath   string
	ServerName  string
}

CreateVaultClientInput is used as input to the CreateVaultClient function.

type Datacenters added in v0.6.0

type Datacenters struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Datacenters is the dependency to query all datacenters

func ParseDatacenters added in v0.6.0

func ParseDatacenters(s ...string) (*Datacenters, error)

ParseDatacenters creates a new datacenter dependency.

func (*Datacenters) CanShare added in v0.12.0

func (d *Datacenters) CanShare() bool

CanShare returns if this dependency is shareable.

func (*Datacenters) Display added in v0.6.0

func (d *Datacenters) Display() string

Display returns a string that should be displayed to the user in output (for example).

func (*Datacenters) Fetch added in v0.6.0

func (d *Datacenters) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a slice of strings representing the datacenters

func (*Datacenters) HashCode added in v0.6.0

func (d *Datacenters) HashCode() string

HashCode returns the hash code for this dependency.

func (*Datacenters) Stop added in v0.14.0

func (d *Datacenters) Stop()

Stop terminates this dependency's execution early.

type Dependency

type Dependency interface {
	Fetch(*ClientSet, *QueryOptions) (interface{}, *ResponseMetadata, error)
	CanShare() bool
	HashCode() string
	Display() string
	Stop()
}

Dependency is an interface for a dependency that Consul Template is capable of watching.

type FetchError added in v0.16.0

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

FetchError is a special kind of error returned by the Fetch method that contains additional metadata which informs the caller how to respond. This error implements the standard Error interface, so it can be passed as a regular error down the stack.

func ErrWithExit added in v0.16.0

func ErrWithExit(err error) *FetchError

func ErrWithExitf added in v0.16.0

func ErrWithExitf(s string, i ...interface{}) *FetchError

func (*FetchError) Error added in v0.16.0

func (e *FetchError) Error() string

func (*FetchError) OriginalError added in v0.16.0

func (e *FetchError) OriginalError() error

func (*FetchError) ShouldExit added in v0.16.0

func (e *FetchError) ShouldExit() bool

type File

type File struct {
	sync.Mutex
	// contains filtered or unexported fields
}

File represents a local file dependency.

func ParseFile

func ParseFile(s string) (*File, error)

ParseFile creates a file dependency from the given path.

func (*File) CanShare added in v0.12.0

func (d *File) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*File) Display

func (d *File) Display() string

Display prints the human-friendly output.

func (*File) Fetch

func (d *File) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch retrieves this dependency and returns the result or any errors that occur in the process.

func (*File) HashCode

func (d *File) HashCode() string

HashCode returns a unique identifier.

func (*File) Stop added in v0.14.0

func (d *File) Stop()

Stop halts the dependency's fetch function.

type HealthService

type HealthService struct {
	Node        string
	NodeAddress string
	Address     string
	ID          string
	Name        string
	Tags        ServiceTags
	Checks      []*api.HealthCheck
	Status      string
	Port        uint64
}

HealthService is a service entry in Consul.

type HealthServiceList

type HealthServiceList []*HealthService

HealthServiceList is a sortable slice of Service

func (HealthServiceList) Len

func (s HealthServiceList) Len() int

Len, Swap, and Less are used to implement the sort.Sort interface.

func (HealthServiceList) Less

func (s HealthServiceList) Less(i, j int) bool

func (HealthServiceList) Swap

func (s HealthServiceList) Swap(i, j int)

type HealthServices

type HealthServices struct {
	sync.Mutex

	Name         string
	Tag          string
	DataCenter   string
	StatusFilter ServiceStatusFilter
	// contains filtered or unexported fields
}

HealthServices is the struct that is formed from the dependency inside a template.

func ParseHealthServices

func ParseHealthServices(s ...string) (*HealthServices, error)

ParseHealthServices processes the incoming strings to build a service dependency.

Supported arguments

ParseHealthServices("service_id")
ParseHealthServices("service_id", "health_check")

Where service_id is in the format of service(.tag(@datacenter)) and health_check is either "any" or "passing".

If no health_check is provided then its the same as "passing".

func (*HealthServices) CanShare added in v0.12.0

func (d *HealthServices) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*HealthServices) Display

func (d *HealthServices) Display() string

Display prints the human-friendly output.

func (*HealthServices) Fetch

func (d *HealthServices) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a slice of HealthService objects.

func (*HealthServices) HashCode

func (d *HealthServices) HashCode() string

HashCode returns a unique identifier.

func (*HealthServices) Stop added in v0.14.0

func (d *HealthServices) Stop()

Stop halts the dependency's fetch function.

type KeyPair

type KeyPair struct {
	Path  string
	Key   string
	Value string

	// Lesser-used, but still valuable keys from api.KV
	CreateIndex uint64
	ModifyIndex uint64
	LockIndex   uint64
	Flags       uint64
	Session     string
}

KeyPair is a simple Key-Value pair

type Node

type Node struct {
	Node            string
	Address         string
	TaggedAddresses map[string]string
}

Node is a node entry in Consul

type NodeDetail added in v0.10.0

type NodeDetail struct {
	Node     *Node
	Services NodeServiceList
}

NodeDetail is a wrapper around the node and its services.

type NodeList added in v0.10.0

type NodeList []*Node

NodeList is a sortable list of node objects by name and then IP address.

func (NodeList) Len added in v0.10.0

func (s NodeList) Len() int

func (NodeList) Less added in v0.10.0

func (s NodeList) Less(i, j int) bool

func (NodeList) Swap added in v0.10.0

func (s NodeList) Swap(i, j int)

type NodeService added in v0.10.0

type NodeService struct {
	ID                string
	Service           string
	Tags              ServiceTags
	Port              int
	Address           string
	EnableTagOverride bool
}

NodeService is a service on a single node.

type NodeServiceList added in v0.10.0

type NodeServiceList []*NodeService

NodeServiceList is a sortable list of node service names.

func (NodeServiceList) Len added in v0.10.0

func (s NodeServiceList) Len() int

func (NodeServiceList) Less added in v0.10.0

func (s NodeServiceList) Less(i, j int) bool

func (NodeServiceList) Swap added in v0.10.0

func (s NodeServiceList) Swap(i, j int)

type QueryOptions added in v0.9.0

type QueryOptions struct {
	AllowStale bool
	WaitIndex  uint64
	WaitTime   time.Duration
}

QueryOptions is a list of options to send with the query. These options are client-agnostic, and the dependency determines which, if any, of the options to use.

type ResponseMetadata added in v0.9.0

type ResponseMetadata struct {
	LastIndex   uint64
	LastContact time.Duration
}

ResponseMetadata is a struct that contains metadata about the response. This is returned from a Fetch function call.

type Secret added in v0.9.0

type Secret struct {
	LeaseID       string
	LeaseDuration int
	Renewable     bool

	// Data is the actual contents of the secret. The format of the data
	// is arbitrary and up to the secret backend.
	Data map[string]interface{}
}

Secret is a vault secret.

type ServiceStatusFilter

type ServiceStatusFilter []string

ServiceStatusFilter is used to specify a list of service statuses that you want filter by.

func NewServiceStatusFilter added in v0.8.0

func NewServiceStatusFilter(s string) (ServiceStatusFilter, error)

NewServiceStatusFilter creates a status filter from the given string in the format `[key[,key[,key...]]]`. Each status is split on the comma character and must match one of the valid status names.

If the empty string is given, it is assumed only "passing" statuses are to be returned.

If the user specifies "any" with other keys, an error will be returned.

func (ServiceStatusFilter) Accept added in v0.8.0

func (f ServiceStatusFilter) Accept(s string) bool

Accept allows us to check if a slice of health checks pass this filter.

func (ServiceStatusFilter) String

func (f ServiceStatusFilter) String() string

String returns the string representation of this status filter

type ServiceTags

type ServiceTags []string

ServiceTags is a slice of tags assigned to a Service

func (ServiceTags) Contains

func (t ServiceTags) Contains(s string) bool

Contains returns true if the tags exists in the ServiceTags slice.

type StoreKey

type StoreKey struct {
	sync.Mutex

	Path       string
	DataCenter string
	// contains filtered or unexported fields
}

StoreKey represents a single item in Consul's KV store.

func ParseStoreKey

func ParseStoreKey(s string) (*StoreKey, error)

ParseStoreKey parses a string of the format a(/b(/c...))

func (*StoreKey) CanShare added in v0.12.0

func (d *StoreKey) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*StoreKey) Display

func (d *StoreKey) Display() string

Display prints the human-friendly output.

func (*StoreKey) Fetch

func (d *StoreKey) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns string of the value to Path.

func (*StoreKey) HashCode

func (d *StoreKey) HashCode() string

HashCode returns a unique identifier.

func (*StoreKey) SetDefault added in v0.11.0

func (d *StoreKey) SetDefault(s string)

SetDefault is used to set the default value.

func (*StoreKey) SetExistenceCheck added in v0.17.0

func (d *StoreKey) SetExistenceCheck(b bool)

SetExistenceCheck sets this keys as an existence check instead of a value check.

func (*StoreKey) Stop added in v0.14.0

func (d *StoreKey) Stop()

Stop halts the dependency's fetch function.

type StoreKeyPrefix

type StoreKeyPrefix struct {
	sync.Mutex

	Prefix     string
	DataCenter string
	// contains filtered or unexported fields
}

StoreKeyPrefix is the representation of a requested key dependency from inside a template.

func ParseStoreKeyPrefix

func ParseStoreKeyPrefix(s string) (*StoreKeyPrefix, error)

ParseStoreKeyPrefix parses a string of the format a(/b(/c...))

func (*StoreKeyPrefix) CanShare added in v0.12.0

func (d *StoreKeyPrefix) CanShare() bool

CanShare returns a boolean if this dependency is shareable.

func (*StoreKeyPrefix) Display

func (d *StoreKeyPrefix) Display() string

Display prints the human-friendly output.

func (*StoreKeyPrefix) Fetch

func (d *StoreKeyPrefix) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Consul API defined by the given client and returns a slice of KeyPair objects

func (*StoreKeyPrefix) HashCode

func (d *StoreKeyPrefix) HashCode() string

HashCode returns a unique identifier.

func (*StoreKeyPrefix) Stop added in v0.14.0

func (d *StoreKeyPrefix) Stop()

Stop halts the dependency's fetch function.

type Test added in v0.9.0

type Test struct {
	Name string
}

Test is a special dependency that does not actually speaks to a server.

func (*Test) CanShare added in v0.12.0

func (d *Test) CanShare() bool

func (*Test) Display added in v0.9.0

func (d *Test) Display() string

func (*Test) Fetch added in v0.9.0

func (d *Test) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

func (*Test) HashCode added in v0.9.0

func (d *Test) HashCode() string

func (*Test) Stop added in v0.14.0

func (d *Test) Stop()

type TestFetchError added in v0.9.0

type TestFetchError struct {
	Name string
}

TestFetchError is a special dependency that returns an error while fetching.

func (*TestFetchError) CanShare added in v0.12.0

func (d *TestFetchError) CanShare() bool

func (*TestFetchError) Display added in v0.9.0

func (d *TestFetchError) Display() string

func (*TestFetchError) Fetch added in v0.9.0

func (d *TestFetchError) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

func (*TestFetchError) HashCode added in v0.9.0

func (d *TestFetchError) HashCode() string

func (*TestFetchError) Stop added in v0.14.0

func (d *TestFetchError) Stop()

type TestRetry added in v0.9.0

type TestRetry struct {
	sync.Mutex
	Name string
	// contains filtered or unexported fields
}

TestRetry is a special dependency that errors on the first fetch and succeeds on subsequent fetches.

func (*TestRetry) CanShare added in v0.12.0

func (d *TestRetry) CanShare() bool

func (*TestRetry) Display added in v0.9.0

func (d *TestRetry) Display() string

func (*TestRetry) Fetch added in v0.9.0

func (d *TestRetry) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

func (*TestRetry) HashCode added in v0.9.0

func (d *TestRetry) HashCode() string

func (*TestRetry) Stop added in v0.14.0

func (d *TestRetry) Stop()

type TestStale added in v0.9.0

type TestStale struct {
	Name string
}

TestStale is a special dependency that can be used to test what happens when stale data is permitted.

func (*TestStale) CanShare added in v0.12.0

func (d *TestStale) CanShare() bool

func (*TestStale) Display added in v0.9.0

func (d *TestStale) Display() string

func (*TestStale) Fetch added in v0.9.0

func (d *TestStale) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch is used to implement the dependency interface.

func (*TestStale) HashCode added in v0.9.0

func (d *TestStale) HashCode() string

func (*TestStale) Stop added in v0.14.0

func (d *TestStale) Stop()

type VaultSecret added in v0.9.0

type VaultSecret struct {
	sync.Mutex

	Path string
	// contains filtered or unexported fields
}

VaultSecret is the dependency to Vault for a secret

func ParseVaultSecret added in v0.9.0

func ParseVaultSecret(s ...string) (*VaultSecret, error)

ParseVaultSecret creates a new datacenter dependency.

func (*VaultSecret) CanShare added in v0.12.0

func (d *VaultSecret) CanShare() bool

CanShare returns if this dependency is shareable.

func (*VaultSecret) Display added in v0.9.0

func (d *VaultSecret) Display() string

Display returns a string that should be displayed to the user in output (for example).

func (*VaultSecret) Fetch added in v0.9.0

func (d *VaultSecret) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Vault API

func (*VaultSecret) HashCode added in v0.9.0

func (d *VaultSecret) HashCode() string

HashCode returns the hash code for this dependency.

func (*VaultSecret) Stop added in v0.14.0

func (d *VaultSecret) Stop()

Stop halts the given dependency's fetch.

type VaultSecrets added in v0.14.0

type VaultSecrets struct {
	sync.Mutex

	Path string
	// contains filtered or unexported fields
}

VaultSecrets is the dependency to list secrets in Vault.

func ParseVaultSecrets added in v0.14.0

func ParseVaultSecrets(s string) (*VaultSecrets, error)

ParseVaultSecrets creates a new datacenter dependency.

func (*VaultSecrets) CanShare added in v0.14.0

func (d *VaultSecrets) CanShare() bool

CanShare returns if this dependency is shareable.

func (*VaultSecrets) Display added in v0.14.0

func (d *VaultSecrets) Display() string

Display returns a string that should be displayed to the user in output (for example).

func (*VaultSecrets) Fetch added in v0.14.0

func (d *VaultSecrets) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Vault API

func (*VaultSecrets) HashCode added in v0.14.0

func (d *VaultSecrets) HashCode() string

HashCode returns the hash code for this dependency.

func (*VaultSecrets) Stop added in v0.14.0

func (d *VaultSecrets) Stop()

Stop halts the dependency's fetch function.

type VaultToken added in v0.11.0

type VaultToken struct {
	sync.Mutex
	// contains filtered or unexported fields
}

VaultToken is the dependency to Vault for a secret

func ParseVaultToken added in v0.14.0

func ParseVaultToken() (*VaultToken, error)

ParseVaultToken creates a new VaultToken dependency.

func (*VaultToken) CanShare added in v0.12.0

func (d *VaultToken) CanShare() bool

CanShare returns if this dependency is shareable.

func (*VaultToken) Display added in v0.11.0

func (d *VaultToken) Display() string

Display returns a string that should be displayed to the user in output (for example).

func (*VaultToken) Fetch added in v0.11.0

func (d *VaultToken) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error)

Fetch queries the Vault API

func (*VaultToken) HashCode added in v0.11.0

func (d *VaultToken) HashCode() string

HashCode returns the hash code for this dependency.

func (*VaultToken) Stop added in v0.14.0

func (d *VaultToken) Stop()

Stop halts the dependency's fetch function.

Jump to

Keyboard shortcuts

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