Documentation ¶
Overview ¶
Package config manages CLI configurations for your DC/OS clusters.
Each configured cluster has an associated TOML configuration file which can be parsed, updated, or displayed through the Config struct.
Index ¶
- Variables
- func Keys() map[string]string
- type Cluster
- func (c *Cluster) ACSToken() string
- func (c *Cluster) Config() *Config
- func (c *Cluster) Dir() string
- func (c *Cluster) ID() string
- func (c *Cluster) Name() string
- func (c *Cluster) SetACSToken(acsToken string)
- func (c *Cluster) SetID(id string)
- func (c *Cluster) SetName(name string)
- func (c *Cluster) SetTLS(tls TLS)
- func (c *Cluster) SetTimeout(timeout time.Duration)
- func (c *Cluster) SetURL(url string)
- func (c *Cluster) TLS() (TLS, error)
- func (c *Cluster) Timeout() time.Duration
- func (c *Cluster) URL() string
- type Config
- func (c *Config) Fs() afero.Fs
- func (c *Config) Get(key string) interface{}
- func (c *Config) Keys() []string
- func (c *Config) LoadPath(path string) error
- func (c *Config) LoadReader(reader io.Reader) error
- func (c *Config) LoadTree(tree *toml.Tree)
- func (c *Config) Path() string
- func (c *Config) Persist() error
- func (c *Config) Set(key string, val interface{}) (err error)
- func (c *Config) SetPath(path string)
- func (c *Config) ToMap() map[string]interface{}
- func (c *Config) Unset(key string)
- type Manager
- type ManagerOpts
- type Opts
- type SSLError
- type TLS
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConfigNotFound = errors.New("no match found")
ErrConfigNotFound means that the manager cannot find a config using a name/id.
var (
ErrNoConfigPath = errors.New("no path specified for the config")
)
Errors related to the Config.
var ErrNotAttached = errors.New("no cluster is attached")
ErrNotAttached indicates that no cluster is attached.
var ErrTooManyConfigs = errors.New("multiple matches found")
ErrTooManyConfigs means that more than one config has been found for a given search.
Functions ¶
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster is a subset representation of a DC/OS CLI configuration.
It is a proxy struct on top of a config which provides user-friendly getters and setters for common configurations such as "core.dcos_url" or "core.ssl_verify". It leverages Go types as much as possible.
func NewCluster ¶
NewCluster returns a new cluster for a given config, if omitted it uses an empty config.
func (*Cluster) ACSToken ¶
ACSToken returns the token generated by authenticating to DC/OS using the Admin Router Access Control Service.
func (*Cluster) SetACSToken ¶
SetACSToken sets the token generated by authenticating to DC/OS using the Admin Router Access Control Service.
func (*Cluster) SetTimeout ¶
SetTimeout sets the HTTP request timeout once the connection is established.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the backend for Config data. It aggregates multiple sources (env vars, TOML document) and is able to get/set/unset key(s) in the TOML document.
func (*Config) LoadPath ¶
LoadPath populates the store based on a path to a TOML file. If the file doesn't exist, an empty one is created.
Example ¶
package main import ( "fmt" "github.com/dcos/dcos-cli/pkg/config" ) func main() { store := config.Empty() err := store.LoadPath("/path/to/config.toml") if err != nil { // Handle error. } // Displays the DC/OS URL if it exists in the file. fmt.Println(store.Get("core.dcos_url")) // Change the cluster name. store.Set("cluster.name", "my-new-cluster-name") }
Output:
func (*Config) LoadReader ¶
LoadReader populates the store based on an io.Reader containing TOML data.
Example ¶
package main import ( "fmt" "strings" "github.com/dcos/dcos-cli/pkg/config" ) func main() { store := config.Empty() err := store.LoadReader(strings.NewReader(` [core] dcos_url = "https://example.com" dcos_acs_token = "token_zj8Tb0vhQw" ssl_verify = "/path/to/dcos_ca.crt" [cluster] name = "my-cluster" `)) if err != nil { // Handle error. } fmt.Println(store.Get("core.dcos_url")) // https://example.com fmt.Println(store.Get("core.dcos_acs_token")) // "token_zj8Tb0vhQw" fmt.Println(store.Get("core.cluster_name")) // "my-cluster" }
Output:
func (*Config) LoadTree ¶
func (c *Config) LoadTree(tree *toml.Tree)
LoadTree populates the store with a TOML tree.
func (*Config) Persist ¶
Persist flushes the in-memory TOML tree representation to the path associated to the Config.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is able to retrieve, create, and delete configs.
func NewManager ¶
func NewManager(opts ManagerOpts) *Manager
NewManager creates a new config manager.
func (*Manager) Attach ¶
Attach sets a given config as the current one. This is done by adding an `attached` file next to it. If another config is already attached, the file gets moved.
func (*Manager) Current ¶
Current retrieves the current config.
The lookup order is : - DCOS_CLUSTER is defined and is the name/ID of a configured cluster. - An attached file exists alongside a configured cluster, OR there is a single configured cluster.
type ManagerOpts ¶
type ManagerOpts struct { // Fs is an abstraction for the filesystem. All filesystem operations // for the manager should be done through it instead of the os package. Fs afero.Fs // EnvLookup is the function used to lookup environment variables. // When not set it defaults to os.LookupEnv. EnvLookup func(key string) (string, bool) // Dir is the root directory for the config manager. Dir string }
ManagerOpts are functional options for a Manager.
type Opts ¶
type Opts struct { // EnvWhitelist is a map of config keys and environment variables. // When present, these env vars take precedence over the values in the toml.Tree. EnvWhitelist map[string]string // EnvLookup is the function used to lookup environment variables. // When not set it defaults to os.LookupEnv. EnvLookup func(key string) (string, bool) // Fs is an abstraction for the filesystem. All filesystem operations // for the store should be done through it instead of the os package. Fs afero.Fs }
Opts are functional options for a Config.
type SSLError ¶
type SSLError struct {
// contains filtered or unexported fields
}
func NewSSLError ¶
type TLS ¶
type TLS struct { // Insecure specifies if server certificates should be accepted without verification. // // Skipping verification against the system's CA bundle or a cluster-specific CA is highly discouraged // and should only be done during testing/development. Insecure bool // Path to the root CA bundle. RootCAsPath string // A pool of root CAs to verify server certificates against. RootCAs *x509.CertPool }
TLS holds the configuration for TLS clients.