Пример #1
0
// UserByName satisfies AccountProvider.
func (m *MockProvider) UserByName(name string) (*accounts.User, error) {
	for _, u := range m.Usrs {
		if name == u.Name {
			return u, m.Err
		}
	}
	return nil, accounts.UsernameNotFound(name)
}
Пример #2
0
// AuthorizedKeys satisfies AccountProvider.
func (s *cachingStore) AuthorizedKeys(username string) ([]string, error) {
	cu, ok := s.userByNameImpl(username)
	if !ok {
		return nil, accounts.UsernameNotFound(username)
	} else if !nowOutsideTimespan(cu.keyRefreshTime, s.config.KeyRefreshCooldown) {
		logger.Infof("Returning cached keys for %v due to cooldown.", username)
		return cu.keys, nil
	}
	view, err := s.apiClient.AuthorizedKeys(username)
	if err != nil {
		return cu.keys, nil
	}
	go s.updateCachedKeys(username, view.Keys, view.Sudoer, timeNow())
	return view.Keys, nil
}
Пример #3
0
// UserByName satisfies AccountProvider.
func (s *cachingStore) UserByName(name string) (*accounts.User, error) {
	cu, ok := s.userByNameImpl(name)
	if ok {
		return cu.user, nil
	}
	ch := make(chan struct{})
	logger.Infof("Triggering refresh due to missing user %v.", name)
	s.updateWaiters <- ch
	// Block on update.
	<-ch
	cu, ok = s.userByNameImpl(name)
	if ok {
		return cu.user, nil
	}
	return nil, accounts.UsernameNotFound(name)
}