Fix setting empty OTP secret; minor refactors

This commit is contained in:
Mitchell Simon 2019-09-07 01:44:43 -04:00
parent 2096d6ada8
commit e136b40b70
6 changed files with 33 additions and 30 deletions

View file

@ -6,7 +6,6 @@ import (
"encoding/gob"
"fmt"
"os"
"sync"
"go.etcd.io/bbolt"
@ -38,24 +37,19 @@ func (db BoltDB) GetAllMetadata(ctx context.Context, sourceHost string, errch ch
return nil
}
var wg sync.WaitGroup
c := bkt.hostPrimaryIndex.Cursor()
if sourceHost == "" {
for key, value := c.First(); key != nil; key, value = c.Next() {
wg.Add(1)
unmarshalAndSendCred(value, mdch, errch, &wg)
unmarshalAndSendCred(value, mdch, errch)
}
} else {
hostBytes := []byte(sourceHost)
for key, value := c.Seek(hostBytes); bytes.HasPrefix(key, hostBytes); key, value = c.Next() {
wg.Add(1)
unmarshalAndSendCred(value, mdch, errch, &wg)
unmarshalAndSendCred(value, mdch, errch)
}
}
wg.Wait()
return nil
})
if err != nil {
@ -67,9 +61,7 @@ func (db BoltDB) GetAllMetadata(ctx context.Context, sourceHost string, errch ch
return mdch
}
func unmarshalAndSendCred(value []byte, mdch chan<- types.Metadata, errch chan<- error, wg *sync.WaitGroup) {
defer wg.Done()
func unmarshalAndSendCred(value []byte, mdch chan<- types.Metadata, errch chan<- error) {
var cred types.Credential
err := gobUnmarshal(value, &cred)