Skip to content

Commit

Permalink
leverage sync.Once
Browse files Browse the repository at this point in the history
  • Loading branch information
pschultz committed Jun 29, 2017
1 parent 7fec346 commit 49767dd
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cert/vault_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type VaultSource struct {
// This value is advisory and the Vault server may ignore or silently
// change it.
renewTTL int

once sync.Once
}
}

Expand All @@ -69,19 +71,13 @@ func (s *VaultSource) client() (*api.Client, error) {

func (s *VaultSource) setAuth(c *api.Client) error {
s.mu.Lock()

firstCall := true

defer func() {
c.SetToken(s.auth.token)
if firstCall {
s.checkRenewal(c)
}
s.auth.once.Do(func() { s.checkRenewal(c) })
s.mu.Unlock()
}()

if s.auth.token != "" {
firstCall = false
return nil
}

Expand Down

0 comments on commit 49767dd

Please sign in to comment.