Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative expiration times #2125

Closed
technoweenie opened this issue Apr 4, 2017 · 3 comments
Closed

Relative expiration times #2125

technoweenie opened this issue Apr 4, 2017 · 3 comments
Labels
Milestone

Comments

@technoweenie
Copy link
Contributor

The Batch API and git-lfs-authenticate ssh call both can optionally return an expires_at marking when an authentication token expires. The client uses this hint to know if it should attempt the request, or get a fresh token. However, this causes problems for users with incorrect times.

Proposal: Introduce expires_in, which returns the number of seconds the token is valid. This should take precedence over an existing expires_at property.

@technoweenie technoweenie added this to the v2.1.0 milestone Apr 4, 2017
@ttaylorr
Copy link
Contributor

ttaylorr commented Apr 4, 2017

I think this is a great call, I'm definitely for adding this to the API. I've been wondering this morning about how we should implement this in the client. I have a few thoughts:

  1. Expand both APIs to include the following type signature:
type T struct {
        // ...
        ExpiresAt time.Time
        ExpiresIn time.Duration
}

func (t *T) IsExpiredWithin(d time.Duration) bool { ... }

Which would definitely work, I'm just not sure I like exposing both ExpiresAt and ExpiresIn as public fields. That could be good, but I'm not sure where a caller would need to care.

  1. Another thought is that we could have a new function:
package tools

func ParseExpiresAtOrIn(r io.Reader) (time.Duration, error) { ... }

Which would work and simplifies the signature of both API types, but also introduces a new function and an additional parse step.

At a broader scope, I like this change because we don't have to break existing APIs, and we can deprecate the expires_at property at a later, major version bump of the API.

@technoweenie
Copy link
Contributor Author

ParseExpiresAtOrIn(r io.Reader): What is io.Reader in this scenario? I'm totally fine with adding both a new public property to a json-decoded struct, since it will be a public property of the API.

@ttaylorr
Copy link
Contributor

ttaylorr commented Apr 4, 2017

ParseExpiresAtOrIn(r io.Reader): What is io.Reader in this scenario?

I think in this case it'd be a reader that dispenses JSON, so that we could feed it to encoding/json.NewDecoder().

Either way, I'm fine with just adding a new property to each API's type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants