config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentProfile

func CurrentProfile() string

func GetString

func GetString(k *koanf.Koanf, key, env string, flag *pflag.Flag) string

func LoadFromFile

func LoadFromFile(defaultFile, customFile string) (string, error)

func ProfileList

func ProfileList() []string

func ReadUserInput

func ReadUserInput(prompt, key, profile string, validate ...Validator)

func RegisterAuthMethod

func RegisterAuthMethod(name string, method AuthMethod)

func SetProfileCommand

func SetProfileCommand(defaultConfig string) *cobra.Command

func SetupConfigFlags

func SetupConfigFlags(command *cobra.Command)

func SetupEndpointFlags

func SetupEndpointFlags(command *cobra.Command, service string, init func(cmd *cobra.Command, cfg EndpointConfig))

func SupportedAuthMethods

func SupportedAuthMethods() []string

func SwitchProfile

func SwitchProfile(profile string) error

func WriteToFile

func WriteToFile(customFile string) error

Types

type AuthMethod

type AuthMethod func(*cobra.Command, *koanf.Koanf, string) EndpointAuth

type AuthMethodFlag

type AuthMethodFlag string

func (*AuthMethodFlag) Set

func (e *AuthMethodFlag) Set(v string) error

func (*AuthMethodFlag) String

func (e *AuthMethodFlag) String() string

func (*AuthMethodFlag) Type

func (e *AuthMethodFlag) Type() string

type EndpointAuth

type EndpointAuth interface {
	TlsCertificates() []tls.Certificate
}

type EndpointConfig

type EndpointConfig struct {
	Endpoint string
	CaFile   string
	Auth     EndpointAuth
}

func LoadEndpointConfig

func LoadEndpointConfig(command *cobra.Command, service, configFile string) EndpointConfig

func (EndpointConfig) TlsConfig

func (epCfg EndpointConfig) TlsConfig(serverName string) *tls.Config

type Validator

type Validator func(string) error
var (
	ValidateURL Validator = func(s string) error {
		u, err := url.Parse(s)
		if err != nil {
			return err
		}
		if _, err = net.ResolveIPAddr("ip", u.Hostname()); err != nil {
			return err
		}
		return nil
	}
	ValidateFileExists Validator = func(s string) error {
		inf, err := os.Stat(s)
		if err != nil {
			return err
		}
		if inf.IsDir() {
			return errors.New("Must be a file but is a directory")
		}
		return nil
	}
	ValidateTCPAddr Validator = func(s string) error {
		_, err := net.ResolveTCPAddr("tcp", s)
		return err
	}
)

func (Validator) AllowEmpty

func (v Validator) AllowEmpty() Validator

Jump to

Keyboard shortcuts

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