util

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 47 Imported by: 4

Documentation

Index

Constants

View Source
const (
	CONFIGFILENAME = "config"
)
View Source
const (
	DefaultSuggestionsMinimumDistance = 2
)
View Source
const (
	DefaultWritePermissions = 0760
)

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.27.0

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

func AreCertsTrusted added in v0.27.0

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

func BinaryLocation added in v0.27.0

func BinaryLocation() (string, error)

func CacheDir added in v0.27.0

func CacheDir() (string, error)

func ConfigDir

func ConfigDir() (string, error)

func Confirm added in v0.27.0

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

Confirm prompts the user to confirm something

func ControllerCreate added in v0.27.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.27.0

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

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

func ControllerDetailEntity added in v0.27.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.27.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.27.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 CopyDir added in v0.27.0

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

credit https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func CopyDirOverwrite added in v0.27.0

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

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

func CopyFile added in v0.27.0

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

credit https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func CreateUniqueDirectory added in v0.27.0

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 added in v0.27.0

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

DownloadArtifactoryFile will download a file from the given Artifactory URL

func DownloadFile added in v0.27.0

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

Download a file from the given URL

func EdgeControllerGetManagementApiBasePath added in v0.27.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 added in v0.27.0

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 added in v0.27.0

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 EdgeControllerRequest added in v0.27.0

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 added in v0.27.0

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 added in v0.27.0

func EnvironmentsDir() (string, error)

func FileExists added in v0.27.0

func FileExists(path string) (bool, error)

func FirstNotEmptyString added in v0.27.0

func FirstNotEmptyString(values ...string) string

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

func GetArtifactoryPath added in v0.27.0

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

func GetLatestSemanticVersionFromArtifactory added in v0.27.0

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

func GetLatestTerraformProviderVersionFromArtifactory added in v0.27.0

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

func GetLatestVersionFromArtifactory added in v0.27.0

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

func GetTerraformProviderArtifactoryPath added in v0.27.0

func GetTerraformProviderArtifactoryPath(provider string, branch string) string

func GetWellKnownCerts added in v0.27.0

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

func HomeDir added in v0.27.0

func HomeDir() string

func InvalidArg added in v0.27.0

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

func InvalidArgError added in v0.27.0

func InvalidArgError(value string, err error) error

func InvalidArgf added in v0.27.0

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

func InvalidOption added in v0.27.0

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

func InvalidOptionError added in v0.27.0

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

func InvalidOptionf added in v0.27.0

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

func IsEmpty added in v0.27.0

func IsEmpty(name string) (bool, error)

func IsServerTrusted added in v0.27.0

func IsServerTrusted(host string) (bool, error)

func LoadBytes added in v0.27.0

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

loads a file

func LogReleaseVersionCheck added in v0.27.0

func LogReleaseVersionCheck(zitiComponent string)

func MissingOption added in v0.27.0

func MissingOption(name string) error

func NewClient added in v0.28.0

func NewClient() *resty.Client

Use a 2-second timeout with a retry count of 5

func NewEdgeManagementClient added in v0.27.0

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

func NewEmptyParentCmd added in v0.27.0

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

NewEmptyParentCmd creates a new cobra command with no parent

func NewEnvironmentDir added in v0.27.0

func NewEnvironmentDir(envName string) (string, error)

func NewFabricManagementClient added in v0.27.0

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

func NewRequest added in v0.27.0

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

func OutputJson added in v0.28.0

func OutputJson(out io.Writer, data []byte)

func PKIRootDir added in v0.27.0

func PKIRootDir() (string, error)

func PathWithBinary added in v0.27.0

func PathWithBinary() string

func PersistRestClientConfig added in v0.27.0

func PersistRestClientConfig(config *RestClientConfig) error

func PickName added in v0.27.0

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

func PickNameWithDefault added in v0.27.0

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

func PickNames added in v0.27.0

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

func PickPassword added in v0.27.0

func PickPassword(message string) (string, error)

func PickRequiredNameWithDefault added in v0.27.0

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

func PickValue added in v0.27.0

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

func PrettyPrintResponse added in v0.28.0

func PrettyPrintResponse(resp *resty.Response) string

func ReadCert added in v0.27.0

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

func ReadZitiAppConfigFile added in v0.27.0

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 added in v0.27.0

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 added in v0.27.0

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

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

func RenameDir added in v0.27.0

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

func RenameFile added in v0.27.0

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

func ReverseStrings added in v0.27.0

func ReverseStrings(a []string)

func SelectNames added in v0.27.0

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

SelectNames select which names from the list should be chosen

func SelectNamesWithFilter added in v0.27.0

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 added in v0.27.0

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

SortedMapKeys returns the sorted keys of the given map

