Documentation ¶
Overview ¶
Package common holds code needed by multiple commands.
Index ¶
- Constants
- func ConsulLogin(client *api.Client, params LoginParams, log hclog.Logger) (string, error)
- func GetMetricsEnabled(v string) (bool, bool)
- func GetResolvedServerAddresses(serverAddresses []string, providers map[string]discover.Provider, ...) ([]string, error)
- func GetScrapePath(v string) (string, bool)
- func Logger(level string, jsonLogging bool) (hclog.Logger, error)
- func NamedLogger(level string, jsonLogging bool, name string) (hclog.Logger, error)
- func ParseScrapePort(v string) (int, bool)
- func ValidateUnprivilegedPort(flagName, flagValue string) error
- func WriteFileWithPerms(outputFile, payload string, mode os.FileMode) error
- func WriteTempFile(t *testing.T, contents string) string
- func ZapLogger(level string, jsonLogging bool) (logr.Logger, error)
- type LoginParams
Constants ¶
const ( // ACLReplicationTokenName is the name used for the ACL replication policy and // Kubernetes secret. It is consumed in both the server-acl-init and // create-federation-secret commands and so lives in this common package. ACLReplicationTokenName = "acl-replication" DatadogAgentTokenName = "datadog-agent-metrics" // ACLTokenSecretKey is the key that we store the ACL tokens in when we // create Kubernetes secrets. ACLTokenSecretKey = "token" // CLILabelKey and CLILabelValue are added to each secret on creation so the CLI knows // which secrets to delete on an uninstall. CLILabelKey = "managed-by" CLILabelValue = "consul-k8s" )
Variables ¶
This section is empty.
Functions ¶
func ConsulLogin ¶
func ConsulLogin(client *api.Client, params LoginParams, log hclog.Logger) (string, error)
ConsulLogin issues an ACL().Login to Consul and writes out the token to tokenSinkFile. The logic of this is taken from the `consul login` command.
func GetMetricsEnabled ¶
func GetResolvedServerAddresses ¶
func GetResolvedServerAddresses(serverAddresses []string, providers map[string]discover.Provider, logger hclog.Logger) ([]string, error)
GetResolvedServerAddresses resolves the Consul server address if it has been provided a provider else it returns the server addresses that were input to it. It attempts to use go-discover iff there is a single server address, the value of which begins with "provider=", else it returns the server addresses as is.
func GetScrapePath ¶
func Logger ¶
Logger returns an hclog instance with log level set and JSON logging enabled/disabled, or an error if level is invalid.
func NamedLogger ¶
NamedLogger Logger returns a named hclog instance with log level set and JSON logging enabled/disabled, or an error if level is invalid.
func ParseScrapePort ¶
func ValidateUnprivilegedPort ¶
ValidateUnprivilegedPort converts flags representing ports into integer and validates that it's in the unprivileged port range.
func WriteFileWithPerms ¶
WriteFileWithPerms will write payload as the contents of the outputFile and set permissions after writing the contents. This function is necessary since using os.WriteFile() alone will create the new file with the requested permissions prior to actually writing the file, so you can't set read-only permissions.
func WriteTempFile ¶
WriteTempFile writes contents to a temporary file and returns the file name. It will remove the file once the test completes.
Types ¶
type LoginParams ¶
type LoginParams struct { // AuthMethod is the name of the auth method. AuthMethod string // Datacenter is the datacenter for the login request. Datacenter string // Namespace is the namespace for the login request. Namespace string // BearerTokenFile is the file where the bearer token is stored. BearerTokenFile string // TokenSinkFile is the file where to write the token received from Consul. TokenSinkFile string // Meta is the metadata to set on the token. Meta map[string]string // NumRetries is the number of times to try to log in. NumRetries uint64 }
LoginParams are parameters used to log in to consul.