Documentation
¶
Index ¶
- Constants
- func AppendUniqNoneEmptyString(slice []string, element string) []string
- func AskQuestionFromPrompt(question string) string
- func CheckBackplaneVersion(cmd *cobra.Command)
- func CheckHealth(url string) bool
- func CheckValidPrompt() bool
- func CreateTempKubeConfig(kubeConfig *api.Config) error
- func GetContextNickname(namespace, clusterNick, userNick string) string
- func GetDefaultKubeConfig() api.Config
- func GetFormattedError(rsp *http.Response) error
- func GetFreePort() (int, error)
- func GetStringFieldFromJWT(token string, field string) (string, error)
- func GetUsernameFromJWT(token string) string
- func MatchBaseDomain(longHostname, baseDomain string) bool
- func ModifyTempKubeConfigFileName(fileName string) error
- func ParseParamsFlag(paramsFlag []string) (map[string]string, error)
- func ReadKubeconfigRaw() (api.Config, error)
- func RemoveTempKubeConfig()
- func RenderJSON(reader io.Reader) error
- func RenderJSONBytes(i interface{}) error
- func RenderTabbedTable(headers []string, data [][]string)
- func RenderTable(headers []string, data [][]string)
- func TryParseBackplaneAPIError(rsp *http.Response) (*BackplaneApi.Error, error)
- func TryPrintAPIError(rsp *http.Response, rawFlag bool) error
- func TryRenderErrorRaw(rsp *http.Response) error
- type BackplaneCluster
- type ClientUtils
- type ClusterUtils
- type DefaultClientUtilsImpl
- func (s *DefaultClientUtilsImpl) GetBackplaneClient(backplaneURL string, ocmToken string, proxyURL *string) (client BackplaneApi.ClientInterface, err error)
- func (s *DefaultClientUtilsImpl) MakeBackplaneAPIClient(base string) (BackplaneApi.ClientWithResponsesInterface, error)
- func (*DefaultClientUtilsImpl) MakeBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientWithResponsesInterface, error)
- func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClient(base string) (BackplaneApi.ClientInterface, error)
- func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClientWithAccessToken(base, accessToken string) (BackplaneApi.ClientInterface, error)
- func (s *DefaultClientUtilsImpl) SetClientProxyURL(proxyURL string) error
- type DefaultClusterUtilsImpl
- func (s *DefaultClusterUtilsImpl) GetBackplaneCluster(params ...string) (BackplaneCluster, error)
- func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromClusterKey(clusterKey string) (BackplaneCluster, error)
- func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromConfig() (BackplaneCluster, error)
- func (s *DefaultClusterUtilsImpl) GetClusterIDAndHostFromClusterURL(clusterURL string) (string, string, error)
- type DefaultShellChecker
- type ShellCheckerInterface
Constants ¶
const ( ClustersPageSize = 50 BackplaneAPIURLRegexp string = `(?mi)^https:\/\/api\.(.*)backplane\.(.*)` ClusterIDRegexp string = "/?backplane/cluster/([a-zA-Z0-9]+)/?" )
Variables ¶
This section is empty.
Functions ¶
func AppendUniqNoneEmptyString ¶ added in v0.1.31
AppendUniqNoneEmptyString will append a string to a slice if that string is not empty and is not already part of the slice
func AskQuestionFromPrompt ¶ added in v0.1.31
AskQuestionFromPrompt will first check if stdIn/Err are valid for promting, if not the it will just return empty string otherwise if will display the question to stderr and read answer as returned string
func CheckBackplaneVersion ¶ added in v0.1.5
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 ¶
CheckHealth check if the given url returns http status 200 return false if it not 200 or encounter any error.
func CheckValidPrompt ¶ added in v0.1.31
func CheckValidPrompt() bool
CheckValidPrompt checks that the stdin and stderr are valid for prompt and are not provided by a pipe or file
func CreateTempKubeConfig ¶
CreateTempKubeConfig creates a temporary kubeconfig file from the provided configuration. If kubeConfig is nil, it uses a default configuration. The temporary file is written to the system's temp directory.
func GetContextNickname ¶ added in v0.1.39
GetContextNickname returns a nickname of a context
func GetDefaultKubeConfig ¶ added in v0.1.3
GetDefaultKubeConfig return default kube config
func GetFormattedError ¶
GetFormattedError parses a Backplane API error and returns it as a formatted error message. It extracts the status code and message from the response and formats them for display.
func GetFreePort ¶
GetFreePort asks the OS for an available port to listen to. https://github.com/phayes/freeport/blob/master/freeport.go
func GetStringFieldFromJWT ¶ added in v0.1.7
GetStringFieldFromJWT extracts a string field from a JWT token without verification. It parses the token and returns the specified field value as a string. Returns an error if the token cannot be parsed, the field doesn't exist, or the field is not a string.
func GetUsernameFromJWT ¶ added in v0.1.39
GetUsernameFromJWT returns the username extracted from JWT token
func MatchBaseDomain ¶
MatchBaseDomain returns true if the given longHostname matches the baseDomain.
func ModifyTempKubeConfigFileName ¶ added in v0.1.3
ModifyTempKubeConfigFileName update default temp kube config file name
func ParseParamsFlag ¶
ParseParamsFlag parses command-line parameter flags in the format "key=value". It returns a map of key-value pairs extracted from the input slice. Returns an error if any parameter is missing the '=' separator or has an empty key.
func ReadKubeconfigRaw ¶
ReadKubeconfigRaw reads and parses the raw kubeconfig from the default location. Returns the parsed kubeconfig as an api.Config object.
func RemoveTempKubeConfig ¶
func RemoveTempKubeConfig()
RemoveTempKubeConfig removes the temporary kubeconfig file set in the KUBECONFIG environment variable. It only removes the file if the KUBECONFIG environment variable is set.
func RenderJSON ¶ added in v0.1.9
RenderJSON is an effectual function that renders the reader as JSON returns err if render fails
func RenderJSONBytes ¶ added in v0.1.9
func RenderJSONBytes(i interface{}) error
RenderJSONBytes is an effectual function that renders the reader as JSON returns err if render fails
func RenderTabbedTable ¶
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 ¶
RenderTable renders data in a formatted table using the tablewriter library. It displays the headers and data with proper alignment and formatting.
func TryParseBackplaneAPIError ¶
func TryParseBackplaneAPIError(rsp *http.Response) (*BackplaneApi.Error, error)
TryParseBackplaneAPIError attempts to parse a Backplane API error from an HTTP response. It reads the response body and unmarshals it into a BackplaneApi.Error struct. Returns detailed error information if parsing fails.
func TryPrintAPIError ¶
TryPrintAPIError prints a Backplane API error in either raw JSON or formatted text. When rawFlag is true, it prints the error as raw JSON; otherwise, it prints formatted text.
func TryRenderErrorRaw ¶
TryRenderErrorRaw parses and renders a Backplane API error as JSON output. It attempts to parse the error from the response and display it in JSON format.
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, proxyURL *string) (client BackplaneApi.ClientInterface, err error)
SetClientProxyURL(proxyURL string) error
}
var (
DefaultClientUtils ClientUtils = &DefaultClientUtilsImpl{}
)
type ClusterUtils ¶ added in v0.1.2
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, proxyURL *string) (client BackplaneApi.ClientInterface, err error)
GetBackplaneClient returns authenticated Backplane API client Proxy is optional.
func (*DefaultClientUtilsImpl) MakeBackplaneAPIClient ¶
func (s *DefaultClientUtilsImpl) MakeBackplaneAPIClient(base string) (BackplaneApi.ClientWithResponsesInterface, error)
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 ¶ added in v0.1.9
func (s *DefaultClientUtilsImpl) SetClientProxyURL(proxyURL string) error
SetClientProxyURL Set client proxy url for http transport
type DefaultClusterUtilsImpl ¶ added in v0.1.2
type DefaultClusterUtilsImpl struct{}
func (*DefaultClusterUtilsImpl) GetBackplaneCluster ¶ added in v0.1.2
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 ¶ added in v0.1.2
func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromClusterKey(clusterKey string) (BackplaneCluster, error)
GetBackplaneClusterFromClusterKey get the backplane cluster from the given cluster
func (*DefaultClusterUtilsImpl) GetBackplaneClusterFromConfig ¶ added in v0.1.2
func (s *DefaultClusterUtilsImpl) GetBackplaneClusterFromConfig() (BackplaneCluster, error)
GetBackplaneClusterFromConfig get the backplane cluster from config file
func (*DefaultClusterUtilsImpl) GetClusterIDAndHostFromClusterURL ¶ added in v0.1.2
func (s *DefaultClusterUtilsImpl) GetClusterIDAndHostFromClusterURL(clusterURL string) (string, string, error)
GetClusterIDAndHostFromClusterURL with Cluster URL format: https://api-backplane.apps.com/backplane/cluster/<cluster-id>/
type DefaultShellChecker ¶ added in v0.1.17
type DefaultShellChecker struct{}
func (DefaultShellChecker) IsValidShell ¶ added in v0.1.17
func (checker DefaultShellChecker) IsValidShell(shellPath string) bool
Helper function to check if a shell is valid
type ShellCheckerInterface ¶ added in v0.1.17
var ShellChecker ShellCheckerInterface = DefaultShellChecker{}