escfg

package
v0.0.0-...-906fdf7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 10 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 DisplayConfig

func DisplayConfig(cfg Config) ([]byte, error)

Marshal a Config into bytes

func GenDefaultConfig

func GenDefaultConfig(file string) (err error)

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

func GenESConfig

func GenESConfig(cfg Config) (es7cfg elastic7.Config, err error)

func GetContexts

func GetContexts(cfg Config) []string

Return a list of contexts

func IsValidCfg

func IsValidCfg(b []byte) bool

Test if a config file is valid by attempting to unmarshal into a Config struct

func TestContext

func TestContext(n string)

Test a named context

func ToBytes

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

Read a file into bytes

func UseContext

func UseContext(n string, cfg Config, file string) error

Change the value of Config.CurrentContext

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 ReadConfig

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

Unmarshal bytes into a Config

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`
	Password string `yaml:"password",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