Skip to content

Commit 6efd1c1

Browse files
authored
Merge pull request #50 from lsst-dm/IT-6370/release-field
add version field to RequestStatus client response
2 parents 670603d + b63ab31 commit 6efd1c1

File tree

6 files changed

+106
-7
lines changed

6 files changed

+106
-7
lines changed

conf/conf.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type S3ndConf struct {
2424
UploadPartsize *k8sresource.Quantity
2525
UploadBwlimit *k8sresource.Quantity
2626
UploadWriteBufferSize *k8sresource.Quantity
27+
version string
2728
}
2829

2930
func (conf *S3ndConf) ToMap() map[string]string {
@@ -47,10 +48,16 @@ func (conf *S3ndConf) UploadBwlimitBytes() int64 {
4748
return util.DivCeil(conf.UploadBwlimit.Value(), 8)
4849
}
4950

51+
// Version returns the s3nd|api version.
52+
func (conf *S3ndConf) Version() string {
53+
return conf.version
54+
}
55+
5056
// Parse the environment variables and flags. If a flag is not set, the
5157
// environment variable is used. Errors are fatal.
5258
func NewConf(version string) S3ndConf {
5359
conf := S3ndConf{}
60+
conf.version = version
5461

5562
// start flags
5663
defaultHost, ok := os.LookupEnv("S3ND_HOST")
@@ -116,7 +123,7 @@ func NewConf(version string) S3ndConf {
116123
// end flags
117124

118125
if *versionFlag {
119-
fmt.Println(version)
126+
fmt.Println(conf.version)
120127
os.Exit(0)
121128
}
122129

docs/docs.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ const docTemplate = `{
175175
},
176176
"task": {
177177
"$ref": "#/definitions/task"
178+
},
179+
"version": {
180+
"description": "s3nd|api version",
181+
"type": "string",
182+
"example": "0.0.0"
178183
}
179184
}
180185
},
@@ -206,6 +211,11 @@ const docTemplate = `{
206211
"example": "Gray Garden Slug"
207212
}
208213
}
214+
},
215+
"version": {
216+
"description": "s3nd|api version",
217+
"type": "string",
218+
"example": "0.0.0"
209219
}
210220
}
211221
},
@@ -222,6 +232,11 @@ const docTemplate = `{
222232
},
223233
"task": {
224234
"$ref": "#/definitions/task"
235+
},
236+
"version": {
237+
"description": "s3nd|api version",
238+
"type": "string",
239+
"example": "0.0.0"
225240
}
226241
}
227242
},
@@ -238,6 +253,11 @@ const docTemplate = `{
238253
},
239254
"task": {
240255
"$ref": "#/definitions/task"
256+
},
257+
"version": {
258+
"description": "s3nd|api version",
259+
"type": "string",
260+
"example": "0.0.0"
241261
}
242262
}
243263
},
@@ -317,6 +337,11 @@ const docTemplate = `{
317337
"example": "s3://my-bucket/my-key"
318338
}
319339
}
340+
},
341+
"version": {
342+
"description": "s3nd|api version",
343+
"type": "string",
344+
"example": "0.0.0"
320345
}
321346
}
322347
},
@@ -352,6 +377,11 @@ const docTemplate = `{
352377
"example": "s3://my-bucket/my-key"
353378
}
354379
}
380+
},
381+
"version": {
382+
"description": "s3nd|api version",
383+
"type": "string",
384+
"example": "0.0.0"
355385
}
356386
}
357387
},

docs/swagger.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@
166166
},
167167
"task": {
168168
"$ref": "#/definitions/task"
169+
},
170+
"version": {
171+
"description": "s3nd|api version",
172+
"type": "string",
173+
"example": "0.0.0"
169174
}
170175
}
171176
},
@@ -197,6 +202,11 @@
197202
"example": "Gray Garden Slug"
198203
}
199204
}
205+
},
206+
"version": {
207+
"description": "s3nd|api version",
208+
"type": "string",
209+
"example": "0.0.0"
200210
}
201211
}
202212
},
@@ -213,6 +223,11 @@
213223
},
214224
"task": {
215225
"$ref": "#/definitions/task"
226+
},
227+
"version": {
228+
"description": "s3nd|api version",
229+
"type": "string",
230+
"example": "0.0.0"
216231
}
217232
}
218233
},
@@ -229,6 +244,11 @@
229244
},
230245
"task": {
231246
"$ref": "#/definitions/task"
247+
},
248+
"version": {
249+
"description": "s3nd|api version",
250+
"type": "string",
251+
"example": "0.0.0"
232252
}
233253
}
234254
},
@@ -308,6 +328,11 @@
308328
"example": "s3://my-bucket/my-key"
309329
}
310330
}
331+
},
332+
"version": {
333+
"description": "s3nd|api version",
334+
"type": "string",
335+
"example": "0.0.0"
311336
}
312337
}
313338
},
@@ -343,6 +368,11 @@
343368
"example": "s3://my-bucket/my-key"
344369
}
345370
}
371+
},
372+
"version": {
373+
"description": "s3nd|api version",
374+
"type": "string",
375+
"example": "0.0.0"
346376
}
347377
}
348378
},

