accountmanager.go 688 B

12345678910111213141516171819202122232425262728293031323334
  1. package internal
  2. import "sync"
  3. var (
  4. accounts = make(map[string]Account)
  5. lock sync.RWMutex
  6. )
  7. // Account holds the username/password for an etcd cluster.
  8. type Account struct {
  9. User string
  10. Pass string
  11. }
  12. // AddAccount adds the username/password for the given etcd cluster.
  13. func AddAccount(endpoints []string, user, pass string) {
  14. lock.Lock()
  15. defer lock.Unlock()
  16. accounts[getClusterKey(endpoints)] = Account{
  17. User: user,
  18. Pass: pass,
  19. }
  20. }
  21. // GetAccount gets the username/password for the given etcd cluster.
  22. func GetAccount(endpoints []string) (Account, bool) {
  23. lock.RLock()
  24. defer lock.RUnlock()
  25. account, ok := accounts[getClusterKey(endpoints)]
  26. return account, ok
  27. }