utils

package module
v0.0.0-...-76c2fa8 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClustersPageSize             = 50
	BackplaneAPIURLRegexp string = `(?mi)^https:\/\/api\.(.*)backplane\.(.*)`
	ClusterIDRegexp       string = "/?backplane/cluster/([a-zA-Z0-9]+)/?"
)

Variables

This section is empty.

Functions

func CheckBackplaneVersion

func CheckBackplaneVersion(cmd *cobra.Command)

CheckBackplaneVersion checks the backplane version and aims to only report any errors encountered in the process in order to avoid calling functions act as usual

func CheckHealth

func CheckHealth(url string) bool

CheckHealth check if the given url returns http status 200 return false if it not 200 or encounter any error.

func CreateTempKubeConfig

func CreateTempKubeConfig(kubeConfig *api.Config) error

func GetDefaultKubeConfig

func GetDefaultKubeConfig() api.Config

GetDefaultKubeConfig return default kube config

func GetFormattedError

func GetFormattedError(rsp *http.Response) error

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the OS for an available port to listen to. https://github.com/phayes/freeport/blob/master/freeport.go

func GetStringFieldFromJWT

func GetStringFieldFromJWT(token string, field string) (string, error)

func MatchBaseDomain

func MatchBaseDomain(longHostname, baseDomain string) bool

MatchBaseDomain returns true if the given longHostname matches the baseDomain.

func ModifyTempKubeConfigFileName

func ModifyTempKubeConfigFileName(fileName string) error

ModifyTempKubeConfigFileName update default temp kube config file name

func ParseParamsFlag

func ParseParamsFlag(paramsFlag []string) (map[string]string, error)

func ReadKubeconfigRaw

func ReadKubeconfigRaw() (api.Config, error)

func RemoveTempKubeConfig

func RemoveTempKubeConfig()

func RenderJSON

func RenderJSON(reader io.Reader) error

RenderJSON is an effectual function that renders the reader as JSON returns err if render fails

func RenderJSONBytes

func RenderJSONBytes(i interface{}) error

RenderJSONBytes is an effectual function that renders the reader as JSON returns err if render fails

func RenderTabbedTable

func RenderTabbedTable(headers []string, data [][]string)

RenderTabbedTable only uses tabs and renders based on terminal width available It keeps the first column in it's full length and truncates others

func RenderTable

func RenderTable(headers []string, data [][]string)

func TryParseBackplaneAPIError

func TryParseBackplaneAPIError(rsp *http.Response) (*BackplaneApi.Error, error)

func TryPrintAPIError

func TryPrintAPIError(rsp *http.Response, rawFlag bool) error

func TryRenderErrorRaw

func TryRenderErrorRaw(rsp *http.Response) error

Types

type BackplaneCluster

type BackplaneCluster struct {
	ClusterID     string
	ClusterURL    string // for e.g. https://api-backplane.apps.com/backplane/cluster/<cluster-id>/
	BackplaneHost string // for e.g. https://api-backplane.apps.com
}

type ClientUtils

type ClientUtils interface {
	MakeBackplaneAPIClient(base string) (BackplaneApi.ClientWithResponsesInterface, error)
	MakeBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientWithResponsesInterface, error)
	MakeRawBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientInterface, error)
	MakeRawBackplaneAPIClient(base string) (BackplaneApi.ClientInterface, error)
	GetBackplaneClient(backplaneURL string, ocmToken *string) (client BackplaneApi.ClientInterface, err error)
	SetClientProxyURL(proxyURL string) error
}
var (
	DefaultClientUtils ClientUtils = &DefaultClientUtilsImpl{}
)

type ClusterUtils

type ClusterUtils interface {
	GetClusterIDAndHostFromClusterURL(clusterURL string) (string, string, error)
	GetBackplaneClusterFromConfig() (BackplaneCluster, error)
	GetBackplaneClusterFromClusterKey(clusterKey string) (BackplaneCluster, error)
	GetBackplaneCluster(params ...string) (BackplaneCluster, error)
}
var (
	DefaultClusterUtils ClusterUtils = &DefaultClusterUtilsImpl{}
)

type DefaultClientUtilsImpl

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

func (*DefaultClientUtilsImpl) GetBackplaneClient

func (s *DefaultClientUtilsImpl) GetBackplaneClient(backplaneURL string, ocmToken *string) (client BackplaneApi.ClientInterface, err error)

GetBackplaneClient returns authenticated Backplane API client

func (*DefaultClientUtilsImpl) MakeBackplaneAPIClient

func (*DefaultClientUtilsImpl) MakeBackplaneAPIClientWithAccessToken

func (*DefaultClientUtilsImpl) MakeBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientWithResponsesInterface, error)

func (*DefaultClientUtilsImpl) MakeRawBackplaneAPIClient

func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClient(base string) (BackplaneApi.ClientInterface, error)

func (*DefaultClientUtilsImpl) MakeRawBackplaneAPIClientWithAccessToken

