Skip to content

Commit aaa6799

Browse files
committed
Merge branch 'develop'
2 parents 2f970f2 + 01cda71 commit aaa6799

15 files changed

+751
-680
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/challenge-api/tree/d
3434
Configuration for the application is at `config/default.js`.
3535
The following parameters can be set in config files or in env variables:
3636

37+
- READONLY: sets the API in read-only mode. POST/PUT/PATCH/DELETE operations will return 403 Forbidden
3738
- LOG_LEVEL: the log level, default is 'debug'
3839
- PORT: the server port, default is 3000
3940
- AUTH_SECRET: The authorization secret used during token verification.

app.js

+9
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ const fileUpload = require('express-fileupload')
1616
const YAML = require('yamljs')
1717
const swaggerUi = require('swagger-ui-express')
1818
const challengeAPISwaggerDoc = YAML.load('./docs/swagger.yaml')
19+
const { ForbiddenError } = require('./src/common/errors')
1920

2021
// setup express app
2122
const app = express()
2223

24+
// Disable POST, PUT, PATCH, DELETE operations if READONLY is set to true
25+
app.use((req, res, next) => {
26+
if (config.READONLY && ['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method)) {
27+
throw new ForbiddenError('Action is temporarely not allowed!')
28+
}
29+
next()
30+
})
31+
2332
// serve challenge V5 API swagger definition
2433
app.use('/v5/challenges/docs', swaggerUi.serve, swaggerUi.setup(challengeAPISwaggerDoc))
2534

config/default.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
module.exports = {
6+
READONLY: process.env.READONLY || false,
67
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
78
PORT: process.env.PORT || 3000,
89
API_VERSION: process.env.API_VERSION || 'v5',

docs/swagger.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ paths:
397397
description: Server error
398398
schema:
399399
$ref: '#/definitions/ErrorModel'
400-
/challengeTypes:
400+
/challenge-types:
401401
get:
402402
tags:
403403
- ChallengeTypes
@@ -513,7 +513,7 @@ paths:
513513
description: Server error
514514
schema:
515515
$ref: '#/definitions/ErrorModel'
516-
'/challengeTypes/:challengeTypeId':
516+
'/challenge-types/:challengeTypeId':
517517
get:
518518
tags:
519519
- ChallengeTypes
@@ -650,7 +650,7 @@ paths:
650650
description: Server error
651651
schema:
652652
$ref: '#/definitions/ErrorModel'
653-
/challengeSettings:
653+
/challenge-settings:
654654
get:
655655
tags:
656656
- ChallengeSettings
@@ -758,7 +758,7 @@ paths:
758758
description: Server error
759759
schema:
760760
$ref: '#/definitions/ErrorModel'
761-
'/challengeSettings/:challengeSettingId':
761+
'/challenge-settings/:challengeSettingId':
762762
get:
763763
tags:
764764
- ChallengeSettings
@@ -853,7 +853,7 @@ paths:
853853
description: Server error
854854
schema:
855855
$ref: '#/definitions/ErrorModel'
856-
/challengePhases:
856+
/challenge-phases:
857857
get:
858858
tags:
859859
- ChallengePhases
@@ -961,7 +961,7 @@ paths:
961961
description: Server error
962962
schema:
963963
$ref: '#/definitions/ErrorModel'
964-
/challengePhases/:challengePhaseId:
964+
/challenge-phases/:challengePhaseId:
965965
get:
966966
tags:
967967
- ChallengePhases
@@ -1152,7 +1152,7 @@ paths:
11521152
description: Server error
11531153
schema:
11541154
$ref: '#/definitions/ErrorModel'
1155-
/timelineTemplates:
1155+
/timeline-templates:
11561156
get:
11571157
tags:
11581158
- TimelineTemplates
@@ -1260,7 +1260,7 @@ paths:
12601260
description: Server error
12611261
schema:
12621262
$ref: '#/definitions/ErrorModel'
1263-
/timelineTemplates/:timelineTemplateId:
1263+
/timeline-templates/:timelineTemplateId:
12641264
get:
12651265
tags:
12661266
- TimelineTemplates
@@ -1451,7 +1451,7 @@ paths:
14511451
description: Server error
14521452
schema:
14531453
$ref: '#/definitions/ErrorModel'
1454-
/challengeTimelines:
1454+
/challenge-timelines:
14551455
get:
14561456
tags:
14571457
- ChallengeTypeTimelineTemplates
@@ -1540,7 +1540,7 @@ paths:
15401540
description: Server error
15411541
schema:
15421542
$ref: '#/definitions/ErrorModel'
1543-
/challengeTimelines/:challengeTypeTimelineTemplateId:
1543+
/challenge-timelines/:challengeTypeTimelineTemplateId:
15441544
get:
15451545
tags:
15461546
- ChallengeTypeTimelineTemplates
@@ -1677,7 +1677,7 @@ paths:
16771677
description: Server error
16781678
schema:
16791679
$ref: '#/definitions/ErrorModel'
1680-
/challengeAuditLogs:
1680+
/challenge-auditLogs:
16811681
get:
16821682
tags:
16831683
- AuditLog

0 commit comments

Comments
 (0)