Skip to content

Commit a5f8ca4

Browse files
Added artifact end points
1 parent b4dfd33 commit a5f8ca4

File tree

8 files changed

+480
-37
lines changed

8 files changed

+480
-37
lines changed

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = {
1515
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used by the application
1616
AWS_READ_UNITS: process.env.AWS_READ_UNITS || 5,
1717
AWS_WRITE_UNITS: process.env.AWS_WRITE_UNITS || 5,
18-
S3_BUCKET: process.env.S3_BUCKET || 'tc-testing-submissions' // S3 Bucket to which submissions need to be uploaded
18+
S3_BUCKET: process.env.S3_BUCKET || 'tc-testing-submissions', // S3 Bucket to which submissions need to be uploaded
19+
ARTIFACT_BUCKET: process.env.ARTIFACT_BUCKET || 'tc-testing-submissions' // S3 bucket to which artifacts need to be uploaded
1920
},
2021
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
2122
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'error.notification',

docs/Submission API.postman_collection.json

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "1c4ee28f-c371-444e-9cc4-00aaab082194",
3+
"_postman_id": "ff7cef98-25e0-4a50-b956-27bf55869441",
44
"name": "Submission API",
55
"description": "Topcoder Submission API Postman Collection",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
@@ -2727,6 +2727,142 @@
27272727
},
27282728
"response": []
27292729
},
2730+
{
2731+
"name": "Create Artifact",
2732+
"event": [
2733+
{
2734+
"listen": "test",
2735+
"script": {
2736+
"id": "1811a0ee-8f4f-47da-84ce-18492396e11b",
2737+
"exec": [
2738+
""
2739+
],
2740+
"type": "text/javascript"
2741+
}
2742+
}
2743+
],
2744+
"request": {
2745+
"method": "POST",
2746+
"header": [
2747+
{
2748+
"key": "Authorization",
2749+
"value": "Bearer {{USER_TOKEN}}"
2750+
}
2751+
],
2752+
"body": {
2753+
"mode": "formdata",
2754+
"formdata": [
2755+
{
2756+
"key": "artifact",
2757+
"type": "file",
2758+
"src": ""
2759+
},
2760+
{
2761+
"key": "typeId",
2762+
"value": "{{artifactID}}",
2763+
"type": "text"
2764+
}
2765+
]
2766+
},
2767+
"url": {
2768+
"raw": "{{URL}}/submissions/{{submissionID}}/artifacts",
2769+
"host": [
2770+
"{{URL}}"
2771+
],
2772+
"path": [
2773+
"submissions",
2774+
"{{submissionID}}",
2775+
"artifacts"
2776+
]
2777+
}
2778+
},
2779+
"response": []
2780+
},
2781+
{
2782+
"name": "List Artifacts",
2783+
"event": [
2784+
{
2785+
"listen": "test",
2786+
"script": {
2787+
"id": "1811a0ee-8f4f-47da-84ce-18492396e11b",
2788+
"exec": [
2789+
""
2790+
],
2791+
"type": "text/javascript"
2792+
}
2793+
}
2794+
],
2795+
"protocolProfileBehavior": {
2796+
"disableBodyPruning": true
2797+
},
2798+
"request": {
2799+
"method": "GET",
2800+
"header": [
2801+
{
2802+
"key": "Authorization",
2803+
"value": "Bearer {{USER_TOKEN}}"
2804+
}
2805+
],
2806+
"body": {},
2807+
"url": {
2808+
"raw": "{{URL}}/submissions/{{submissionID}}/artifacts",
2809+
"host": [
2810+
"{{URL}}"
2811+
],
2812+
"path": [
2813+
"submissions",
2814+
"{{submissionID}}",
2815+
"artifacts"
2816+
]
2817+
}
2818+
},
2819+
"response": []
2820+
},
2821+
{
2822+
"name": "Download Artifact",
2823+
"event": [
2824+
{
2825+
"listen": "test",
2826+
"script": {
2827+
"id": "1811a0ee-8f4f-47da-84ce-18492396e11b",
2828+
"exec": [
2829+
"if( responseCode.code === 200) {",
2830+
" const response = JSON.parse(responseBody);",
2831+
" pm.environment.set(\"submissionID\", response.id);",
2832+
"}"
2833+
],
2834+
"type": "text/javascript"
2835+
}
2836+
}
2837+
],
2838+
"protocolProfileBehavior": {
2839+
"disableBodyPruning": true
2840+
},
2841+
"request": {
2842+
"method": "GET",
2843+
"header": [
2844+
{
2845+
"key": "Authorization",
2846+
"value": "Bearer {{USER_TOKEN}}"
2847+
}
2848+
],
2849+
"body": {},
2850+
"url": {
2851+
"raw": "{{URL}}/submissions/{{submissionID}}/artifacts/{{artifactID}}/download",
2852+
"host": [
2853+
"{{URL}}"
2854+
],
2855+
"path": [
2856+
"submissions",
2857+
"{{submissionID}}",
2858+
"artifacts",
2859+
"{{artifactID}}",
2860+
"download"
2861+
]
2862+
}
2863+
},
2864+
"response": []
2865+
},
27302866
{
27312867
"name": "Delete Submission",
27322868
"request": {
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
{
2-
"id": "4dc7f607-5fac-476c-b60b-8ec11aca574c",
3-
"name": "submission-api",
4-
"values": [
5-
{
6-
"key": "URL",
7-
"value": "http://localhost:3000/api/v5",
8-
"enabled": true,
9-
"type": "text"
10-
},
11-
{
12-
"key": "ADMIN_TOKEN",
13-
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJBZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlRvbnlKIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0MzMyODgiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiYWRtaW5AdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.pIHUtMwIV07ZgfaUk9916X49rgjKclM9kzQP419LBo0",
14-
"enabled": true,
15-
"type": "text"
16-
},
17-
{
18-
"key": "COPILOT_TOKEN",
19-
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJDb3BpbG90Il0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6ImNhbGxtZWthdG9vdGllIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwMTIiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiY2FsbG1la2F0b290aWVAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.AR1-A7zm8Rur-P36De4GUsSO1FsSb2CWby8KUZ66Dm0",
20-
"enabled": true,
21-
"type": "text"
22-
},
23-
{
24-
"key": "USER_TOKEN",
25-
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM",
26-
"enabled": true,
27-
"type": "text"
28-
}
29-
],
30-
"_postman_variable_scope": "environment",
31-
"_postman_exported_at": "2018-07-03T14:48:12.881Z",
32-
"_postman_exported_using": "Postman/6.1.3"
2+
"id": "eac995de-0f91-4dd2-a4c7-dab75cc3037e",
3+
"name": "submission-api",
4+
"values": [
5+
{
6+
"key": "URL",
7+
"value": "http://localhost:3000/api/v5",
8+
"enabled": true
9+
},
10+
{
11+
"key": "ADMIN_TOKEN",
12+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJBZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlRvbnlKIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0MzMyODgiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiYWRtaW5AdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.pIHUtMwIV07ZgfaUk9916X49rgjKclM9kzQP419LBo0",
13+
"enabled": true
14+
},
15+
{
16+
"key": "COPILOT_TOKEN",
17+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJDb3BpbG90Il0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6ImNhbGxtZWthdG9vdGllIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwMTIiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiY2FsbG1la2F0b290aWVAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.AR1-A7zm8Rur-P36De4GUsSO1FsSb2CWby8KUZ66Dm0",
18+
"enabled": true
19+
},
20+
{
21+
"key": "USER_TOKEN",
22+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM",
23+
"enabled": true
24+
},
25+
{
26+
"key": "submissionID",
27+
"value": "a12a4180-65aa-42ec-a945-5fd21dec0505",
28+
"description": {
29+
"content": "",
30+
"type": "text/plain"
31+
},
32+
"enabled": true
33+
},
34+
{
35+
"key": "artifactID",
36+
"value": "c56a4180-65aa-42ec-a945-5fd21dec0503",
37+
"description": "",
38+
"enabled": true
39+
}
40+
],
41+
"_postman_variable_scope": "environment",
42+
"_postman_exported_at": "2019-01-10T10:16:10.847Z",
43+
"_postman_exported_using": "Postman/6.5.3"
3344
}

docs/swagger.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,103 @@ paths:
434434
$ref: '#/definitions/NotFound'
435435
500:
436436
$ref: '#/definitions/ServerError'
437+
/submissions/{submissionId}/artifacts:
438+
post:
439+
summary: Create artifact for the given submission ID
440+
description: |
441+
Create artifact in S3
442+
443+
**Authorization:** Create artifact follows the same authorization rules as Create submission
444+
tags:
445+
- Submissions
446+
operationId: createArtifact
447+
parameters:
448+
- $ref: '#/parameters/submissionIdParam'
449+
- in: body
450+
name: typeId
451+
required: true
452+
schema:
453+
type: string
454+
example: 'c56a4180-65aa-42ec-a945-5fd21dec0503'
455+
responses:
456+
200:
457+
description: Artifact created successfully
458+
schema:
459+
type: object
460+
properties:
461+
artifact:
462+
type: string
463+
description: Uploaded artifact name
464+
example: c56a4180-65aa-42ec-a945-5fd21dec0503.json
465+
400:
466+
$ref: '#/definitions/BadRequest'
467+
401:
468+
$ref: '#/definitions/Unauthorized'
469+
403:
470+
$ref: '#/definitions/Forbidden'
471+
404:
472+
$ref: '#/definitions/NotFound'
473+
500:
474+
$ref: '#/definitions/ServerError'
475+
get:
476+
summary: List artifacts for the given Submission ID
477+
description: |
478+
List artifacts for given Submission ID from S3
479+
480+
**Authorization:** List artifact follows the same authorization rules as Get submission
481+
tags:
482+
- Submissions
483+
operationId: listArtifacts
484+
parameters:
485+
- $ref: '#/parameters/submissionIdParam'
486+
responses:
487+
200:
488+
description: Artifacts from S3 listed successfully
489+
schema:
490+
type: object
491+
properties:
492+
artifacts:
493+
type: array
494+
description: Artifact IDs list
495+
items:
496+
type: string
497+
example: c56a4180-65aa-42ec-a945-5fd21dec0503
498+
400:
499+
$ref: '#/definitions/BadRequest'
500+
401:
501+
$ref: '#/definitions/Unauthorized'
502+
403:
503+
$ref: '#/definitions/Forbidden'
504+
404:
505+
$ref: '#/definitions/NotFound'
506+
500:
507+
$ref: '#/definitions/ServerError'
508+
/submissions/{submissionId}/artifacts/{file}/download:
509+
get:
510+
summary: Download artifact from S3
511+
description: |
512+
Download artifact from S3 using Submission ID and Artifact ID
513+
514+
**Authorization:** Download artifact follows same authorization rules as Download submission
515+
tags:
516+
- Submissions
517+
operationId: downloadArtifact
518+
parameters:
519+
- $ref: '#/parameters/submissionIdParam'
520+
- $ref: '#/parameters/fileParam'
521+
responses:
522+
200:
523+
description: Artifact from S3 downloaded successfully
524+
400:
525+
$ref: '#/definitions/BadRequest'
526+
401:
527+
$ref: '#/definitions/Unauthorized'
528+
403:
529+
$ref: '#/definitions/Forbidden'
530+
404:
531+
$ref: '#/definitions/NotFound'
532+
500:
533+
$ref: '#/definitions/ServerError'
437534
/reviewSummations:
438535
get:
439536
summary: Get all review summations.
@@ -1537,6 +1634,13 @@ parameters:
15371634
description: review type id
15381635
required: true
15391636
type: string
1637+
1638+
fileParam:
1639+
name: file
1640+
in: path
1641+
description: artifact id
1642+
required: true
1643+
type: string
15401644

15411645
submissionIdParam:
15421646
name: submissionId

src/controllers/ArtifactController.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Artifact Controller
3+
*/
4+
5+
const ArtifactService = require('../services/ArtifactService')
6+
7+
/**
8+
* Download Artifact from S3
9+
* @param req the http request
10+
* @param res the http response
11+
*/
12+
function * downloadArtifact (req, res) {
13+
const result = yield ArtifactService.downloadArtifact(req.params.submissionId, req.params.file)
14+
res.attachment(result.fileName)
15+
res.send(result.file)
16+
}
17+
18+
/**
19+
* List Artifacts from S3 bucket
20+
* @param req the http request
21+
* @param res the http response
22+
*/
23+
function * listArtifacts (req, res) {
24+
res.json(yield ArtifactService.listArtifacts(req.params.submissionId))
25+
}
26+
27+
/**
28+
* Upload and Create Artifact
29+
* @param req the http request
30+
* @param res the http response
31+
*/
32+
function * createArtifact (req, res) {
33+
res.json(yield ArtifactService.createArtifact(req.files, req.params.submissionId, req.body))
34+
}
35+
36+
module.exports = {
37+
downloadArtifact,
38+
listArtifacts,
39+
createArtifact
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy