utils

package
v0.9.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const BashCompEnvVarFlag = "cobra_annotation_bash_env_var_flag"

BashCompEnvVarFlag cobra flag's annotation used for bind env to flag.

Variables

View Source
var (
	ErrKeyGeneration     = errors.New("unable to generate key")
	ErrValidation        = errors.New("unable to validate key")
	ErrPublicKey         = errors.New("unable to convert public key")
	ErrUnableToWriteFile = errors.New("unable to write file")
)

This file Borrowed from https://github.com/docker/machine/blob/master/libmachine/ssh/keys.go.

Functions

func AskForConfirmation

func AskForConfirmation(s string, def bool) (rtn bool)

AskForConfirmation ask for confirmation form os.Stdin.

func AskForConfirmationWithError added in v0.7.0

func AskForConfirmationWithError(s string, def bool) (rtn bool, err error)

func AskForSelectItem

func AskForSelectItem(s string, ss map[string]string) string

AskForSelectItem ask for select item from the given map key.

func CommandExitWithoutHelpInfo added in v0.7.0

func CommandExitWithoutHelpInfo(f func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string)

func ConvertFlags added in v0.3.0

func ConvertFlags(cmd *cobra.Command, fs []types.Flag) *pflag.FlagSet

ConvertFlags change autok3s flags to FlagSet, will mark required annotation if possible.

func ConvertToFields added in v0.4.0

func ConvertToFields(obj interface{}) (map[string]schemas.Field, error)

ConvertToFields convert interface to schemas' field.

func EnsureFileExist

func EnsureFileExist(file string) error

EnsureFileExist ensures file exist.

func EnsureFolderExist

func EnsureFolderExist(path string) error

EnsureFolderExist ensures folder exist.

func GenerateRand added in v0.5.1

func GenerateRand() int

func GenerateSSHKey added in v0.3.0

func GenerateSSHKey(path string) error

GenerateSSHKey generates SSH keypair based on path of the private key The public key would be generated to the same path with ".pub" added.

func GetFileContent added in v0.7.0

func GetFileContent(path string) ([]byte, error)

func GetSSHConfig

func GetSSHConfig(username, sshPrivateKeyString, passphrase, sshCert string, password string, timeout time.Duration, useAgentAuth bool) (*ssh.ClientConfig, error)

GetSSHConfig generate ssh config.

func IsFileExists added in v0.7.0

func IsFileExists(file string) bool

func IsTerm added in v0.6.0

func IsTerm() bool

func MergeConfig added in v0.4.0

func MergeConfig(source, target reflect.Value)

MergeConfig merge config.

func RandomToken

func RandomToken(size int) (string, error)

RandomToken generate random token.

func RegistryToString added in v0.8.0

func RegistryToString(registry *registries.Registry) (string, error)

func RemoveSSHKey added in v0.4.1

func RemoveSSHKey(path string) error

RemoveSSHKey delete SSH keypair based on path.

func SSHCertificatePath

func SSHCertificatePath(sshCertPath string) (string, error)

SSHCertificatePath returns ssh certificate key content from given path

func SSHPrivateKeyPath

func SSHPrivateKeyPath(sshKey string) (string, error)

SSHPrivateKeyPath returns ssh private key content from given path.

func StringSupportBase64 added in v0.5.0

func StringSupportBase64(value string) string

func StripUserHome added in v0.7.0

func StripUserHome(path string) string

func UniqueArray

func UniqueArray(origin []string) (unique []string)

UniqueArray returns unique array.

func UserHome

func UserHome() string

UserHome returns user's home dir.

func ValidateRequiredFlags added in v0.4.0

func ValidateRequiredFlags(flags *pflag.FlagSet)

ValidateRequiredFlags set `flag.Change` if the required flag has default value but not changed by flags.Set to pass the required check https://github.com/spf13/cobra/blob/v1.1.1/command.go#L1001

func VerifyRegistryFileContent added in v0.8.0

func VerifyRegistryFileContent(path, content string) (*registries.Registry, error)

func WaitFor added in v0.3.0

func WaitFor(fn func() (bool, error)) error

WaitFor holds parameters applied to a Backoff function.

Types

type FirstErrGroup added in v0.6.0

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

func NewFirstErrorGroup added in v0.6.0

func NewFirstErrorGroup() *FirstErrGroup

func (*FirstErrGroup) FirstError added in v0.6.0

func (g *FirstErrGroup) FirstError() <-chan error

func (*FirstErrGroup) Go added in v0.6.0

func (g *FirstErrGroup) Go(f func() error)

func (*FirstErrGroup) Wait added in v0.6.0

func (g *FirstErrGroup) Wait() int32

type KeyPair added in v0.3.0

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
}

KeyPair struct for private/public key.

func NewKeyPair added in v0.3.0

func NewKeyPair() (keyPair *KeyPair, err error)

NewKeyPair generates a new SSH keypair This will return a private & public key encoded as DER.

func (*KeyPair) Fingerprint added in v0.3.0

func (kp *KeyPair) Fingerprint() string

Fingerprint calculates the fingerprint of the public key.

func (*KeyPair) WriteToFile added in v0.3.0

func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error

WriteToFile writes keypair to files.

Jump to

Keyboard shortcuts

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