util

package
v0.25.9 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWritePermissions = 0760

	MaximumNewDirectoryAttempts = 1000
)
View Source
const (
	CONFIGFILENAME = "config"
)
View Source
const (
	DefaultSuggestionsMinimumDistance = 2
)

Variables

View Source
var ColorError = color.New(color.FgRed).SprintFunc()
View Source
var ColorInfo = color.New(color.FgGreen).SprintFunc()
View Source
var ColorStatus = color.New(color.FgBlue).SprintFunc()
View Source
var ColorWarning = color.New(color.FgYellow).SprintFunc()

Functions

func AreCertsSame added in v0.22.0

func AreCertsSame(p common.Printer, server, local []byte) bool

func AreCertsTrusted added in v0.22.0

func AreCertsTrusted(host string, certs []byte) (bool, error)

func BinaryLocation

func BinaryLocation() (string, error)

func CacheDir

func CacheDir() (string, error)

func ConfigDir

func ConfigDir() (string, error)

func Confirm

func Confirm(message string, defaultValue bool, help string) bool

Confirm prompts the user to confirm something

func ControllerCreate added in v0.24.0

func ControllerCreate(api API, entityType string, body string, out io.Writer, logRequestJson, logResponseJson bool, timeout int, verbose bool) (*gabs.Container, error)

ControllerCreate will create entities of the given type in the given Edge Controller

func ControllerDelete added in v0.24.0

func ControllerDelete(api API, entityType string, id string, body string, out io.Writer, logRequestJson bool, logResponseJson bool, timeout int, verbose bool) error

ControllerDelete will delete entities of the given type in the given Controller

func ControllerDetailEntity added in v0.24.0

func ControllerDetailEntity(api API, entityType, entityId string, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error)

func ControllerList added in v0.24.0

func ControllerList(api API, path string, params url.Values, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error)

ControllerList will list entities of the given type in the given Edge Controller

func ControllerUpdate added in v0.24.0

func ControllerUpdate(api API, entityType string, body string, out io.Writer, method string, logRequestJson, logResponseJSON bool, timeout int, verbose bool) (*gabs.Container, error)

ControllerUpdate will update entities of the given type in the given Edge Controller

func CopyDirOverwrite

func CopyDirOverwrite(src string, dst string) (err error)

CopyDirOverwrite copies from the source dir to the destination dir overwriting files along the way

func CreateUniqueDirectory

func CreateUniqueDirectory(dir string, name string, maximumAttempts int) (string, error)

CreateUniqueDirectory creates a new directory but if the combination of dir and name exists then append a number until a unique name is found

func DownloadArtifactoryFile

func DownloadArtifactoryFile(url string, filepath string) (err error)

DownloadArtifactoryFile will download a file from the given Artifactory URL

func DownloadFile

func DownloadFile(filepath string, url string) (err error)

Download a file from the given URL

func DownloadGitHubReleaseAsset added in v0.16.3

func DownloadGitHubReleaseAsset(fullUrl string, filepath string) (err error)

DownloadGitHubReleaseAsset will download a file from the given GitHUb release area

func EdgeControllerGetManagementApiBasePath added in v0.20.0

func EdgeControllerGetManagementApiBasePath(host string, cert string) string

EdgeControllerGetManagementApiBasePath accepts host as `http://domain:port` and attempts to determine the proper path that should be used to access the Edge Management API. Depending on the version of the Edge Controller the API may be monolith on `/edge/<version>` and `/` or split into `/edge/management/<version>` and `/edge/client/<version>`.

func EdgeControllerList

func EdgeControllerList(path string, params url.Values, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error)

EdgeControllerList will list entities of the given type in the given Edge Controller

func EdgeControllerListSubEntities

func EdgeControllerListSubEntities(entityType, subType, entityId string, filter string, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error)

EdgeControllerListSubEntities will list entities of the given type in the given Edge Controller

func EdgeControllerLogin

func EdgeControllerLogin(url string, cert string, authentication string, out io.Writer, logJSON bool, timeout int, verbose bool) (*gabs.Container, error)

EdgeControllerLogin will authenticate to the given Edge Controller

func EdgeControllerRequest

func EdgeControllerRequest(entityType string, out io.Writer, logJSON bool, timeout int, verbose bool, doRequest func(*resty.Request, string) (*resty.Response, error)) (*gabs.Container, error)

