clientcmd

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 13 Imported by: 8

Documentation

Overview

Package clientcmd provides one stop shopping for building a working client from a fixed config, from a .iamconfig file, from command line flags, or from any merged combination.

Index

Constants

View Source
const (
	RecommendedConfigPathFlag   = "iamconfig"
	RecommendedConfigPathEnvVar = "IAMCONFIG"
	RecommendedHomeDir          = ".iam"
	RecommendedFileName         = "config"
	RecommendedSchemaName       = "scheme"
)

Defines some useful for const variables.

Variables

View Source
var (
	RecommendedConfigDir  = path.Join(homedir.HomeDir(), RecommendedHomeDir)
	RecommendedHomeFile   = path.Join(RecommendedConfigDir, RecommendedFileName)
	RecommendedSchemaFile = path.Join(RecommendedConfigDir, RecommendedSchemaName)
)

Defines some useful variables.

View Source
var (
	// ErrNoContext defines no context chosen error.
	ErrNoContext = errors.New("no context chosen")

	// ErrEmptyConfig defines no configuration has been provided error.
	ErrEmptyConfig = NewEmptyConfigError(
		"no configuration has been provided, try setting IAM_SERVER_ADDRESS environment variable",
	)

	// ErrEmptyServer defines a no server defined error.
	ErrEmptyServer = errors.New("server has no server defined")
)

Functions

func BuildConfigFromFlags

func BuildConfigFromFlags(serverURL, iamconfigPath string) (*restclient.Config, error)

BuildConfigFromFlags is a helper function that builds configs from a master url or a iamconfig filepath. These are passed in as command line flags for cluster components. Warnings should reflect this usage. If neither masterUrl or iamconfigPath are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback to the default config.

func IsConfigurationInvalid

func IsConfigurationInvalid(err error) bool

IsConfigurationInvalid returns true if the provided error indicates the configuration is invalid.

func IsEmptyConfig

func IsEmptyConfig(err error) bool

IsEmptyConfig returns true if the provided error indicates the provided configuration is empty.

func NewEmptyConfigError

func NewEmptyConfigError(message string) error

NewEmptyConfigError returns an error wrapping the given message which IsEmptyConfig() will recognize as an empty config error.

func ParseTimeout

func ParseTimeout(duration string) (time.Duration, error)

ParseTimeout returns a parsed duration from a string A duration string value must be a positive integer, optionally followed by a corresponding time unit (s|m|h).

func RESTConfigFromIAMConfig

func RESTConfigFromIAMConfig(configBytes []byte) (*restclient.Config, error)

RESTConfigFromIAMConfig is a convenience method to give back a restconfig from your iamconfig bytes. For programmatic access, this is what you want 80% of the time.

Types

type AuthInfo

type AuthInfo struct {
	LocationOfOrigin  string
	ClientCertificate string `yaml:"client-certificate,omitempty"      mapstructure:"client-certificate,omitempty"`
	// ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate
	// +optional
	ClientCertificateData string `yaml:"client-certificate-data,omitempty" mapstructure:"client-certificate-data,omitempty"`
	// ClientKey is the path to a client key file for TLS.
	// +optional
	ClientKey string `yaml:"client-key,omitempty"              mapstructure:"client-key,omitempty"`
	// ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey
	// +optional
	ClientKeyData string `yaml:"client-key-data,omitempty"         mapstructure:"client-key-data,omitempty"`
	// Token is the bearer token for authentication to the iam cluster.
	// +optional
	Token string `yaml:"token,omitempty"                   mapstructure:"token,omitempty"`

	Username string `yaml:"username,omitempty" mapstructure:"username,omitempty"`
	Password string `yaml:"password,omitempty" mapstructure:"password,omitempty"`

	SecretID  string `yaml:"secret-id,omitempty"  mapstructure:"secret-id,omitempty"`
	SecretKey string `yaml:"secret-key,omitempty" mapstructure:"secret-key,omitempty"`
}

AuthInfo contains information that describes identity information. This is use to tell the iam cluster who you are.

type ClientConfig

type ClientConfig interface {
	// ClientConfig returns a complete client config
	ClientConfig() (*restclient.Config, error)
}

ClientConfig is used to make it easy to get an api server client.

func NewClientConfigFromBytes

func NewClientConfigFromBytes(configBytes []byte) (ClientConfig, error)

NewClientConfigFromBytes takes your iamconfig and gives you back a ClientConfig.

func NewClientConfigFromConfig

func NewClientConfigFromConfig(config *Config) ClientConfig

NewClientConfigFromConfig takes your Config and gives you back a ClientConfig.

type Config

type Config struct {
	APIVersion string    `yaml:"apiVersion,omitempty" mapstructure:"apiVersion,omitempty"`
	AuthInfo   *AuthInfo `yaml:"user,omitempty"       mapstructure:"user,omitempty"`
	Server     *Server   `yaml:"server,omitempty"     mapstructure:"server,omitempty"`
}

Config defines a config struct used by marmotedu-sdk-go.

func Load

func Load(data []byte) (*Config, error)

Load takes a byte slice and deserializes the contents into Config object. Encapsulates deserialization without assuming the source is a file.

func LoadFromFile

func LoadFromFile(filename string) (*Config, error)

LoadFromFile load config from file.

func NewConfig

func NewConfig() *Config

NewConfig is a convenience function that returns a new Config object with non-nil maps.

type DirectClientConfig

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

DirectClientConfig wrap for Config.

func (*DirectClientConfig) ClientConfig

func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error)

ClientConfig implements ClientConfig.

func (*DirectClientConfig) ConfirmUsable

func (config *DirectClientConfig) ConfirmUsable() error

ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config, but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.

type Server

type Server struct {
	LocationOfOrigin string
	Timeout          time.Duration `yaml:"timeout,omitempty"                    mapstructure:"timeout,omitempty"`
	MaxRetries       int           `yaml:"max-retries,omitempty"                mapstructure:"max-retries,omitempty"`
	RetryInterval    time.Duration `yaml:"retry-interval,omitempty"             mapstructure:"retry-interval,omitempty"`
	Address          string        `yaml:"address,omitempty"                    mapstructure:"address,omitempty"`
	// TLSServerName is used to check server certificate. If TLSServerName is empty, the hostname used to contact the
	// server is used.
	// +optional
	TLSServerName string `yaml:"tls-server-name,omitempty"            mapstructure:"tls-server-name,omitempty"`
	// InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS
	// connections insecure.
	// +optional
	InsecureSkipTLSVerify bool `yaml:"insecure-skip-tls-verify,omitempty"   mapstructure:"insecure-skip-tls-verify,omitempty"`
	// CertificateAuthority is the path to a cert file for the certificate authority.
	// +optional
	CertificateAuthority string `yaml:"certificate-authority,omitempty"      mapstructure:"certificate-authority,omitempty"`
	// CertificateAuthorityData contains PEM-encoded certificate authority certificates.
	// Overrides CertificateAuthority
	// +optional
	CertificateAuthorityData string `yaml:"certificate-authority-data,omitempty" mapstructure:"certificate-authority-data,omitempty"`
}

Server contains information about how to communicate with a iam api server.

Jump to

Keyboard shortcuts

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