2020-07-26 17:09:05 +08:00
|
|
|
package discov
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
2022-02-09 14:40:05 +08:00
|
|
|
var (
|
|
|
|
// errEmptyEtcdHosts indicates that etcd hosts are empty.
|
|
|
|
errEmptyEtcdHosts = errors.New("empty etcd hosts")
|
|
|
|
// errEmptyEtcdKey indicates that etcd key is empty.
|
|
|
|
errEmptyEtcdKey = errors.New("empty etcd key")
|
|
|
|
)
|
|
|
|
|
2021-02-18 22:56:35 +08:00
|
|
|
// EtcdConf is the config item with the given key on etcd.
|
2020-07-26 17:09:05 +08:00
|
|
|
type EtcdConf struct {
|
2022-01-02 20:23:50 +08:00
|
|
|
Hosts []string
|
|
|
|
Key string
|
|
|
|
User string `json:",optional"`
|
|
|
|
Pass string `json:",optional"`
|
|
|
|
CertFile string `json:",optional"`
|
|
|
|
CertKeyFile string `json:",optional=CertFile"`
|
|
|
|
CACertFile string `json:",optional=CertFile"`
|
|
|
|
InsecureSkipVerify bool `json:",optional"`
|
2021-10-31 09:05:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// HasAccount returns if account provided.
|
|
|
|
func (c EtcdConf) HasAccount() bool {
|
|
|
|
return len(c.User) > 0 && len(c.Pass) > 0
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
2022-01-02 20:23:50 +08:00
|
|
|
// HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided.
|
|
|
|
func (c EtcdConf) HasTLS() bool {
|
|
|
|
return len(c.CertFile) > 0 && len(c.CertKeyFile) > 0 && len(c.CACertFile) > 0
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:56:35 +08:00
|
|
|
// Validate validates c.
|
2020-07-26 17:09:05 +08:00
|
|
|
func (c EtcdConf) Validate() error {
|
|
|
|
if len(c.Hosts) == 0 {
|
2022-02-09 14:40:05 +08:00
|
|
|
return errEmptyEtcdHosts
|
2020-07-26 17:09:05 +08:00
|
|
|
} else if len(c.Key) == 0 {
|
2022-02-09 14:40:05 +08:00
|
|
|
return errEmptyEtcdKey
|
2020-07-26 17:09:05 +08:00
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|