func EdgeControllerVerify

func EdgeControllerVerify(entityType, id, body string, out io.Writer, logJSON bool, timeout int, verbose bool) error

EdgeControllerVerify will verify entities of the given type in the given Edge Controller

func EnvironmentsDir

func EnvironmentsDir() (string, error)

func FabricConfigDir

func FabricConfigDir() (string, error)

func FileExists

func FileExists(path string) (bool, error)

func FirstNotEmptyString

func FirstNotEmptyString(values ...string) string

FirstNotEmptyString returns the first non empty string or the empty string if none can be found

func GetArtifactoryPath

func GetArtifactoryPath(staging bool, appName string, branch string) string

func GetCommandOutput

func GetCommandOutput(dir string, name string, args ...string) (string, error)

GetCommandOutput evaluates the given command and returns the trimmed output

func GetLatestGitHubReleaseAsset added in v0.16.3

func GetLatestGitHubReleaseAsset(verbose bool, appName string) (string, error)

func GetLatestGitHubReleaseVersion added in v0.16.3

func GetLatestGitHubReleaseVersion(verbose bool, appName string) (semver.Version, error)

func GetLatestSemanticVersionFromArtifactory

func GetLatestSemanticVersionFromArtifactory(verbose bool, staging bool, branch string, appName string, versionWildcard string) (semver.Version, error)

func GetLatestTerraformProviderVersionFromArtifactory

func GetLatestTerraformProviderVersionFromArtifactory(branch string, provider string) (semver.Version, error)

func GetLatestVersionFromArtifactory

func GetLatestVersionFromArtifactory(verbose bool, staging bool, branch string, appName string) (semver.Version, error)

func GetTerraformProviderArtifactoryPath

func GetTerraformProviderArtifactoryPath(provider string, branch string) string

func GetWellKnownCerts added in v0.22.0

func GetWellKnownCerts(host string) ([]byte, []*x509.Certificate, error)

func HomeDir

func HomeDir() string

func InvalidArg

func InvalidArg(value string, values []string) error

func InvalidArgError

func InvalidArgError(value string, err error) error

func InvalidArgf

func InvalidArgf(value string, message string, a ...interface{}) error

func InvalidOption

func InvalidOption(name string, value string, values []string) error

func InvalidOptionError

func InvalidOptionError(option string, value string, err error) error

func InvalidOptionf

func InvalidOptionf(option string, value string, message string, a ...interface{}) error

func IsEmpty

func IsEmpty(name string) (bool, error)

func IsServerTrusted added in v0.22.0

func IsServerTrusted(host string) (bool, error)

func LoadBytes

func LoadBytes(dir, name string) ([]byte, error)

loads a file

func LogReleaseVersionCheck added in v0.25.3

func LogReleaseVersionCheck(ziti_component string)

func MissingOption

func MissingOption(name string) error

func NewEdgeManagementClient added in v0.20.3

func NewEdgeManagementClient(clientOpts ClientOpts) (*rest_management_api_client.ZitiEdgeManagement, error)

func NewEmptyParentCmd

func NewEmptyParentCmd(name string, description string) *cobra.Command

NewEmptyParentCmd creates a new cobra command with no parent

func NewEnvironmentDir

func NewEnvironmentDir(envName string) (string, error)

func NewFabricManagementClient added in v0.24.2

func NewFabricManagementClient(clientOpts ClientOpts) (*fabric_rest_client.ZitiFabric, error)

func NewRequest added in v0.24.0

func NewRequest(restClientIdentity RestClientIdentity, timeoutInSeconds int, verbose bool) (*resty.Request, error)

func PKIRootDir

func PKIRootDir() (string, error)

func PathWithBinary

func PathWithBinary() string

func PersistRestClientConfig added in v0.22.0

func PersistRestClientConfig(config *RestClientConfig) error

func PickName

func PickName(names []string, message string) (string, error)

func PickNameWithDefault

func PickNameWithDefault(names []string, message string, defaultValue string) (string, error)

func PickNames

func PickNames(names []string, message string) ([]string, error)

func PickPassword

func PickPassword(message string) (string, error)

func PickRequiredNameWithDefault

func PickRequiredNameWithDefault(names []string, message string, defaultValue string) (string, error)

