Skip to content

Commit

Permalink
cmd/cue: store token expiry timestamps in UTC in logins.json
Browse files Browse the repository at this point in the history
That is, rather than a local-timezone timestamp such as

    "expiry": "2024-10-01T12:25:11.136734393+02:00"

it is more consistent and straightforward to use UTC:

    "expiry": "2024-10-01T10:25:26.177186044Z"

There should be zero change in the token refresh logic either way,
but this will be easier for humans to grasp and debug.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I673482b6c667eb4bea2f2d6c426ba077142e008a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202036
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Oct 1, 2024
1 parent 25e0884 commit 6b73188
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/cue/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ inside $CUE_CONFIG_DIR; see 'cue help environment'.
return fmt.Errorf("cannot obtain the OAuth2 token: %v", err)
}

// For consistency, store timestamps in UTC.
tok.Expiry = tok.Expiry.UTC()

_, err = cueconfig.UpdateRegistryLogin(loginsPath, host.Name, tok)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cue/cmd/testdata/script/login_immediate.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ grep -count=1 '"access_token"' cueconfig/logins.json
# Ensure the contents of the token look correct.
grep -count=1 '"access_token": "secret-access-token"' cueconfig/logins.json
grep -count=1 '"token_type": "Bearer"' cueconfig/logins.json
# TODO(mvdan): store expiry timestamps in UTC for consistency.
grep '"expiry": "20..-..-..T' cueconfig/logins.json
# Timestamps are always stored in UTC.
grep '"expiry": "20..-..-..T.*Z"' cueconfig/logins.json
# oauthregistry does not give a refresh token, and we use encoding/json's omitempty.
! grep '"refresh_token"' cueconfig/logins.json

0 comments on commit 6b73188

Please sign in to comment.