util

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package util contains a set of common resources that are intended to be used in the ecctl project as a whole.

Index

Constants

View Source
const (
	// DefaultESPort is the default port on ES clusters running on cloud
	DefaultESPort = 9243

	// DefaultIndexPollerRate is the polling interval in seconds for tab-completion on index endpoints
	DefaultIndexPollerRate = 15
)
View Source
const (
	// ValidClusterID holds a valid cluster id value
	ValidClusterID = "320b7b540dfc967a7a649c18e2fce4ed"
	// InvalidClusterID holds an invalid valid cluster id value
	InvalidClusterID = "!23"
	// ValidDuration holds a valid duration value
	ValidDuration = "3 seconds"
)
View Source
const (
	// DefaultRetries retries for the plan.TrackParams which accounts
	// for the Pending plan not being present in the backend, it will retry
	// the request the times specified here. 2 is the default anectdotically
	// because it provides a maximum sleeping time of (PollFrequency * 2)^2
	// or math.Exp2(2). Increasing this value will cause the PlanTracker to
	// sleep for more time than it's required, thus making ecctl less efficient.
	DefaultRetries = 2

	// DefaultPollFrequency is frequency on which the API is polled for updates
	// on pending plans. This value is also used as the cooldown time when used
	// with MaxRetries > 0.
	DefaultPollFrequency = time.Second * 10
)
View Source
const (
	// DefaultClientTimeout client http timeout for console requests
	DefaultClientTimeout = 15
)

Variables

View Source
var (
	// ErrAPIReq is the message returned when API reference is required for a command
	ErrAPIReq = errors.New("api reference is required for command")
	// ErrDeploymentID is the message returned when a provided cluster id is not of the expected length (32 chars)
	ErrDeploymentID = errors.New("deployment id should have a length of 32 characters")

	// SkipMaintenanceHeaders tells the EC proxy layer to still send requests to the
	// underlying cluster instances even if they are in maintenance mode
	SkipMaintenanceHeaders = map[string]string{
		"X-Found-Bypass-Maintenance": "true",
	}
)

Functions

func AppendTrackResponses

func AppendTrackResponses(res ...mock.Response) []mock.Response

AppendTrackResponses is aimed to be used while testing to add the tracking responses as a successful plan, it assumes that there's 1 retry performed by the client.

func AskForConfirmation

func AskForConfirmation(reader io.Reader, out *output.Device) bool

AskForConfirmation scans the stdin for "y" or "yes" (case insensitive)

func DashesToUnderscore

func DashesToUnderscore(s string) string

DashesToUnderscore returns an underscore separated string converted from dash separated form.

func FieldsOfStruct

func FieldsOfStruct(p interface{}) map[string]string

FieldsOfStruct returns a list of the kebabcased struct property names that have the tag `kebabcase:"description"` set. The map that will be returned will have the form of: "skip-data-migration": "description"

func GetTimeoutFromSize

func GetTimeoutFromSize(size int64) time.Duration

GetTimeoutFromSize computes a time.Duration from the size, if the computed value is smaller than the minimum timeout that is returned instead

func Min

func Min(a, b int8) int8

Min returns the minimum of two int8

func NewFailedPlanUnknown

func NewFailedPlanUnknown() mock.Response

NewFailedPlanUnknown returns a mocked response from a failed plan.

func NewMockTrackChangeParams

func NewMockTrackChangeParams(id string) planutil.TrackChangeParams

NewMockTrackChangeParams creates new tracking params for test purposes.

func NewSuccessfulCurrentPlan

func NewSuccessfulCurrentPlan(currentTime ...time.Time) mock.Response

NewSuccessfulCurrentPlan returns a mocked response from a successful plan.

func RandomString

func RandomString(n int) string

RandomString generates a random strings with a defined length.

func ReadMFAToken

func ReadMFAToken(reader io.Reader, out *output.Device) (string, error)

ReadMFAToken reads an MFA token

func Set

func Set(p interface{}, key string, value interface{})

Set will populate a property from its dashed version to the specified value i.e. passing `skip-snapshot` as a key will populate the `SkipSnapshot` prop.

func SetClusterTracking

func SetClusterTracking(params planutil.TrackChangeParams, id, kind string) planutil.TrackChangeParams

SetClusterTracking modifies the TrackChangeParams to track a specific id and kind ignoring downstream changes.

func SetRawJSON

func SetRawJSON(c *client.Rest)

SetRawJSON prepares the API transport to send raw JSON

While setting the global JSONMime producer to runtime.TextProducer() looks scary, runtime.TextProducer() falls back on swag.WriteJSON(data) if the object we're marshalling is a struct or slice. So it actually works in most cases.

This is only necessary because the Cloud Swagger Spec lists some JSON blob data as strings. When those are changed to JSON Objects, this can go away.

func UnderscoreToDashes

func UnderscoreToDashes(s string) string

UnderscoreToDashes returns a dash separated string converted from underscore or camelcase separated form.

func UnsetRawJSON

func UnsetRawJSON(c *client.Rest)

UnsetRawJSON un-does what SetRawJSON does :)

Types

type Validator

type Validator interface {
	Validate() error
}

Validator interface is mostly used for parameter structures that need to check a set of conditions and act as a gate before running expensive external calls

Jump to

Keyboard shortcuts

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