util

package
v0.0.0-...-a0d9de1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	URI      string `yaml:"uri"`
}

Credentials struct represents each individual entry in a valid credentials file. URI should be unique for every entry

type CredentialsFile

type CredentialsFile struct {
	Credentials []Credentials `yaml:"credentials"`
}

CredentialsFile struct represents credentials YAML files with a top level field called `credentials` which contains a list of Credentials struct values

type Factory

type Factory interface {
	GetAWSClient() (bbAws.Client, error)
	GetGitLabClient() (bbGitLab.Client, error)
	GetHelmClient(cmd *cobra.Command, namespace string) (helm.Client, error)
	GetK8sClientset(cmd *cobra.Command) (kubernetes.Interface, error)
	GetLoggingClient() bbLog.Client                              // this can't bubble up an error, if it fails it will panic
	GetLoggingClientWithLogger(logger *slog.Logger) bbLog.Client // this can't bubble up an error, if it fails it will panic
	GetRuntimeClient(*runtime.Scheme) (runtimeClient.Client, error)
	GetK8sDynamicClient(cmd *cobra.Command) (dynamic.Interface, error)
	GetOutputClient(cmd *cobra.Command, streams genericIOOptions.IOStreams) bbOutput.Client
	GetRestConfig(cmd *cobra.Command) (*rest.Config, error)
	GetCommandExecutor(cmd *cobra.Command, pod *coreV1.Pod, container string, command []string, stdout io.Writer, stderr io.Writer) (remoteCommand.Executor, error)
	GetCredentialHelper() func(string, string) (string, error)
	GetCommandWrapper(name string, args ...string) *bbUtilApiWrappers.Command
	GetIstioClientSet(cfg *rest.Config) (bbUtilApiWrappers.IstioClientset, error)
	GetConfigClient(command *cobra.Command) (*bbConfig.ConfigClient, error)
	GetViper() *viper.Viper
	GetIOStream() *genericIOOptions.IOStreams
}

Factory is an interface providing initialization methods for various external clients

type UtilityFactory

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

UtilityFactory is a concrete implementation of the Factory interface containing a pre-initialized Viper instance

func NewFactory

func NewFactory() *UtilityFactory

NewFactory initializes and returns a new instance of UtilityFactory

func (*UtilityFactory) GetAWSClient

func (f *UtilityFactory) GetAWSClient() (bbAws.Client, error)

GetAWSClient initializes and returns a new AWS API client

func (*UtilityFactory) GetCommandExecutor

func (f *UtilityFactory) GetCommandExecutor(cmd *cobra.Command, pod *coreV1.Pod, container string, command []string, stdout io.Writer, stderr io.Writer) (remoteCommand.Executor, error)

GetCommandExecutor initializes and returns a new SPDY executor that can run the given command in a Pod in the k8s cluster

Returns a nil executor and an error if there are any issues with the intialization

func (*UtilityFactory) GetCommandWrapper

func (f *UtilityFactory) GetCommandWrapper(name string, args ...string) *bbUtilApiWrappers.Command

GetCommandWrapper initializes and returns a new Command instance which encapsulates the functionality needed to run a CLI command `name` is the command to execute i.e. kubectl `args` string values are all passed to the command as CLI arguments

func (*UtilityFactory) GetConfigClient

func (f *UtilityFactory) GetConfigClient(command *cobra.Command) (*bbConfig.ConfigClient, error)

GetConfigClient initializes and returns a new bbctl config client

Returns a nil client and an error if there are any issues with the intialization

func (*UtilityFactory) GetCredentialHelper

func (f *UtilityFactory) GetCredentialHelper() func(string, string) (string, error)

GetCredentialHelper returns a function reference to the configured credential helper function that can be called to fetch credential values. A custom credential helper function is any CLI executable script which can be passed into this function via the bbctl config settings as a file path.

Credential helper functions take 2 parameters. For the default `credentials-file` implementation, these parameters are:

* component (string) - The Credentials struct field name, either `username` or `password`

* uri (string) - The Credentials struct URI value which uniquely identifies the requested component

These parameters are passed into custom credential helpers as CLI arguments in the same order.

Errors when no credential helper is defined, there is an issue reading credentials from a file, there is an issue running a custom credential helper script, and when an empty value is returned for a requested credential component

func (*UtilityFactory) GetGitLabClient

func (f *UtilityFactory) GetGitLabClient() (bbGitLab.Client, error)

GetGitLabClient initializes and returns a new GitLab API client

func (*UtilityFactory) GetHelmClient