func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientInterface, error)

func (*DefaultClientUtilsImpl) SetClientProxyURL

func (s *DefaultClientUtilsImpl) SetClientProxyURL(proxyURL string) error

SetClientProxyURL Set client proxy url for http transport

type DefaultClusterUtilsImpl

type DefaultClusterUtilsImpl struct{}

func (*DefaultClusterUtilsImpl) GetBackplaneCluster

func (s *DefaultClusterUtilsImpl) GetBackplaneCluster(params ...string) (BackplaneCluster, error)

GetBackplaneCluster returns BackplaneCluster, if clusterKey is present it will try to search for cluster otherwise it will load cluster from the kube config file.

func (*DefaultClusterUtilsImpl) GetBackplaneClusterFromClusterKey

func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromClusterKey(clusterKey string) (BackplaneCluster, error)

GetBackplaneClusterFromClusterKey get the backplane cluster from the given cluster

func (*DefaultClusterUtilsImpl) GetBackplaneClusterFromConfig

func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromConfig() (BackplaneCluster, error)

GetBackplaneClusterFromConfig get the backplane cluster from config file

func (*DefaultClusterUtilsImpl) GetClusterIDAndHostFromClusterURL

func (s *DefaultClusterUtilsImpl) GetClusterIDAndHostFromClusterURL(clusterURL string) (string, string, error)

GetClusterIDAndHostFromClusterURL with Cluster URL format: https://api-backplane.apps.com/backplane/cluster/<cluster-id>/

type DefaultOCMInterfaceImpl

type DefaultOCMInterfaceImpl struct{}

func (*DefaultOCMInterfaceImpl) GetClusterInfoByID

func (*DefaultOCMInterfaceImpl) GetClusterInfoByID(clusterID string) (*cmv1.Cluster, error)

GetClusterInfoByID calls the OCM to retrieve the cluster info for a given internal cluster id.

func (*DefaultOCMInterfaceImpl) GetManagingCluster

func (o *DefaultOCMInterfaceImpl) GetManagingCluster(targetClusterID string) (clusterID, clusterName string, err error)

GetManagingCluster returns the managing cluster (hive shard or hypershift management cluster) for the given clusterID

func (*DefaultOCMInterfaceImpl) GetOCMAccessToken

func (*DefaultOCMInterfaceImpl) GetOCMAccessToken() (*string, error)

GetOCMAccessToken initiates the OCM connection and returns the access token

func (*DefaultOCMInterfaceImpl) GetPullSecret

func (*DefaultOCMInterfaceImpl) GetPullSecret() (string, error)

GetPullSecret returns pull secret from OCM

func (*DefaultOCMInterfaceImpl) GetServiceCluster

func (*DefaultOCMInterfaceImpl) GetServiceCluster(targetClusterID string) (clusterID, clusterName string, err error)

GetServiceCluster gets the service cluster for a given hpyershift hosted cluster

func (*DefaultOCMInterfaceImpl) GetStsSupportJumpRoleARN

func (*DefaultOCMInterfaceImpl) GetStsSupportJumpRoleARN(clusterID string) (string, error)

func (*DefaultOCMInterfaceImpl) GetTargetCluster

func (*DefaultOCMInterfaceImpl) GetTargetCluster(clusterKey string) (clusterID, clusterName string, err error)

GetTargetCluster returns one single cluster based on the search key and survery.

func (*DefaultOCMInterfaceImpl) IsClusterHibernating

func (*DefaultOCMInterfaceImpl) IsClusterHibernating(clusterID string) (bool, error)

IsClusterHibernating returns a boolean to indicate whether the cluster is hibernating

func (*DefaultOCMInterfaceImpl) IsProduction

func (*DefaultOCMInterfaceImpl) IsProduction() (bool, error)

IsProduction checks if OCM is currently in production env

type DefaultShellChecker

type DefaultShellChecker struct{}

func (DefaultShellChecker) IsValidShell

func (checker DefaultShellChecker) IsValidShell(shellPath string) bool

Helper function to check if a shell is valid

type OCMInterface

type OCMInterface interface {
	IsClusterHibernating(clusterID string) (bool, error)
	GetTargetCluster(clusterKey string) (clusterID, clusterName string, err error)
	GetManagingCluster(clusterKey string) (clusterID, clusterName string, err error)
	GetOCMAccessToken() (*string, error)
	GetServiceCluster(clusterKey string) (clusterID, clusterName string, err error)
	GetClusterInfoByID(clusterID string) (*cmv1.Cluster, error)
	IsProduction() (bool, error)
	GetPullSecret() (string, error)
	GetStsSupportJumpRoleARN(clusterID string) (string, error)
}
var DefaultOCMInterface OCMInterface = &DefaultOCMInterfaceImpl{}

type ShellCheckerInterface

type ShellCheckerInterface interface {
	IsValidShell(shellPath string) bool
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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