func StringArrayIndex added in v0.27.0

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

func StringArrayToLower added in v0.27.0

func StringArrayToLower(values []string) []string

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

func StringIndexes added in v0.27.0

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

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

func StringMatchesAny added in v0.27.0

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

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

func StringMatchesPattern added in v0.27.0

func StringMatchesPattern(text string, pattern string) bool

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

func SuggestionsFor added in v0.27.0

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

func TerraformProviderBinaryLocation added in v0.27.0

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 added in v0.27.0

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 WrapIfApiError added in v0.27.0

func WrapIfApiError(err error) error

func WriteCert added in v0.27.0

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

func WriteZitiAppConfigFile added in v0.27.0

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 added in v0.27.0

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

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

func ZitiAppConfigDir added in v0.27.0

func ZitiAppConfigDir(zitiApp string) (string, error)

Types

type API added in v0.27.0

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

type AQLResult added in v0.27.0

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 added in v0.27.0

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

type ApiErrorPayload added in v0.27.0

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

type ArtifactoryAQLData added in v0.27.0

type ArtifactoryAQLData struct {
	Results []AQLResult
}

type ArtifactoryStorageChildrenData added in v0.27.0

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

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

func GetCurrentSnapshotListFromArtifactory added in v0.27.0

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

type ArtifactoryStorageData added in v0.27.0

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 added in v0.27.0

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

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

type ClientOpts added in v0.27.0

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

type Data added in v0.27.0

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.27.0

type EdgeManagementAuth struct {
	Token string
}

func (EdgeManagementAuth) AuthenticateRequest added in v0.27.0

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

type RestApiError added in v0.27.0

type RestApiError struct {
	ApiErrorPayload
}

func (RestApiError) Error added in v0.27.0

func (a RestApiError) Error() string

type RestClientConfig added in v0.27.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.27.0

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

func (*RestClientConfig) GetIdentity added in v0.27.0

func (self *RestClientConfig) GetIdentity() string

type RestClientEdgeIdentity added in v0.27.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.27.0

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

func (*RestClientEdgeIdentity) IsReadOnly added in v0.27.0

func (self *RestClientEdgeIdentity) IsReadOnly() bool

func (*RestClientEdgeIdentity) NewClient added in v0.27.0

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

func (*RestClientEdgeIdentity) NewEdgeManagementClient added in v0.27.0

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

func (*RestClientEdgeIdentity) NewFabricManagementClient added in v0.27.0

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

func (*RestClientEdgeIdentity) NewRequest added in v0.27.0

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

func (*RestClientEdgeIdentity) NewTlsClientConfig added in v0.27.0

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

func (*RestClientEdgeIdentity) NewWsHeader added in v0.27.0

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

type RestClientFabricIdentity added in v0.27.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.27.0

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

func (*RestClientFabricIdentity) IsReadOnly added in v0.27.0

func (self *RestClientFabricIdentity) IsReadOnly() bool

func (*RestClientFabricIdentity) NewClient added in v0.27.0

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

func (*RestClientFabricIdentity) NewEdgeManagementClient added in v0.27.0

func (*RestClientFabricIdentity) NewFabricManagementClient added in v0.27.0

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

func (*RestClientFabricIdentity) NewRequest added in v0.27.0

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

func (*RestClientFabricIdentity) NewTlsClientConfig added in v0.27.0

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

func (*RestClientFabricIdentity) NewWsHeader added in v0.27.0

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

type RestClientIdentity added in v0.27.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.27.0

func LoadSelectedIdentity() (RestClientIdentity, error)

func LoadSelectedIdentityForApi added in v0.27.0

func LoadSelectedIdentityForApi(api API) (RestClientIdentity, error)

func LoadSelectedRWIdentity added in v0.27.0

func LoadSelectedRWIdentity() (RestClientIdentity, error)

func LoadSelectedRWIdentityForApi added in v0.27.0

func LoadSelectedRWIdentityForApi(api API) (RestClientIdentity, error)

type Session added in v0.27.0

type Session struct {
	Host  string
	Token string
	Cert  string
}

Session stores configuration options for the CLI

func (*Session) GetBaseUrl added in v0.27.0

func (session *Session) GetBaseUrl() string

func (*Session) GetCert added in v0.27.0

func (session *Session) GetCert() string

func (*Session) GetToken added in v0.27.0

func (session *Session) GetToken() string

func (*Session) Load added in v0.27.0

func (session *Session) Load() error

Load reads in the Ziti CLI session file

func (*Session) Persist added in v0.27.0

func (session *Session) Persist() error

Persist writes out the Ziti CLI session file

func (*Session) String added in v0.27.0

func (session *Session) String() string

Jump to

Keyboard shortcuts

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