func (f *UtilityFactory) GetHelmClient(cmd *cobra.Command, namespace string) (helm.Client, error)

GetHelmClient initializes and returns a new Helm client that can perform operations in the given namespace

Returns a nil client and an error if there are any issues with the intialization

Errors when there are issues with the bbctl configurations

func (*UtilityFactory) GetIOStream

func (f *UtilityFactory) GetIOStream() *genericIOOptions.IOStreams

GetIOStream initializes and returns a new IOStreams object used to interact with console input, output, and error output

func (*UtilityFactory) GetIstioClientSet

func (f *UtilityFactory) GetIstioClientSet(cfg *rest.Config) (bbUtilApiWrappers.IstioClientset, error)

GetIstioClientSet initializes and returns a new istio client set by calling versioned.NewForConfig() with the provided REST config settings

Returns a nil client and an error if there are any issues with the intialization

func (*UtilityFactory) GetK8sClientset

func (f *UtilityFactory) GetK8sClientset(cmd *cobra.Command) (kubernetes.Interface, error)

GetK8sClientset initializes and returns a new k8s client by calling the kubernetes.NewForConfig() function with the REST configuration defined in the bbctl config layered together with any existing KUBECONFIG settings and k8s config CLI parameters

Returns a nil client and an error if there are any issues with the intialization

Errors when there are issues with the bbctl configurations

func (*UtilityFactory) GetK8sDynamicClient

func (f *UtilityFactory) GetK8sDynamicClient(cmd *cobra.Command) (dynamic.Interface, error)

GetK8sDynamicClient initializes and returns a new dynamic k8s client by calling the dynamic.NewForConfig() function with the configuration defined in the bbctl config layered together with any existing KUBECONFIG settings and k8s config CLI parameters

Returns a nil client and an error if there are any issues with the intialization

Errors when there are issues with the bbctl configurations

func (*UtilityFactory) GetLoggingClient

func (f *UtilityFactory) GetLoggingClient() bbLog.Client

GetLoggingClient initializes and returns a new logging client using the default slog logger implementation

Errors when there are issues initializing the logger

func (*UtilityFactory) GetLoggingClientWithLogger

func (f *UtilityFactory) GetLoggingClientWithLogger(logger *slog.Logger) bbLog.Client

GetLoggingClientWithLogger initializes and returns a new logging client using the given logger implementation

Errors when there are issues initializing the logger

func (*UtilityFactory) GetOutputClient

func (f *UtilityFactory) GetOutputClient(cmd *cobra.Command, streams genericiooptions.IOStreams) bbOutput.Client

GetOutputClient initializes and returns an output client based on the specified format flag and I/O streams. It retrieves the "format" flag from the provided command, initializes an output client getter, and obtains the appropriate output client using the specified format and streams. Default format is "text"

Errors when issues occur using the clients Output method.

func (*UtilityFactory) GetRestConfig

func (f *UtilityFactory) GetRestConfig(cmd *cobra.Command) (*rest.Config, error)

GetRestConfig returns the k8s REST configuration defined in the bbctl config layered together with any existing KUBECONFIG settings and k8s config CLI parameters

Returns a nil client and an error if there are any issues with the intialization

func (*UtilityFactory) GetRuntimeClient

func (f *UtilityFactory) GetRuntimeClient(scheme *runtime.Scheme) (runtimeClient.Client, error)

GetRuntimeClient initializes and returns a new k8s runtime client by calling the client.New() function

Returns a nil client and an error if there are any issues with the intialization

Errors when there are issues creating the k8s REST config

func (*UtilityFactory) GetViper

func (f *UtilityFactory) GetViper() *viper.Viper

GetViper returns the viper instance

func (*UtilityFactory) ReadCredentialsFile

func (f *UtilityFactory) ReadCredentialsFile(component string, uri string) (string, error)

ReadCredentialsFile reads the credentials file for the requested uri and attempts to return the string value for the requested component Multiple credentials can be present in the file and are identified by their `uri` field

Credentials file path is pulled from the bbctl config and will default to ~/.bbctl/credentials.yaml when not set

Valid component values are `username` and `password`, any other value will return an error

Errors when the credentials file cannot be accessed or parsed, component value is invalid, and when uri is not found in credentials list

Directories

Path Synopsis
Package output provides utilities for outputting data in different formats such as JSON, YAML, and text.
Package output provides utilities for outputting data in different formats such as JSON, YAML, and text.
aws
log

Jump to

Keyboard shortcuts

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