From 279515730105c4e7104621231ff52acff7059956 Mon Sep 17 00:00:00 2001 From: mcorbin Date: Sat, 4 Dec 2021 19:15:30 +0100 Subject: [PATCH] wip --- client/config.go | 42 ++++++++++++++++++++++++++++++++++++++++++ client/root.go | 22 ++++++++++++++++++++++ cmd/config.go | 27 +++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 client/config.go create mode 100644 client/root.go create mode 100644 cmd/config.go diff --git a/client/config.go b/client/config.go new file mode 100644 index 00000000..d8640907 --- /dev/null +++ b/client/config.go @@ -0,0 +1,42 @@ +package client + +import ( + "github.com/pkg/errors" + + "github.com/mcorbin/cabourotte/healthcheck" + "github.com/mcorbin/cabourotte/http" +) + +// Configuration of a Cabourotte client +type Configuration struct { + Host string + Port uint32 + Path string + Protocol healthcheck.Protocol + Key string + Cert string + Cacert string + BasicAuth http.BasicAuth `yaml:"basic-auth" json:"basic-auth"` + Insecure bool +} + +// UnmarshalYAML parses the configuration. +func (c *Configuration) UnmarshalYAML(unmarshal func(interface{}) error) error { + type rawConfiguration Configuration + raw := rawConfiguration{} + if err := unmarshal(&raw); err != nil { + return errors.Wrap(err, "Unable to read HTTP exporter configuration") + } + if raw.Host == "" { + return errors.New("Invalid host for the HTTP exporter configuration") + } + if raw.Port == 0 { + return errors.New("Invalid port for the HTTP server") + } + if !((raw.Key != "" && raw.Cert != "") || + (raw.Key == "" && raw.Cert == "")) { + return errors.New("Invalid certificates") + } + *c = Configuration(raw) + return nil +} diff --git a/client/root.go b/client/root.go new file mode 100644 index 00000000..5291701f --- /dev/null +++ b/client/root.go @@ -0,0 +1,22 @@ +package client + +// Client a Cabourotte client +type Client struct { + Config *Configuration +} + +// New creates a new client +func New(config *Configuration) Client { + client := Client{ + Config: config, + } + return client +} + +func (c *Client) request() { + +} + +func (c *Client) List() { + +} diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 00000000..0077f250 --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/pkg/errors" + + "github.com/mcorbin/cabourotte/healthcheck" + "github.com/mcorbin/cabourotte/http" +) + +// Instance configuration of a Cabourotte instance +type Instance struct { + Host string + Port uint32 + Path string + Protocol healthcheck.Protocol + Key string + Cert string + Cacert string + BasicAuth http.BasicAuth `yaml:"basic-auth" json:"basic-auth"` + Insecure bool +} + +// MainConfiguration The CLI configuration +type MainConfiguration struct { + defaultInstance string `yaml:"default-instance" json:"default-instance"` + Instances map[string]Instance +}