Skip to content

Commit b65800a

Browse files
committed
tq,lfsapi/auth: change expires_in to be a whole number of seconds
1 parent 5e4016d commit b65800a

6 files changed

Lines changed: 18 additions & 12 deletions

File tree

docs/api/batch.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ omitted.
8383
* `href` - String URL to download the object.
8484
* `header` - Optional hash of String HTTP header key/value pairs to apply
8585
to the request.
86-
* `expires_in` - Nanoseconds after local client time when transfer will
87-
expire. Preferred over `expires_at` if both are provided.
86+
* `expires_in` - Whole number of seconds after local client time when
87+
transfer will expire. Preferred over `expires_at` if both are provided.
88+
Maximum of 9223372036, minimum of -9223372036.
8889
* `expires_at` - String ISO 8601 formatted timestamp for when the given
8990
action expires (usually due to a temporary token).
9091

lfsapi/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ type sshAuthResponse struct {
5858
Href string `json:"href"`
5959
Header map[string]string `json:"header"`
6060
ExpiresAt time.Time `json:"expires_at"`
61-
ExpiresIn time.Duration `json:"expires_in"`
61+
ExpiresIn int64 `json:"expires_in"`
6262
}
6363

6464
func (r *sshAuthResponse) IsExpiredWithin(d time.Duration) (time.Time, bool) {
65-
return tools.IsExpiredAtOrIn(d, r.ExpiresAt, r.ExpiresIn)
65+
return tools.IsExpiredAtOrIn(d, r.ExpiresAt, time.Duration(r.ExpiresIn)*time.Second)
6666
}
6767

6868
type sshAuthClient struct {

test/cmd/lfstest-gitserver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ type lfsLink struct {
180180
Href string `json:"href"`
181181
Header map[string]string `json:"header,omitempty"`
182182
ExpiresAt time.Time `json:"expires_at,omitempty"`
183-
ExpiresIn time.Duration `json:"expires_in,omitempty"`
183+
ExpiresIn int64 `json:"expires_in,omitempty"`
184184
}
185185

186186
type lfsError struct {
@@ -484,10 +484,10 @@ func serveExpired(a *lfsLink, repo, handler string) *lfsLink {
484484
case "expired-absolute":
485485
a.ExpiresAt = at
486486
case "expired-relative":
487-
a.ExpiresIn = dur
487+
a.ExpiresIn = -5
488488
case "expired-both":
489489
a.ExpiresAt = at
490-
a.ExpiresIn = dur
490+
a.ExpiresIn = -5
491491
}
492492

493493
return a

test/cmd/ssh-echo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type sshResponse struct {
1414
Href string `json:"href"`
1515
Header map[string]string `json:"header"`
1616
ExpiresAt time.Time `json:"expires_at,omitempty"`
17-
ExpiresIn time.Duration `json:"expires_in,omitempty"`
17+
ExpiresIn int64 `json:"expires_in,omitempty"`
1818
}
1919

2020
func main() {
@@ -40,10 +40,10 @@ func main() {
4040
case "ssh-expired-absolute":
4141
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
4242
case "ssh-expired-relative":
43-
r.ExpiresIn = -5 * time.Minute
43+
r.ExpiresIn = -5
4444
case "ssh-expired-both":
4545
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
46-
r.ExpiresIn = -5 * time.Minute
46+
r.ExpiresIn = -5
4747
}
4848

4949
json.NewEncoder(os.Stdout).Encode(r)

tq/schemas/http-batch-response-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"type": "object",
1515
"additionalProperties": true
1616
},
17+
"expires_in": {
18+
"type": "number",
19+
"maximum": 9223372036,
20+
"minimum": -9223372036
21+
},
1722
"expires_at": {
1823
"type": "string"
1924
}

tq/transfer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ type Action struct {
113113
Href string `json:"href"`
114114
Header map[string]string `json:"header,omitempty"`
115115
ExpiresAt time.Time `json:"expires_at,omitempty"`
116-
ExpiresIn time.Duration `json:"expires_in,omitempty"`
116+
ExpiresIn int64 `json:"expires_in,omitempty"`
117117
}
118118

119119
func (a *Action) IsExpiredWithin(d time.Duration) (time.Time, bool) {
120-
return tools.IsExpiredAtOrIn(d, a.ExpiresAt, a.ExpiresIn)
120+
return tools.IsExpiredAtOrIn(d, a.ExpiresAt, time.Duration(a.ExpiresIn)*time.Second)
121121
}
122122

123123
type ActionSet map[string]*Action

0 commit comments

Comments
 (0)