common

package
v0.0.0-...-7754ea6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MPL-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package common holds code needed by multiple commands.

Index

Constants

View Source
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 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 Logger

func Logger(level string, jsonLogging bool) (hclog.Logger, error)

Logger returns an hclog instance with log level set and JSON logging enabled/disabled, or an error if level is invalid.

func NamedLogger

func NamedLogger(level string, jsonLogging bool, name string) (hclog.Logger, error)

NamedLogger Logger returns a named hclog instance with log level set and JSON logging enabled/disabled, or an error if level is invalid.

func ValidateUnprivilegedPort

func ValidateUnprivilegedPort(flagName, flagValue string) error

ValidateUnprivilegedPort converts flags representing ports into integer and validates that it's in the unprivileged port range.

func WriteFileWithPerms

func WriteFileWithPerms(outputFile, payload string, mode os.FileMode) error

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

func WriteTempFile(t *testing.T, contents string) string

WriteTempFile writes contents to a temporary file and returns the file name. It will remove the file once the test completes.

func ZapLogger

func ZapLogger(level string, jsonLogging bool) (logr.Logger, error)

ZapLogger returns a logr.Logger instance with log level set and JSON logging enabled/disabled, or an error if the level is invalid.

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.

Jump to

Keyboard shortcuts

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