client

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsulDefaultMaxRetry = 8 // to be consistent with hcat retries

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// SetEnv Set the environment for the client
	SetEnv(map[string]string) error

	// SetStdout Set the standard out for the client
	SetStdout(w io.Writer)

	// Init initializes the client and environment
	Init(ctx context.Context) error

	// Apply makes a request to apply changes
	Apply(ctx context.Context) error

	// Plan makes a request to generate a plan of proposed changes
	Plan(ctx context.Context) (bool, error)

	// Validate verifies that the generated configurations are valid
	Validate(ctx context.Context) error

	// GoString defines the printable version of the client
	GoString() string
}

Client describes the interface for a driver's client that interacts with network infrastructure.

type ConsulAgentConfig added in v0.6.0

type ConsulAgentConfig = map[string]map[string]interface{}

ConsulAgentConfig represents the responseCode body from Consul /v1/agent/self API endpoint. The response contains configuration and member information of the requested agent. Care must always be taken to do type checks when casting, as structure could potentially change over time.

type ConsulClient added in v0.6.0

type ConsulClient struct {
	*consulapi.Client
	// contains filtered or unexported fields
}

ConsulClient is a client to the Consul API

func NewConsulClient added in v0.6.0

func NewConsulClient(conf *config.ConsulConfig, maxRetry int) (*ConsulClient, error)

NewConsulClient constructs a consul api client

func (*ConsulClient) DeregisterService added in v0.6.0

func (c *ConsulClient) DeregisterService(ctx context.Context, serviceID string, q *consulapi.QueryOptions) error

DeregisterService removes a service through the Consul agent.

func (*ConsulClient) GetHealthChecks added in v0.7.0

func (c *ConsulClient) GetHealthChecks(ctx context.Context, serviceName string, opts *consulapi.QueryOptions) (consulapi.HealthChecks, error)

GetHealthChecks is used to return the health checks associated with a service

func (*ConsulClient) GetLicense added in v0.6.0

func (c *ConsulClient) GetLicense(ctx context.Context, q *consulapi.QueryOptions) (string, error)

GetLicense queries Consul for a signed license, and returns it if available GetLicense is a Consul Enterprise only endpoint, a 404 returned assumes we are connected to OSS Consul GetLicense does not require any ACLs

func (*ConsulClient) KVGet added in v0.7.0

KVGet fetches a Consul KV pair, retrying the request on server errors and rate limit errors.

func (*ConsulClient) Lock added in v0.7.0

func (c *ConsulClient) Lock(l *consulapi.Lock, stopCh <-chan struct{}) (<-chan struct{}, error)

Lock attempts to acquire the given lock.

func (*ConsulClient) QueryServices added in v0.7.0

func (c *ConsulClient) QueryServices(ctx context.Context, filter string, opts *consulapi.QueryOptions) ([]*consulapi.AgentService, error)

QueryServices returns a subset of the locally registered services that match the given filter expression and QueryOptions.

func (*ConsulClient) RegisterService added in v0.6.0

RegisterService registers a service through the Consul agent.

func (*ConsulClient) SessionCreate added in v0.7.0

SessionCreate initializes a new session, retrying creation requests on server errors and rate limit errors.

func (*ConsulClient) SessionRenewPeriodic added in v0.7.0

func (c *ConsulClient) SessionRenewPeriodic(initialTTL string, id string, q *consulapi.WriteOptions, doneCh <-chan struct{}) error

SessionRenewPeriodic renews a session on a given cadence.

func (*ConsulClient) Unlock added in v0.7.0

func (c *ConsulClient) Unlock(l *consulapi.Lock) error

Unlock releases the given lock.

type ConsulClientInterface added in v0.6.0

type ConsulClientInterface interface {
	GetLicense(ctx context.Context, q *consulapi.QueryOptions) (string, error)
	RegisterService(ctx context.Context, s *consulapi.AgentServiceRegistration) error
	DeregisterService(ctx context.Context, serviceID string, q *consulapi.QueryOptions) error
	SessionCreate(ctx context.Context, se *consulapi.SessionEntry, q *consulapi.WriteOptions) (string, *consulapi.WriteMeta, error)
	SessionRenewPeriodic(initialTTL string, id string, q *consulapi.WriteOptions, doneCh <-chan struct{}) error
	LockOpts(opts *consulapi.LockOptions) (*consulapi.Lock, error)
	Lock(l *consulapi.Lock, stopCh <-chan struct{}) (<-chan struct{}, error)
	Unlock(l *consulapi.Lock) error
	KVGet(ctx context.Context, key string, q *consulapi.QueryOptions) (*consulapi.KVPair, *consulapi.QueryMeta, error)
	QueryServices(ctx context.Context, filter string, q *consulapi.QueryOptions) ([]*consulapi.AgentService, error)
	GetHealthChecks(ctx context.Context, serviceName string, q *consulapi.QueryOptions) (consulapi.HealthChecks, error)
}

