Skip to content

Commit

Permalink
lastRefresh now before attempt made to avoid races
Browse files Browse the repository at this point in the history
Now we won't accidentally try to refresh an expired token
  • Loading branch information
thomasmitchell committed Oct 15, 2019
1 parent 997a781 commit 3e47c85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions storage/configserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newConfigServerAccessor(conf ConfigServerConfig) (*ConfigServerAccessor, er
return nil, fmt.Errorf("Could not get auth endpoint: %s", err)
}

fmt.Printf("AuthURL: %s\n", authURL)
//fmt.Printf("AuthURL: %s\n", authURL)

uaaClient := uaa.Client{
URL: authURL,
Expand Down Expand Up @@ -179,6 +179,7 @@ func (r *refreshTokenStrategy) RefreshToken() string {
func (r *refreshTokenStrategy) Refresh() error {
var authResp *uaa.AuthResponse
var err error
attemptTime := time.Now()
if r.IsClientCredentials {
fmt.Fprintf(os.Stderr, "Refreshing client credentials auth for Credhub\n")
authResp, err = r.UAAClient.ClientCredentials(r.ClientID, r.ClientSecret)
Expand All @@ -197,7 +198,7 @@ func (r *refreshTokenStrategy) Refresh() error {
}

fmt.Fprintf(os.Stderr, "Credhub token refresh was successful\n")
r.lastSuccessfulRefresh = time.Now()
r.lastSuccessfulRefresh = attemptTime
r.TTL = authResp.TTL

r.SetTokens(authResp.AccessToken, authResp.RefreshToken)
Expand Down
3 changes: 2 additions & 1 deletion storage/opsmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (v *OmAccessor) setTokens(accessToken, refreshToken string) {
func (v *OmAccessor) refresh() error {
var authResp *uaa.AuthResponse
var err error
attemptTime := time.Now()
if v.isClientCredentials {
fmt.Fprintf(os.Stderr, "Refreshing client credentials auth for OpsMan\n")
authResp, err = v.uaaClient.ClientCredentials(v.clientID, v.clientSecret)
Expand All @@ -234,7 +235,7 @@ func (v *OmAccessor) refresh() error {
}

fmt.Fprintf(os.Stderr, "Opsman token refresh was successful\n")
v.lastSuccessfulRefresh = time.Now()
v.lastSuccessfulRefresh = attemptTime
v.tokenTTL = authResp.TTL

v.setTokens(authResp.AccessToken, authResp.RefreshToken)
Expand Down

0 comments on commit 3e47c85

Please sign in to comment.