escfg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default configuration file name
	DefaultElasticConfigName string = "config"
	// Default configuration file path
	DefaultElasticFolderPath string = "$HOME/.elastic"
	// Default full path to configuration file
	DefaultElasticConfig string = "$HOME/.elastic/config"
	// Default configuration folder mode
	DefaultElasticFolderMode uint32 = 755
	// Default configuration file mode
	DefaultElasticConfigMode uint32 = 0600
)

Variables

View Source
var DefaultConfig = Config{
	Clusters: []Cluster{
		Cluster{
			Name: "local",
			ElasticAddresses: []string{
				"http://localhost:9200",
				"http://127.0.0.1:9200",
			},
			AllowSelfSigned: "yes",
		},
	},
	Contexts: []Contexts{
		Contexts{
			Name: "local",
			Context: Context{
				Cluster: "local",
				User:    "elastic",
			},
		},
		Contexts{
			Name: "elastic@local",
			Context: Context{
				Cluster: "local",
				User:    "elastic@local",
			},
		},
	},
	Users: []Users{
		Users{
			Name: "elastic@local",
			User: User{
				Name:     "elastic",
				Password: "",
				ApiKey:   "",
				Token: Token{
					Value:      "",
					Expiration: "",
				},
			},
		},
		Users{
			Name: "elastic",
			User: User{
				Name:     "elastic",
				Password: "changeme",
				ApiKey:   "",
				Token: Token{
					Value:      "",
					Expiration: "",
				},
			},
		},
	},
	CurrentContext: "local",
}

Default Config struct used in GenDefaultConfig. Connects to a local elasticsearch cluster

Functions

func ConfigContextGen added in v0.1.4

func ConfigContextGen(cfgOpts *opts.ConfigOptions, cmdOpts *opts.CommandOptions, credOpts *opts.CredentialOptions) error

func ConfigContextGetCurrent added in v0.1.4

func ConfigContextGetCurrent(cfgOpts *opts.ConfigOptions) error

func ConfigContextList added in v0.1.4

func ConfigContextList(cfgOpts *opts.ConfigOptions) error

func ConfigContextShow added in v0.1.4

func ConfigContextShow(cfgOpts *opts.ConfigOptions, cmdOpts *opts.CommandOptions) error

func ConfigContextTest added in v0.1.4

func ConfigContextTest(cfgOpts *opts.ConfigOptions, cmdOpts *opts.CommandOptions) error

func ConfigContextUse added in v0.1.4

func ConfigContextUse(cfgOpts *opts.ConfigOptions, cmdOpts *opts.CommandOptions) error

Change the value of Config.CurrentContext

func ConfigGenDefaultConfig added in v0.1.4

func ConfigGenDefaultConfig(cfgOpts *opts.ConfigOptions) (err error)

Generate a configuration file for connecting to a local elasticsearch cluster if a file is not found by path

func ConfigShow added in v0.1.4

func ConfigShow(cfgOpts *opts.ConfigOptions) error

Marshal a Config into bytes

func ConfigTest added in v0.1.4

func ConfigTest(cfgOpts *opts.ConfigOptions) error

func GenClient added in v0.1.4

func GenClient(c *opts.ConfigOptions) (client *elastic7.Client, err error)

func GenESConfig

func GenESConfig(cfg Config, ctx string, debug bool) (es7cfg elastic7.Config, err error)

func ToBytes

func ToBytes(file string) (b []byte, err error)

Read a file into bytes

Types

type Cluster

type Cluster struct {
	Name             string   `yaml:"name"`
	ElasticAddresses []string `yaml:"elastic-addresses,omitempty"`
	//KibanaAddresses  []string `yaml:"kibana-addresses",omitempty`
	CloudID         string `yaml:"cloud-id,omitempty"`
	AllowSelfSigned string `yaml:"allowSelfSigned,omitempty"`
}

Connection details for a cluster

func (Cluster) IsNil

func (c Cluster) IsNil() bool

Check if all fields in the Cluster struct have their nil value. Necessary because arrays nested under structs can't be compared

type Config

type Config struct {
	Clusters       []Cluster  `yaml:"clusters"`
	Contexts       []Contexts `yaml:"contexts"`
	Users          []Users    `yaml:"users"`
	CurrentContext string     `yaml:"current-context,omitempty"`
}

File configuration

func NewConfig added in v0.1.4

func NewConfig(baseContext string, fullContext string, configUsername string, cfgOpts *opts.ConfigOptions, credOpts *opts.CredentialOptions) (Config, error)

func ReadConfig

func ReadConfig(file string) (cfg Config, err error)

Unmarshal bytes into a Config

type ConfigCmd added in v0.0.4

type ConfigCmd struct {
	// A ConfigCmd should at least have a Command
	Command string   `yaml:"command"`
	Env     []string `yaml:"env,omitempty"`
	Args    []string `yaml:"args,omitempty"`
}

func (ConfigCmd) IsEmpty added in v0.0.4

func (c ConfigCmd) IsEmpty() bool

Check if ConfigCmd is empty

type Context

type Context struct {
	Cluster string `yaml:"cluster,omitempty"`
	User    string `yaml:"user,omitempty"`
}

A combination of a named Cluster and named User. Used for lookups of the respective objects

type Contexts

type Contexts struct {
	Name    string  `yaml:"name,omitempty"`
	Context Context `yaml:"context,omitempty"`
}

Named Context

type Token

type Token struct {
	Value      string `yaml:"value,omitempty"`
	Expiration string `yaml:"expiration,omitempty"`
}

Token used for authentication

type User

type User struct {
	Name        string    `yaml:"name,omitempty"`
	NameCmd     ConfigCmd `yaml:"name-cmd,omitempty"`
	Password    string    `yaml:"password,omitempty"`
	PasswordCmd ConfigCmd `yaml:"password-cmd,omitempty"`
	ApiKey      string    `yaml:"api-key,omitempty"`
	Token       Token     `yaml:"token,omitempty"`
}

Authentication credentials

type Users

type Users struct {
	Name string `yaml:"name,omitempty"`
	User User   `yaml:"user,omitempty"`
}

Named User

Jump to

Keyboard shortcuts

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