docs/swagger.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Status: Gateway Timeout
224224
| code | integer| `int64` | | | | `200` |
225225
| msg | string| `string` | | | | `upload succeeded` |
226226
| task | [Task](#task)| `Task` | | | | |
227+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
227228

228229

229230

@@ -241,6 +242,7 @@ Status: Gateway Timeout
241242
| code | integer| `int64` | | | | `400` |
242243
| msg | string| `string` | | | | `error parsing request: missing field: uri` |
243244
| task | [RequestStatus400Task](#request-status400-task)| `RequestStatus400Task` | | | | |
245+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
244246

245247

246248

@@ -277,6 +279,7 @@ Status: Gateway Timeout
277279
| code | integer| `int64` | | | | `404` |
278280
| msg | string| `string` | | | | `upload failed because the bucket does not exist` |
279281
| task | [Task](#task)| `Task` | | | | |
282+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
280283

281284

282285

@@ -294,6 +297,7 @@ Status: Gateway Timeout
294297
| code | integer| `int64` | | | | `408` |
295298
| msg | string| `string` | | | | `upload queue timeout` |
296299
| task | [Task](#task)| `Task` | | | | |
300+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
297301

298302

299303

@@ -311,6 +315,7 @@ Status: Gateway Timeout
311315
| code | integer| `int64` | | | | `500` |
312316
| msg | string| `string` | | | | `unknown error` |
313317
| task | [RequestStatus500Task](#request-status500-task)| `RequestStatus500Task` | | | | |
318+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
314319

315320

316321

@@ -358,6 +363,7 @@ Status: Gateway Timeout
358363
| code | integer| `int64` | | | | `504` |
359364
| msg | string| `string` | | | | `timeout during upload attempt 2/2` |
360365
| task | [RequestStatus504Task](#request-status504-task)| `RequestStatus504Task` | | | | |
366+
| version | string| `string` | | | s3nd|api version | `0.0.0` |
361367

362368

363369

docs/swagger.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ definitions:
1919
type: string
2020
task:
2121
$ref: '#/definitions/task'
22+
version:
23+
description: s3nd|api version
24+
example: 0.0.0
25+
type: string
2226
type: object
2327
requestStatus400:
2428
properties:
@@ -41,6 +45,10 @@ definitions:
4145
example: Gray Garden Slug
4246
type: string
4347
type: object
48+
version:
49+
description: s3nd|api version
50+
example: 0.0.0
51+
type: string
4452
type: object
4553
requestStatus404:
4654
properties:
@@ -52,6 +60,10 @@ definitions:
5260
type: string
5361
task:
5462
$ref: '#/definitions/task'
63+
version:
64+
description: s3nd|api version
65+
example: 0.0.0
66+
type: string
5567
type: object
5668
requestStatus408:
5769
properties:
@@ -63,6 +75,10 @@ definitions:
6375
type: string
6476
task:
6577
$ref: '#/definitions/task'
78+
version:
79+
description: s3nd|api version
80+
example: 0.0.0
81+
type: string
6682
type: object
6783
requestStatus500:
6884
properties:
@@ -122,6 +138,10 @@ definitions:
122138
example: s3://my-bucket/my-key
123139
type: string
124140
type: object
141+
version:
142+
description: s3nd|api version
143+
example: 0.0.0
144+
type: string
125145
type: object
126146
requestStatus504:
127147
properties:
@@ -147,6 +167,10 @@ definitions:
147167
example: s3://my-bucket/my-key
148168
type: string
149169
type: object
170+
version:
171+
description: s3nd|api version
172+
example: 0.0.0
173+
type: string
150174
type: object
151175
task:
152176
properties:

upload/handler.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ func (u *RequestURL) UnmarshalText(text []byte) error {
252252
}
253253

254254
type RequestStatus struct {
255-
Code int `json:"code" example:"200"`
256-
Msg string `json:"msg,omitempty" example:"upload succeeded"`
257-
Task *UploadTask `json:"task,omitempty"`
255+
Version string `json:"version" example:"0.0.0"` // s3nd|api version
256+
Code int `json:"code" example:"200"`
257+
Msg string `json:"msg,omitempty" example:"upload succeeded"`
258+
Task *UploadTask `json:"task,omitempty"`
258259
} //@name requestStatus200
259260

260261
// requestStatusSwag400 is used only for Swagger documentation
@@ -456,9 +457,10 @@ func (h *S3ndHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
456457
}
457458

458459
status := RequestStatus{
459-
Code: code,
460-
Msg: msg,
461-
Task: task,
460+
Version: h.conf.Version(),
461+
Code: code,
462+
Msg: msg,
463+
Task: task,
462464
}
463465

464466
logLevel := slog.LevelInfo

0 commit comments

Comments
 (0)