Skip to content

Commit

Permalink
[wip] prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Jun 14, 2024
1 parent d9a10a6 commit a85d39d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions client/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
package consul

import (
"context"
"fmt"
"time"

consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"

"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/useragent"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
Expand Down Expand Up @@ -125,6 +128,35 @@ func (c *consulClient) DeriveTokenWithJWT(req JWTLoginRequest) (*consulapi.ACLTo
Partition: c.partition,
})

timer, timerStop := helper.NewStoppedTimer()
defer timerStop()

var retry uint64
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

for {
_, _, err := c.client.ACL().TokenReadSelf(&consulapi.QueryOptions{
Namespace: t.Namespace,
Partition: c.partition,
AllowStale: true,
Token: t.SecretID,
})
if err == nil {
break
}

c.logger.Trace("waiting for Consul stale query on token")
retry++
timer.Reset(helper.Backoff(time.Second, time.Second*10, retry))
select {
case <-ctx.Done():
break
case <-timer.C:
continue
}
}

return t, err
}

Expand Down

0 comments on commit a85d39d

Please sign in to comment.