tq,lfsapi/auth: change expires_in to be a whole number of seconds
This commit is contained in:
parent
5e4016d8fe
commit
b65800a06d
@ -83,8 +83,9 @@ omitted.
|
||||
* `href` - String URL to download the object.
|
||||
* `header` - Optional hash of String HTTP header key/value pairs to apply
|
||||
to the request.
|
||||
* `expires_in` - Nanoseconds after local client time when transfer will
|
||||
expire. Preferred over `expires_at` if both are provided.
|
||||
* `expires_in` - Whole number of seconds after local client time when
|
||||
transfer will expire. Preferred over `expires_at` if both are provided.
|
||||
Maximum of 9223372036, minimum of -9223372036.
|
||||
* `expires_at` - String ISO 8601 formatted timestamp for when the given
|
||||
action expires (usually due to a temporary token).
|
||||
|
||||
|
@ -58,11 +58,11 @@ type sshAuthResponse struct {
|
||||
Href string `json:"href"`
|
||||
Header map[string]string `json:"header"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
ExpiresIn time.Duration `json:"expires_in"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
func (r *sshAuthResponse) IsExpiredWithin(d time.Duration) (time.Time, bool) {
|
||||
return tools.IsExpiredAtOrIn(d, r.ExpiresAt, r.ExpiresIn)
|
||||
return tools.IsExpiredAtOrIn(d, r.ExpiresAt, time.Duration(r.ExpiresIn)*time.Second)
|
||||
}
|
||||
|
||||
type sshAuthClient struct {
|
||||
|
@ -180,7 +180,7 @@ type lfsLink struct {
|
||||
Href string `json:"href"`
|
||||
Header map[string]string `json:"header,omitempty"`
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
ExpiresIn time.Duration `json:"expires_in,omitempty"`
|
||||
ExpiresIn int64 `json:"expires_in,omitempty"`
|
||||
}
|
||||
|
||||
type lfsError struct {
|
||||
@ -484,10 +484,10 @@ func serveExpired(a *lfsLink, repo, handler string) *lfsLink {
|
||||
case "expired-absolute":
|
||||
a.ExpiresAt = at
|
||||
case "expired-relative":
|
||||
a.ExpiresIn = dur
|
||||
a.ExpiresIn = -5
|
||||
case "expired-both":
|
||||
a.ExpiresAt = at
|
||||
a.ExpiresIn = dur
|
||||
a.ExpiresIn = -5
|
||||
}
|
||||
|
||||
return a
|
||||
|
@ -14,7 +14,7 @@ type sshResponse struct {
|
||||
Href string `json:"href"`
|
||||
Header map[string]string `json:"header"`
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
ExpiresIn time.Duration `json:"expires_in,omitempty"`
|
||||
ExpiresIn int64 `json:"expires_in,omitempty"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -40,10 +40,10 @@ func main() {
|
||||
case "ssh-expired-absolute":
|
||||
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
|
||||
case "ssh-expired-relative":
|
||||
r.ExpiresIn = -5 * time.Minute
|
||||
r.ExpiresIn = -5
|
||||
case "ssh-expired-both":
|
||||
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
|
||||
r.ExpiresIn = -5 * time.Minute
|
||||
r.ExpiresIn = -5
|
||||
}
|
||||
|
||||
json.NewEncoder(os.Stdout).Encode(r)
|
||||
|
@ -14,6 +14,11 @@
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"expires_in": {
|
||||
"type": "number",
|
||||
"maximum": 9223372036,
|
||||
"minimum": -9223372036
|
||||
},
|
||||
"expires_at": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -113,11 +113,11 @@ type Action struct {
|
||||
Href string `json:"href"`
|
||||
Header map[string]string `json:"header,omitempty"`
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
ExpiresIn time.Duration `json:"expires_in,omitempty"`
|
||||
ExpiresIn int64 `json:"expires_in,omitempty"`
|
||||
}
|
||||
|
||||
func (a *Action) IsExpiredWithin(d time.Duration) (time.Time, bool) {
|
||||
return tools.IsExpiredAtOrIn(d, a.ExpiresAt, a.ExpiresIn)
|
||||
return tools.IsExpiredAtOrIn(d, a.ExpiresAt, time.Duration(a.ExpiresIn)*time.Second)
|
||||
}
|
||||
|
||||
type ActionSet map[string]*Action
|
||||
|
Loading…
Reference in New Issue
Block a user