func PickValue

func PickValue(message string, defaultValue string, required bool) (string, error)

func ReadCert added in v0.22.0

func ReadCert(id string) ([]byte, string, error)

func ReadZitiAppConfigFile

func ReadZitiAppConfigFile(zitiApp string, configData interface{}) error

ReadZitiAppConfigFile reads in the config file data for the given Ziti application from an appropriate location

func ReadZitiAppFile

func ReadZitiAppFile(zitiApp string, fileType string, configData interface{}) error

ReadZitiAppFile reads application data (config, session, preferences, etc) for the given Ziti application from an appropriate location

func RegexpSplit

func RegexpSplit(text string, regexSeperator string) []string

RegexpSplit splits a string into an array using the regexSep as a separator

func RenameDir

func RenameDir(src string, dst string, force bool) (err error)

func RenameFile

func RenameFile(src string, dst string) (err error)

func ReverseStrings

func ReverseStrings(a []string)

func RunAWSCommand

func RunAWSCommand(args ...string) error

RunAWSCommand evaluates the given AWS CLI command and returns the trimmed output

func RunCommand

func RunCommand(dir string, name string, args ...string) error

RunCommand evaluates the given command and returns the trimmed output

func SelectNames

func SelectNames(names []string, message string, selectAll bool) ([]string, error)

SelectNames select which names from the list should be chosen

func SelectNamesWithFilter

func SelectNamesWithFilter(names []string, message string, selectAll bool, filter string) ([]string, error)

SelectNamesWithFilter selects from a list of names with a given filter. Optionally selecting them all

func SortedMapKeys

func SortedMapKeys(m map[string]string) []string

SortedMapKeys returns the sorted keys of the given map

func StringArrayIndex

func StringArrayIndex(array []string, value string) int

func StringArrayToLower

func StringArrayToLower(values []string) []string

StringArrayToLower returns a string slice with all the values converted to lower case

func StringIndexes

func StringIndexes(text string, value string) []int

StringIndexes returns all the indices where the value occurs in the given string

func StringMatchesAny

func StringMatchesAny(text string, includes []string, excludes []string) bool

StringMatches returns true if the given text matches the includes/excludes lists

func StringMatchesPattern

func StringMatchesPattern(text string, pattern string) bool

StringMatchesPattern returns true if the given text matches the includes/excludes lists

func SuggestionsFor

func SuggestionsFor(typedName string, values []string, suggestionsMinimumDistance int, explicitSuggestions ...string) []string

func TerraformProviderBinaryLocation

func TerraformProviderBinaryLocation() (string, error)

TerraformProviderBinaryLocation provides the proper location to place a Terraform provider based on the currently running OS. In Mac/Linux, it's `~/.terraform.d/plugins` and on Windows it's `%APPDATA%\terraform.d\plugins`

func UnTargz

func UnTargz(tarball, target string, onlyFiles []string) error

untargz a tarball to a target, from http://blog.ralch.com/tutorial/golang-working-with-tar-and-gzip

func Unzip added in v0.16.3

func Unzip(src, dest string) error

func WrapIfApiError added in v0.22.0

func WrapIfApiError(err error) error

func WriteCert added in v0.22.0

func WriteCert(p common.Printer, id string, cert []byte) (string, error)

func WriteZitiAppConfigFile

func WriteZitiAppConfigFile(zitiApp string, configData interface{}) error

WriteZitiAppConfigFile writes out the config file data for the given Ziti application to the appropriate config file

func WriteZitiAppFile

func WriteZitiAppFile(zitiApp string, fileType string, appData interface{}) error

WriteZitiAppFile writes application data (config, session, preferences, etc) to an appropriate location

func ZitiAppConfigDir

func ZitiAppConfigDir(zitiApp string) (string, error)

Types

type API added in v0.24.0

type API string
const (
	FabricAPI API = "fabric"
	EdgeAPI   API = "edge"
)

type AQLResult

type AQLResult struct {
	Repo       string
	Path       string
	Name       string
	Type       string
	Size       int
	Created    string
	CreatedBy  string
	Modified   string
	ModifiedBy string
	Updated    string
	Properties []struct {
		Key   string
		Value string
	}
}

Used to parse the '/api/search/aql' response from Artifactory

type AQLVars

type AQLVars struct {
	SemverMajor    string
	SemverMaxMinor string
	SemverMinMinor string
	App            string
	Arch           string
	OS             string
}

type ApiErrorPayload added in v0.22.0

type ApiErrorPayload interface {
	GetPayload() *rest_model.APIErrorEnvelope
}

type ArtifactoryAQLData

type ArtifactoryAQLData struct {
	Results []AQLResult
}

type ArtifactoryStorageChildrenData

type ArtifactoryStorageChildrenData struct {
	URI    string `json:"uri"`
	Folder bool   `json:"folder"`
}

Used to parse the '/api/storage' response from Artifactory

func GetCurrentSnapshotListFromArtifactory

func GetCurrentSnapshotListFromArtifactory(verbose bool) ([]ArtifactoryStorageChildrenData, error)

type ArtifactoryStorageData

type ArtifactoryStorageData struct {
	Repo         string                           `json:"repo"`
	Path         string                           `json:"path"`
	Created      string                           `json:"created"`
	LastModified string                           `json:"lastModified"`
	LastUpdated  string                           `json:"lastUpdated"`
	Children     []ArtifactoryStorageChildrenData `json:"children"`
	URI          string                           `json:"uri"`
}

type ArtifactoryVersionsData

type ArtifactoryVersionsData struct {
	Version   string `json:"version"`
	Artifacts []struct {
	}
}

Used to parse the '/api/versions' response from Artifactory

type ClientOpts added in v0.24.2

type ClientOpts interface {
	OutputRequestJson() bool
	OutputResponseJson() bool
	OutputWriter() io.Writer
	ErrOutputWriter() io.Writer
}

type Data

type Data struct {
	TagSet []struct {
		Value string `json:"Value"`
		Key   string `json:"Key"`
	}
}

Used to parse the 'get-object-tagging' response

type EdgeManagementAuth added in v0.20.3

type EdgeManagementAuth struct {
	Token string
}

func (EdgeManagementAuth) AuthenticateRequest added in v0.20.3

func (e EdgeManagementAuth) AuthenticateRequest(request openApiRuntime.ClientRequest, registry strfmt.Registry) error

type GitHubReleasesData added in v0.16.3

type GitHubReleasesData struct {
	Version string `json:"tag_name"`
	Assets  []struct {
		BrowserDownloadURL string `json:"browser_download_url"`
	}
}

Used to parse the '/releases/latest' response from GitHub

type RestApiError added in v0.22.0

type RestApiError struct {
	ApiErrorPayload
}

func (RestApiError) Error added in v0.22.0

func (a RestApiError) Error() string

type RestClientConfig added in v0.22.0

type RestClientConfig struct {
	EdgeIdentities   map[string]*RestClientEdgeIdentity   `json:"edgeIdentities"`
	FabricIdentities map[string]*RestClientFabricIdentity `json:"fabricIdentities"`
	Default          string                               `json:"default"`
}

func LoadRestClientConfig added in v0.22.0

func LoadRestClientConfig() (*RestClientConfig, string, error)

func (*RestClientConfig) GetIdentity added in v0.22.0

func (self *RestClientConfig) GetIdentity() string

type RestClientEdgeIdentity added in v0.24.0

type RestClientEdgeIdentity struct {
	Url       string `json:"url"`
	Username  string `json:"username"`
	Token     string `json:"token"`
	LoginTime string `json:"loginTime"`
	CaCert    string `json:"caCert,omitempty"`
	ReadOnly  bool   `json:"readOnly"`
}

func (*RestClientEdgeIdentity) GetBaseUrlForApi added in v0.24.0

func (self *RestClientEdgeIdentity) GetBaseUrlForApi(api API) (string, error)

func (*RestClientEdgeIdentity) IsReadOnly added in v0.24.0

func (self *RestClientEdgeIdentity) IsReadOnly() bool

func (*RestClientEdgeIdentity) NewClient added in v0.24.0

func (self *RestClientEdgeIdentity) NewClient(timeout time.Duration, verbose bool) (*resty.Client, error)

func (*RestClientEdgeIdentity) NewEdgeManagementClient added in v0.24.0

func (self *RestClientEdgeIdentity) NewEdgeManagementClient(clientOpts ClientOpts) (*rest_management_api_client.ZitiEdgeManagement, error)