ConsulClientInterface is an interface for a Consul Client If more consul client functionality is required, this interface should be extended with the following considerations: Each request to Consul is: - Retried - Logged at DEBUG-level - Easily mocked

type MissingConsulACLError added in v0.6.0

type MissingConsulACLError struct {
	Err error
}

MissingConsulACLError represents an error returned if the error was due to not having the correct ACL for accessing a Consul resource

func (*MissingConsulACLError) Error added in v0.6.0

func (e *MissingConsulACLError) Error() string

Error returns an error string

func (*MissingConsulACLError) Unwrap added in v0.6.0

func (e *MissingConsulACLError) Unwrap() error

Unwrap returns the underlying error

type NonEnterpriseConsulError added in v0.6.0

type NonEnterpriseConsulError struct {
	Err error
}

NonEnterpriseConsulError represents an error returned if expected enterprise Consul, but enterprise Consul was not found

func (*NonEnterpriseConsulError) Error added in v0.6.0

func (e *NonEnterpriseConsulError) Error() string

Error returns an error string

func (*NonEnterpriseConsulError) Unwrap added in v0.6.0

func (e *NonEnterpriseConsulError) Unwrap() error

Unwrap returns the underlying error

type Printer

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

Printer is a fake client that only logs out actions. Intended to mirror TerraformCLI client and to be used for development only

func NewPrinter

func NewPrinter(config *PrinterConfig) (*Printer, error)

NewPrinter creates a new client

func (*Printer) Apply

func (p *Printer) Apply(context.Context) error

Apply logs out 'apply'

func (*Printer) GoString

func (p *Printer) GoString() string

GoString defines the printable version of this struct.

func (*Printer) Init

func (p *Printer) Init(context.Context) error

Init logs out 'init'

func (*Printer) Plan

func (p *Printer) Plan(context.Context) (bool, error)

Plan logs out 'plan'

func (*Printer) SetEnv

func (p *Printer) SetEnv(map[string]string) error

SetEnv logs out 'setenv'

func (*Printer) SetStdout

func (p *Printer) SetStdout(io.Writer)

SetStdout logs out 'set standard out'

func (*Printer) Validate added in v0.2.0

func (p *Printer) Validate(context.Context) error

Validate logs out 'validate'

type PrinterConfig

type PrinterConfig struct {
	ExecPath   string
	WorkingDir string
	Workspace  string
	Writer     io.Writer
}

PrinterConfig configures the log client

type TerraformCLI

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

TerraformCLI is the client that wraps around terraform-exec to execute Terraform cli commands

func NewTerraformCLI

func NewTerraformCLI(config *TerraformCLIConfig) (*TerraformCLI, error)

NewTerraformCLI creates a terraform-exec client and configures and initializes a new Terraform client

func (*TerraformCLI) Apply

func (t *TerraformCLI) Apply(ctx context.Context) error

Apply executes the cli command `terraform apply` for a given workspace

func (*TerraformCLI) GoString

func (t *TerraformCLI) GoString() string

GoString defines the printable version of this struct.

func (*TerraformCLI) Init

func (t *TerraformCLI) Init(ctx context.Context) error

Init initializes by executing the cli command `terraform init` and `terraform workspace new <name>`

func (*TerraformCLI) Plan

func (t *TerraformCLI) Plan(ctx context.Context) (bool, error)

Plan executes the cli command `terraform plan` for a given workspace

func (*TerraformCLI) SetEnv

func (t *TerraformCLI) SetEnv(env map[string]string) error

SetEnv sets the environment for the Terraform workspace

func (*TerraformCLI) SetStdout

func (t *TerraformCLI) SetStdout(w io.Writer)

SetStdout sets the standard out for Terraform

func (*TerraformCLI) Validate added in v0.2.0

func (t *TerraformCLI) Validate(ctx context.Context) error

Validate verifies the generated configuration files

type TerraformCLIConfig

type TerraformCLIConfig struct {
	Log        bool
	PersistLog bool
	ExecPath   string
	WorkingDir string
	Workspace  string
}

TerraformCLIConfig configures the Terraform client

Jump to

Keyboard shortcuts

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