utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 31 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) bool

AskForConfirmation ask for confirmation form os.Stdin.

func AskForSelectItem

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

AskForSelectItem ask for select item from the given map key.

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(path, file string) error

EnsureFileExist ensures file exist.

func EnsureFolderExist

func EnsureFolderExist(path string) error

EnsureFolderExist ensures folder exist.

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 GetSSHConfig

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

GetSSHConfig generate ssh config.

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

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

WaitFor holds parameters applied to a Backoff function.

Types

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