config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

package config provides structs for holding, parsing, writing, and working with local configuration data for the command line tool.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCluster   = errors.New(MissingConfigCause, "Missing cluster configuration; please set via 'cape config clusters use'")
	ErrMissingHome = errors.New(InvalidEnvCause, "The $HOME environment variable could not be found")
	ErrUserInfo    = errors.New(InvalidEnvCause, "Unable to retrieve info about current user")
)
View Source
var (
	InvalidVersionCause     = errors.NewCause(errors.BadRequestCategory, "invalid_version")
	MissingConfigCause      = errors.NewCause(errors.BadRequestCategory, "missing_config")
	InvalidConfigCause      = errors.NewCause(errors.BadRequestCategory, "invalid_config")
	InvalidEnvCause         = errors.NewCause(errors.BadRequestCategory, "invalid_environment")
	InvalidPermissionsCause = errors.NewCause(errors.BadRequestCategory, "invalid_file_permissions")
	ExistingClusterCause    = errors.NewCause(errors.BadRequestCategory, "cluster_exists")
	ClusterNotFoundCause    = errors.NewCause(errors.NotFoundCategory, "cluster_not_found")
)

Functions

func FolderPath

func FolderPath() (string, error)

FolderPath returns the path to the local folder that holds user-space wide cape configuration

TODO: Add support for XDG_CONFIG standard which can be found at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

func Path

func Path() (string, error)

Path returns the path to local configuration yaml file.

Types

type Cluster

type Cluster struct {
	AuthToken string       `json:"auth_token,omitempty"`
	URL       *models.URL  `json:"url"`
	Label     models.Label `json:"label"`
	CertFile  string       `json:"tls_cert,omitempty"`
	Insecure  bool         `json:"insecure,omitempty"`
}

Cluster represents configuration for a Cape cluster

func (*Cluster) GetURL

func (c *Cluster) GetURL() (*models.URL, error)

GetURL parses the url and returns it

func (*Cluster) SetToken

func (c *Cluster) SetToken(token *base64.Value)

SetToken sets the token on the cluster

func (*Cluster) String

func (c *Cluster) String() string

String completes the Stringer interface

func (*Cluster) Token

func (c *Cluster) Token() (*base64.Value, error)

Token parses the auth token and returns the base64 value

func (*Cluster) Transport

func (c *Cluster) Transport() (coordinator.ClientTransport, error)

Transport returns a configured coordinator transport for this cluster. This can be used with a client

func (*Cluster) Validate

func (c *Cluster) Validate() error

Validate returns an error if the cluster configuration is invalid

type Config

type Config struct {
	Version  int        `json:"version"`
	Context  *Context   `json:"context,omitempty"`
	Clusters []*Cluster `json:"clusters,omitempty"`
	UI       *UI        `json:"ui"`
}

Config represents the configuration settings for the command line

func Default

func Default() *Config

Default returns a Config struct with the default values set

func Parse

func Parse() (*Config, error)

Parse reads the given file path and returns a Config object or returns an error as to why the config could not have been read

func (*Config) AddCluster

func (c *Config) AddCluster(label models.Label, url *models.URL, authToken string) (*Cluster, error)

AddCluster attempts to add the cluster to the configuration

func (*Config) Cluster

func (c *Config) Cluster() (*Cluster, error)

Cluster returns the current cluster, if no cluster is set, cluster will be n

func (*Config) GetCluster

func (c *Config) GetCluster(clusterStr string) (*Cluster, error)

GetCluster returns the cluster by its label

func (*Config) HasCluster

func (c *Config) HasCluster(clusterLabel models.Label) bool

HasCluster returns true if the provided label exists, false otherwise

func (*Config) Print

func (c *Config) Print(w io.Writer) error

Print writes the configuration out the given stream

func (*Config) RemoveCluster

func (c *Config) RemoveCluster(label models.Label) error

RemoveCluster attempts to remove the cluster from configuration

func (*Config) Use

func (c *Config) Use(label models.Label) error

Use sets the given label as the current cluster or to unset the current cluster by passing an empty label

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the config is invalid

func (*Config) Write

func (c *Config) Write() error

Write writes the configuration file out to the globally configured and derived location.

type Context

type Context struct {
	Cluster models.Label `json:"cluster,omitempty"`
}

Context represents the context section of the command line config

func (*Context) Validate

func (c *Context) Validate() error

Validate returns an error if the context is invalid

type Session

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

Session stores CLI "session" data that overrides data in the config. For example, when a command has the flag --cluster it overrides the value in the config.

func NewSession

func NewSession(config *Config, cluster *Cluster) *Session

NewSession returns a new session

func (*Session) Cluster

func (s *Session) Cluster() (*Cluster, error)

Cluster returns the cluster stored on session if exists or the config cluster if it doesn't exist.

type UI

type UI struct {
	Colors     bool `json:"colors"`
	Animations bool `json:"animations"`
}

UI represents the configuration settings for how data is displayed

Jump to

Keyboard shortcuts

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