func (*RestClientEdgeIdentity) NewFabricManagementClient added in v0.24.2

func (self *RestClientEdgeIdentity) NewFabricManagementClient(clientOpts ClientOpts) (*fabric_rest_client.ZitiFabric, error)

func (*RestClientEdgeIdentity) NewRequest added in v0.24.0

func (self *RestClientEdgeIdentity) NewRequest(client *resty.Client) *resty.Request

func (*RestClientEdgeIdentity) NewTlsClientConfig added in v0.24.2

func (self *RestClientEdgeIdentity) NewTlsClientConfig() (*tls.Config, error)

func (*RestClientEdgeIdentity) NewWsHeader added in v0.25.7

func (self *RestClientEdgeIdentity) NewWsHeader() http.Header

type RestClientFabricIdentity added in v0.24.0

type RestClientFabricIdentity struct {
	Url        string `json:"url"`
	CaCert     string `json:"caCert,omitempty"`
	ClientCert string `json:"clientCert,omitempty"`
	ClientKey  string `json:"clientKey,omitempty"`
	ReadOnly   bool   `json:"readOnly"`
}

func (*RestClientFabricIdentity) GetBaseUrlForApi added in v0.24.0

func (self *RestClientFabricIdentity) GetBaseUrlForApi(api API) (string, error)

func (*RestClientFabricIdentity) IsReadOnly added in v0.24.0

func (self *RestClientFabricIdentity) IsReadOnly() bool

func (*RestClientFabricIdentity) NewClient added in v0.24.0

func (self *RestClientFabricIdentity) NewClient(timeout time.Duration, verbose bool) (*resty.Client, error)

func (*RestClientFabricIdentity) NewEdgeManagementClient added in v0.24.0

func (*RestClientFabricIdentity) NewFabricManagementClient added in v0.24.2

func (self *RestClientFabricIdentity) NewFabricManagementClient(clientOpts ClientOpts) (*fabric_rest_client.ZitiFabric, error)

func (*RestClientFabricIdentity) NewRequest added in v0.24.0

func (self *RestClientFabricIdentity) NewRequest(client *resty.Client) *resty.Request

func (*RestClientFabricIdentity) NewTlsClientConfig added in v0.24.2

func (self *RestClientFabricIdentity) NewTlsClientConfig() (*tls.Config, error)

func (*RestClientFabricIdentity) NewWsHeader added in v0.25.7

func (self *RestClientFabricIdentity) NewWsHeader() http.Header

type RestClientIdentity added in v0.22.0

type RestClientIdentity interface {
	NewTlsClientConfig() (*tls.Config, error)
	NewClient(timeout time.Duration, verbose bool) (*resty.Client, error)
	NewRequest(client *resty.Client) *resty.Request
	IsReadOnly() bool
	GetBaseUrlForApi(api API) (string, error)
	NewEdgeManagementClient(clientOpts ClientOpts) (*rest_management_api_client.ZitiEdgeManagement, error)
	NewFabricManagementClient(clientOpts ClientOpts) (*fabric_rest_client.ZitiFabric, error)
	NewWsHeader() http.Header
}

func LoadSelectedIdentity added in v0.22.0

func LoadSelectedIdentity() (RestClientIdentity, error)

func LoadSelectedIdentityForApi added in v0.24.0

func LoadSelectedIdentityForApi(api API) (RestClientIdentity, error)

func LoadSelectedRWIdentity added in v0.22.0

func LoadSelectedRWIdentity() (RestClientIdentity, error)

func LoadSelectedRWIdentityForApi added in v0.24.0

func LoadSelectedRWIdentityForApi(api API) (RestClientIdentity, error)

type Session

type Session struct {
	Host  string
	Token string
	Cert  string
}

Session stores configuration options for the CLI

func (*Session) GetBaseUrl

func (session *Session) GetBaseUrl() string

func (*Session) GetCert

func (session *Session) GetCert() string

func (*Session) GetToken

func (session *Session) GetToken() string

func (*Session) Load

func (session *Session) Load() error

Load reads in the Ziti CLI session file

func (*Session) Persist

func (session *Session) Persist() error

Persist writes out the Ziti CLI session file

func (*Session) String

func (session *Session) String() string

Jump to

Keyboard shortcuts

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