utils

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ImplementationTypeKongGateway indicates an implementation backed by Kong Gateway.
	ImplementationTypeKongGateway = "kong-gateway"
)

Variables

This section is empty.

Functions

func AddExtToFilename added in v1.6.0

func AddExtToFilename(filename, ext string) string

func CleanAddress

func CleanAddress(address string) string

CleanAddress removes trailling / from a URL.

func CleanKongVersion

func CleanKongVersion(version string) (string, error)

CleanKongVersion takes a version of Kong and returns back a string in the form of `/major.minor` version. There are various dashes and dots and other descriptors in Kong version strings, which has often created confusion in code and incorrect parsing, and hence this function does not return the patch version (on which shouldn't rely on anyways).

func Confirm added in v1.7.0

func Confirm(message string) (bool, error)

Confirm prompts a user for a confirmation with message and returns true with no error if input is "yes" or "y" (case-insensitive), otherwise false.

func ConfirmFileOverwrite added in v1.7.0

func ConfirmFileOverwrite(filename string, ext string, assumeYes bool) (bool, error)

ConfirmFileOverwrite is a helper function to determine whether or not the program should truncate and overwrite a file given its name and extension. If the file doesn't already exist in the filesystem, then this will return true, otherwise it will prompt the user for confirmation.

func Empty

func Empty(s *string) bool

Empty checks if a string referenced by s or s itself is empty.

func FilenameToName added in v1.7.0

func FilenameToName(filename string) string

FilenameToName (partially) reverses NameToFilename, replacing all URL-encoded path separator characters with the path separator character. It does not re-add a leading separator, because there is no way to know if that separator was included originally, and only some names (document paths) typically include one.

func GetKongClient

func GetKongClient(opt KongClientConfig) (*kong.Client, error)

GetKongClient returns a Kong client

func GetKonnectClient added in v1.5.0

func GetKonnectClient(httpClient *http.Client, config KonnectConfig) (*konnect.Client,
	error)

func HTTPClient added in v1.7.0

func HTTPClient() *http.Client

HTTPClient returns a new Go stdlib's net/http.Client with sane default timeouts.

func MergeTags

func MergeTags(obj interface{}, tags []string) error

MergeTags merges Tags in the object with tags.

func MustMergeTags

func MustMergeTags(obj interface{}, tags []string)

MustMergeTags is same as MergeTags but panics if there is an error.

func MustRemoveTags

func MustRemoveTags(obj interface{}, tags []string)

MustRemoveTags is same as RemoveTags but panics if there is an error.

func NameToFilename added in v1.7.0

func NameToFilename(name string) string

NameToFilename clears path separators from strings. Some entity names in Kong and Konnect allow path directory separators. Some decK operations write files using entity names, which is not compatible with names that contain path separators. NameToFilename strips leading separator characters and replaces other instances of the separator with its URL-encoded representation.

func RemoveTags

func RemoveTags(obj interface{}, tags []string) error

RemoveTags removes tags from the Tags in obj.

func SendAnalytics added in v1.7.0

func SendAnalytics(cmd, deckVersion, kongVersion string) error

func UUID

func UUID() string

UUID will generate a random v4 unique identifier

func ZeroOutID added in v1.5.1

func ZeroOutID(obj interface{}, altName *string, withID bool)

func ZeroOutTimestamps added in v1.5.1

func ZeroOutTimestamps(obj interface{})

Types

type AtomicInt32Counter added in v1.8.0

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

func (*AtomicInt32Counter) Count added in v1.8.0

func (a *AtomicInt32Counter) Count() int32

func (*AtomicInt32Counter) Increment added in v1.8.0

func (a *AtomicInt32Counter) Increment(delta int32)

type Defaulter

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

Defaulter registers types and fills in struct fields with default values.

func GetKongDefaulter

func GetKongDefaulter() (*Defaulter, error)

GetKongDefaulter returns a defaulter which can set default values for Kong entities.

func (*Defaulter) MustSet

func (d *Defaulter) MustSet(arg interface{})

MustSet is like Set but panics if there is an error.

func (*Defaulter) Register

func (d *Defaulter) Register(def interface{}) error

Register registers a type and it's default value. The default value is passed in and the type is inferred from the default value.

func (*Defaulter) Set

func (d *Defaulter) Set(arg interface{}) error

Set fills in default values in a struct of a registered type.

type ErrArray

type ErrArray struct {
	Errors []error
}

ErrArray holds an array of errors.

func (ErrArray) Error

func (e ErrArray) Error() string

Error returns a pretty string of errors present.

type KongClientConfig

type KongClientConfig struct {
	Address   string
	Workspace string

	TLSServerName string

	TLSCACert string

	TLSSkipVerify bool
	Debug         bool

	SkipWorkspaceCrud bool

	Headers []string

	HTTPClient *http.Client

	Timeout int
}

KongClientConfig holds config details to use to talk to a Kong server.

func (*KongClientConfig) ForWorkspace added in v1.2.3

func (kc *KongClientConfig) ForWorkspace(name string) KongClientConfig

ForWorkspace returns a copy of KongClientConfig that produces a KongClient for the workspace specified by argument.

type KongRawState

type KongRawState struct {
	Services []*kong.Service
	Routes   []*kong.Route

	Plugins []*kong.Plugin

	Upstreams []*kong.Upstream
	Targets   []*kong.Target

	Certificates   []*kong.Certificate
	SNIs           []*kong.SNI
	CACertificates []*kong.CACertificate

	Consumers      []*kong.Consumer
	CustomEntities []*custom.Entity

	KeyAuths    []*kong.KeyAuth
	HMACAuths   []*kong.HMACAuth
	JWTAuths    []*kong.JWTAuth
	BasicAuths  []*kong.BasicAuth
	ACLGroups   []*kong.ACLGroup
	Oauth2Creds []*kong.Oauth2Credential
	MTLSAuths   []*kong.MTLSAuth

	RBACRoles               []*kong.RBACRole
	RBACEndpointPermissions []*kong.RBACEndpointPermission
}

KongRawState contains all of Kong Data

type KonnectConfig added in v1.5.0

type KonnectConfig struct {
	Email    string
	Password string
	Debug    bool

	Address string
}

type KonnectRawState added in v1.5.0

type KonnectRawState struct {
	ServicePackages []*konnect.ServicePackage
	Documents       []*konnect.Document
}

KonnectRawState contains all of Konnect resources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