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
- Variables
- func AppendTrackResponses(res ...mock.Response) []mock.Response
- func AskForConfirmation(reader io.Reader, out *output.Device) bool
- func DashesToUnderscore(s string) string
- func FieldsOfStruct(p interface{}) map[string]string
- func GetTimeoutFromSize(size int64) time.Duration
- func Min(a, b int8) int8
- func NewFailedPlanUnknown() mock.Response
- func NewMockTrackChangeParams(id string) planutil.TrackChangeParams
- func NewSuccessfulCurrentPlan(currentTime ...time.Time) mock.Response
- func RandomString(n int) string
- func ReadMFAToken(reader io.Reader, out *output.Device) (string, error)
- func Set(p interface{}, key string, value interface{})
- func SetClusterTracking(params planutil.TrackChangeParams, id, kind string) planutil.TrackChangeParams
- func SetRawJSON(c *client.Rest)
- func UnderscoreToDashes(s string) string
- func UnsetRawJSON(c *client.Rest)
- type Validator
Constants ¶
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 )
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" )
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 )
const (
// DefaultClientTimeout client http timeout for console requests
DefaultClientTimeout = 15
)
Variables ¶
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 ¶
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 ¶
AskForConfirmation scans the stdin for "y" or "yes" (case insensitive)
func DashesToUnderscore ¶
DashesToUnderscore returns an underscore separated string converted from dash separated form.
func FieldsOfStruct ¶
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 ¶
GetTimeoutFromSize computes a time.Duration from the size, if the computed value is smaller than the minimum timeout that is returned instead
func NewFailedPlanUnknown ¶
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 ¶
NewSuccessfulCurrentPlan returns a mocked response from a successful plan.
func RandomString ¶
RandomString generates a random strings with a defined length.
func ReadMFAToken ¶
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 ¶
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 ¶
UnderscoreToDashes returns a dash separated string converted from underscore or camelcase separated form.