client

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConsulAddr = "http://127.0.0.1:8500"

	EnvConsulCaCert        = "CONSUL_CACERT"
	EnvConsulCaPath        = "CONSUL_CAPATH"
	EnvConsulClientCert    = "CONSUL_CLIENT_CERT"
	EnvConsulClientKey     = "CONSUL_CLIENT_KEY"
	EnvConsulHttpSslVerify = "CONSUL_HTTP_SSL_VERIFY"
	EnvConsulTlsServerName = "CONSUL_TLS_SERVER_NAME"
)
View Source
const (
	DefaultNomadAddr = "http://127.0.0.1:4646"

	EnvNomadCaCert        = "NOMAD_CACERT"
	EnvNomadCaPath        = "NOMAD_CAPATH"
	EnvNomadClientCert    = "NOMAD_CLIENT_CERT"
	EnvNomadClientKey     = "NOMAD_CLIENT_KEY"
	EnvNomadSkipVerify    = "NOMAD_SKIP_VERIFY"
	EnvNomadTlsServerName = "NOMAD_TLS_SERVER_NAME"
)
View Source
const (
	DefaultVaultAddr = "http://127.0.0.1:8200"

	EnvVaultCaCert        = "VAULT_CACERT"
	EnvVaultCaPath        = "VAULT_CAPATH"
	EnvVaultClientCert    = "VAULT_CLIENT_CERT"
	EnvVaultClientKey     = "VAULT_CLIENT_KEY"
	EnvVaultSkipVerify    = "VAULT_SKIP_VERIFY"
	EnvVaultTlsServerName = "VAULT_TLS_SERVER_NAME"
)
View Source
const DefaultTFEAddr = "https://127.0.0.1"

Variables

This section is empty.

Functions

func GetConsulLogPath

func GetConsulLogPath(api *APIClient) (string, error)

func GetNomadLogPath

func GetNomadLogPath(api *APIClient) (string, error)

func GetVaultAuditLogPath

func GetVaultAuditLogPath(api *APIClient) (string, error)

Types

type APIClient

type APIClient struct {
	APIConfig
	// contains filtered or unexported fields
}

APIClient can make API calls.

func NewAPIClient

func NewAPIClient(cfg APIConfig) (*APIClient, error)

NewAPIClient gets an API client for a product.

func NewConsulAPI

func NewConsulAPI() (*APIClient, error)

NewConsulAPI returns an APIClient for Consul.

func NewNomadAPI

func NewNomadAPI() (*APIClient, error)

NewNomadAPI returns an APIClient for Nomad.

func NewTFEAPI

func NewTFEAPI() (*APIClient, error)

NewTFEAPI returns an APIClient for TFE.

func NewVaultAPI

func NewVaultAPI() (*APIClient, error)

NewVaultAPI returns an APIClient for Vault.

func (*APIClient) Get

func (c *APIClient) Get(path string) (interface{}, error)

Get makes a GET request to a given path.

func (*APIClient) GetStringValue

func (c *APIClient) GetStringValue(path string, mapKeys ...string) (string, error)

GetStringValue runs GetValue() then casts the result to a string.

func (*APIClient) GetValue

func (c *APIClient) GetValue(path string, mapKeys ...string) (interface{}, error)

GetValue runs Get() then looks through the response for nested mapKeys.

func (*APIClient) RedactGet added in v0.4.0

func (c *APIClient) RedactGet(path string, redactions []*redact.Redact) (any, error)

RedactGet makes a GET request to a given path and applies redactions before returning result. Result will be empty and safe to use if there is a redaction error.

func (*APIClient) RedactGetWithContext added in v0.5.0

func (c *APIClient) RedactGetWithContext(ctx context.Context, path string, redactions []*redact.Redact) (any, error)

RedactGetWithContext behaves similarly to RedactGet, however it takes a context object as a parameter, which is then used when making HTTP requests. This allows for timeouts and cancellations to propagate.

type APIConfig added in v0.3.0

type APIConfig struct {
	Product   string    `json:"product"`
	BaseURL   string    `json:"baseurl"`
	TLSConfig TLSConfig `json:"-"`
	// contains filtered or unexported fields
}

APIConfig contains the configuration details for an APIClient.

type APIResponse

type APIResponse struct {
	Errors []string `json:"errors"`
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type TLSConfig added in v0.3.0

type TLSConfig struct {
	// CACert is the path to a PEM-encoded CA cert file to use to verify the
	// server SSL certificate. It takes precedence over CACertBytes
	// and CAPath.
	CACert string

	// CACertBytes is a PEM-encoded certificate or bundle. It takes precedence
	// over CAPath.
	CACertBytes []byte

	// CAPath is the path to a directory of PEM-encoded CA cert files to verify
	// the server SSL certificate.
	CAPath string

	// ClientCert is the path to the certificate for communication
	ClientCert string

	// ClientKey is the path to the private key for communication
	ClientKey string

	// TLSServerName, if set, is used to set the SNI host when connecting via
	// TLS.
	TLSServerName string

	// Insecure enables or disables SSL verification. Setting to `true` is highly
	// discouraged.
	Insecure bool
}

TLSConfig contains the parameters needed to configure TLS on the HTTP client used to communicate with an API.

func NewConsulTLSConfig added in v0.3.0

func NewConsulTLSConfig() (TLSConfig, error)

NewConsulTLSConfig returns a TLSConfig object, using default environment variables to build up the object.

func NewNomadTLSConfig added in v0.3.0

func NewNomadTLSConfig() (TLSConfig, error)

NewNomadTLSConfig returns a TLSConfig object, using default environment variables to build up the object.

func NewVaultTLSConfig added in v0.3.0

func NewVaultTLSConfig() (TLSConfig, error)

NewVaultTLSConfig returns a TLSConfig object, using default environment variables to build up the object.

Jump to

Keyboard shortcuts

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