utils

package
v0.0.0-...-a706f41 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultImageNameOSS   = "hashicorp/consul"
	DefaultImageNameENT   = "hashicorp/consul-enterprise"
	ImageVersionSuffixENT = "-ent"
)
View Source
const (
	ImageVersionSuffix = ""
)

Variables

View Source
var (
	TargetVersion string

	LatestImageName string
	LatestVersion   string

	FollowLog bool

	Debug           bool
	Version_1_14, _ = version.NewVersion("1.14")
)

Functions

func ApplyDefaultProxySettings

func ApplyDefaultProxySettings(c *api.Client) (bool, error)

func BoolToPointer

func BoolToPointer(b bool) *bool

func DefaultToEmpty

func DefaultToEmpty(name string) string

func DockerExec

func DockerExec(args []string, stdout io.Writer) error

DockerExec simply shell out to the docker CLI binary on your host.

func DockerImage

func DockerImage(image, version string) string

func Dump

func Dump(v any) string

Dump pretty prints the provided arg as json.

func GenerateKey

func GenerateKey() (pub, priv string, err error)

Generates a private and public key pair that is for signing JWT.

func GetLatestImageName

func GetLatestImageName() string

func GetTargetImageName

func GetTargetImageName() string

func IntToPointer

func IntToPointer(i int) *int

func IsEnterprise

func IsEnterprise() bool

func JQFilter

func JQFilter(config, filter string) ([]string, error)

JQFilter uses the provided "jq" filter to parse json. Matching results are returned as a slice of strings.

func NamespaceOrDefault

func NamespaceOrDefault(name string) string

func NewJWKS

func NewJWKS(pubKey string) (*jose.JSONWebKeySet, error)

newJWKS converts a pem-encoded public key into JWKS data suitable for a verification endpoint response

func PartitionOrDefault

func PartitionOrDefault(name string) string

func PartitionQueryOptions

func PartitionQueryOptions(partition string) *api.QueryOptions

PartitionQueryOptions returns an *api.QueryOptions with the given partition field set only if the partition is non-default. This helps when writing tests for joint use in OSS and ENT.

func RandName

func RandName(name string) string

func SideCarVersion

func SideCarVersion(agentVersion string) string

SideCarVersion returns version based on the agent version in the test: if agent has local, the sidecar version is target-version; otherwise use "latest-version"

func SignJWT

func SignJWT(privKey string, claims jwt.Claims, privateClaims interface{}) (string, error)

SignJWT will bundle the provided claims into a signed JWT. The provided key is assumed to be ECDSA.

If no private key is provided, it will generate a private key. These can be retrieved via the SigningKeys() method.

func StringToPointer

func StringToPointer(s string) *string

func VersionGTE

func VersionGTE(a, b string) bool

ensure version a >= b

func VersionLT

func VersionLT(a, b string) bool

ensure version a < b

Types

type ResettableDefer

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

ResettableDefer is a way to capture a series of cleanup functions and bulk-cancel them. Ideal to use in a long constructor function before the overall Close/Stop/Terminate method is ready to use to tear down all of the portions properly.

func (*ResettableDefer) Add

func (d *ResettableDefer) Add(f func())

Add registers another function to call at Execute time.

func (*ResettableDefer) Execute

func (d *ResettableDefer) Execute()

Execute actually executes the functions registered by Add in the reverse order of their call order (like normal defer blocks).

func (*ResettableDefer) Reset

func (d *ResettableDefer) Reset()

Reset clears the pending defer work.

type Waiter

type Waiter struct {
	// MinFailures before exponential backoff starts. Any failures before
	// MinFailures is reached will wait MinWait time.
	MinFailures uint
	// MinWait time. Returned after the first failure.
	MinWait time.Duration
	// MaxWait time.
	MaxWait time.Duration
	// Factor is the multiplier to use when calculating the delay. Defaults to
	// 1 second.
	Factor time.Duration
	// contains filtered or unexported fields
}

Waiter records the number of failures and performs exponential backoff when when there are consecutive failures.

func (*Waiter) Failures

func (w *Waiter) Failures() int

Failures returns the count of consecutive failures.

func (*Waiter) Reset

func (w *Waiter) Reset()

Reset the failure count to 0.

func (*Waiter) Wait

func (w *Waiter) Wait(ctx context.Context) error

Wait increase the number of failures by one, and then blocks until the context is cancelled, or until the wait time is reached. The wait time increases exponentially as the number of failures increases. Wait will return ctx.Err() if the context is cancelled.

Jump to

Keyboard shortcuts

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