config.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package discov
  2. import "errors"
  3. var (
  4. // errEmptyEtcdHosts indicates that etcd hosts are empty.
  5. errEmptyEtcdHosts = errors.New("empty etcd hosts")
  6. // errEmptyEtcdKey indicates that etcd key is empty.
  7. errEmptyEtcdKey = errors.New("empty etcd key")
  8. )
  9. // EtcdConf is the config item with the given key on etcd.
  10. type EtcdConf struct {
  11. Hosts []string
  12. Key string
  13. User string `json:",optional"`
  14. Pass string `json:",optional"`
  15. CertFile string `json:",optional"`
  16. CertKeyFile string `json:",optional=CertFile"`
  17. CACertFile string `json:",optional=CertFile"`
  18. InsecureSkipVerify bool `json:",optional"`
  19. }
  20. // HasAccount returns if account provided.
  21. func (c EtcdConf) HasAccount() bool {
  22. return len(c.User) > 0 && len(c.Pass) > 0
  23. }
  24. // HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided.
  25. func (c EtcdConf) HasTLS() bool {
  26. return len(c.CertFile) > 0 && len(c.CertKeyFile) > 0 && len(c.CACertFile) > 0
  27. }
  28. // Validate validates c.
  29. func (c EtcdConf) Validate() error {
  30. if len(c.Hosts) == 0 {
  31. return errEmptyEtcdHosts
  32. } else if len(c.Key) == 0 {
  33. return errEmptyEtcdKey
  34. } else {
  35. return nil
  36. }
  37. }