Skip to content

Commit 78a9e1b

Browse files
authored
fix(api-dkim): Add all DKIM API endpoints to API docs generation ZMS-129 (#630)
* added List registered DKIM keys to API docs generation * Added Resolve ID for a DKIM domain api endpoint to API docs generation * Added Delete a DKIM key api endpoint to API docs generation * Added Request DKIM information api endpoint to api docs generation. Fix typo * added create or update dkim key for domain api endpoint to api docs generation
1 parent f61111e commit 78a9e1b

File tree

1 file changed

+224
-53
lines changed

1 file changed

+224
-53
lines changed

lib/api/dkim.js

+224-53
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const DkimHandler = require('../dkim-handler');
88
const tools = require('../tools');
99
const roles = require('../roles');
1010
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema } = require('../schemas');
11+
const { successRes, totalRes, pageRes, previousCursorRes, nextCursorRes } = require('../schemas/response/general-schemas');
1112

1213
module.exports = (db, server) => {
1314
const dkimHandler = new DkimHandler({
@@ -18,18 +19,62 @@ module.exports = (db, server) => {
1819
});
1920

2021
server.get(
21-
{ name: 'dkim', path: '/dkim' },
22+
{
23+
name: 'dkim',
24+
path: '/dkim',
25+
tags: ['DKIM'],
26+
summary: 'List registered DKIM keys',
27+
validationObjs: {
28+
requestBody: {},
29+
queryParams: {
30+
query: Joi.string().empty('').trim().max(255).description('Partial match of a Domain name'),
31+
limit: Joi.number().default(20).min(1).max(250).description('How many records to return'),
32+
next: nextPageCursorSchema,
33+
previous: previousPageCursorSchema,
34+
page: pageNrSchema,
35+
sess: sessSchema,
36+
ip: sessIPSchema
37+
},
38+
pathParams: {},
39+
response: {
40+
200: {
41+
description: 'Success',
42+
model: Joi.object({
43+
success: successRes,
44+
total: totalRes,
45+
page: pageRes,
46+
previousCursor: previousCursorRes,
47+
nextCursor: nextCursorRes,
48+
query: Joi.string().required().description('Query string. Partial match of a Domain name'),
49+
results: Joi.array()
50+
.required()
51+
.items(
52+
Joi.object({
53+
id: Joi.string().required().description('ID of the DKIM'),
54+
domain: Joi.string().required().description('The domain this DKIM key applies to'),
55+
selector: Joi.string().required().description('DKIM selector'),
56+
description: Joi.string().required().description('Key description'),
57+
fingerprint: Joi.string().required().description('Key fingerprint (SHA1)'),
58+
created: Joi.date().required().description('DKIM created datestring')
59+
})
60+
.$_setFlag('objectName', 'GetDkimKeysResult')
61+
.required()
62+
)
63+
.description('DKIM listing')
64+
})
65+
}
66+
}
67+
}
68+
},
2269
tools.responseWrapper(async (req, res) => {
2370
res.charSet('utf-8');
2471

25-
const schema = Joi.object().keys({
26-
query: Joi.string().empty('').trim().max(255),
27-
limit: Joi.number().default(20).min(1).max(250),
28-
next: nextPageCursorSchema,
29-
previous: previousPageCursorSchema,
30-
page: pageNrSchema,
31-
sess: sessSchema,
32-
ip: sessIPSchema
72+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
73+
74+
const schema = Joi.object({
75+
...pathParams,
76+
...queryParams,
77+
...requestBody
3378
});
3479

3580
const result = schema.validate(req.params, {
@@ -117,17 +162,43 @@ module.exports = (db, server) => {
117162
);
118163

119164
server.get(
120-
'/dkim/resolve/:domain',
165+
{
166+
path: '/dkim/resolve/:domain',
167+
tags: ['DKIM'],
168+
summary: 'Resolve ID for a DKIM domain',
169+
validationObjs: {
170+
requestBody: {},
171+
queryParams: {
172+
sess: sessSchema,
173+
ip: sessIPSchema
174+
},
175+
pathParams: {
176+
domain: Joi.string()
177+
.max(255)
178+
//.hostname()
179+
.required()
180+
.description('DKIM domain')
181+
},
182+
response: {
183+
200: {
184+
description: 'Success',
185+
model: Joi.object({
186+
success: successRes,
187+
id: Joi.string().required().description('DKIM unique ID (24 byte hex)').example('609d201236d1d936948f23b1')
188+
})
189+
}
190+
}
191+
}
192+
},
121193
tools.responseWrapper(async (req, res) => {
122194
res.charSet('utf-8');
123195

124-
const schema = Joi.object().keys({
125-
domain: Joi.string()
126-
.max(255)
127-
//.hostname()
128-
.required(),
129-
sess: sessSchema,
130-
ip: sessIPSchema
196+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
197+
198+
const schema = Joi.object({
199+
...pathParams,
200+
...queryParams,
201+
...requestBody
131202
});
132203

133204
const result = schema.validate(req.params, {
@@ -184,34 +255,80 @@ module.exports = (db, server) => {
184255
);
185256

186257
server.post(
187-
'/dkim',
258+
{
259+
path: '/dkim',
260+
tags: ['DKIM'],
261+
summary: 'Create or update DKIM key for domain',
262+
description: 'Add a new DKIM key for a Domain or update existing one. There can be single DKIM key registered for each domain name.',
263+
validationObjs: {
264+
requestBody: {
265+
domain: Joi.string()
266+
.max(255)
267+
//.hostname()
268+
.required()
269+
.description(
270+
'Domain name this DKIM key applies to. Use "*" as a special value that will be used for domains that do not have their own DKIM key set'
271+
),
272+
selector: Joi.string()
273+
.max(255)
274+
//.hostname()
275+
.trim()
276+
.required()
277+
.description('Selector for the key'),
278+
privateKey: Joi.alternatives()
279+
.try(
280+
Joi.string()
281+
.empty('')
282+
.trim()
283+
.regex(/^-----BEGIN (RSA )?PRIVATE KEY-----/, 'DKIM key format')
284+
.description('PEM format RSA or ED25519 string'),
285+
Joi.string().empty('').trim().base64().length(44).description('Raw ED25519 key 44 bytes long if using base64')
286+
)
287+
.description(
288+
'Pem formatted DKIM private key, raw ED25519 is also allowed. If not set then a new 2048 bit RSA key is generated, beware though that it can take several seconds to complete.'
289+
),
290+
description: Joi.string()
291+
.max(255)
292+
//.hostname()
293+
.trim()
294+
.description('Key description'),
295+
sess: sessSchema,
296+
ip: sessIPSchema
297+
},
298+
queryParams: {},
299+
pathParams: {},
300+
response: {
301+
200: {
302+
description: 'Success',
303+
model: Joi.object({
304+
success: successRes,
305+
id: Joi.string().required().description('ID of the DKIM'),
306+
domain: Joi.string().required().description('The domain this DKIM key applies to'),
307+
selector: Joi.string().required().description('DKIM selector'),
308+
description: Joi.string().required().description('Key description'),
309+
fingerprint: Joi.string().required().description('Key fingerprint (SHA1)'),
310+
publicKey: Joi.string().required().description('Public key in DNS format (no prefix/suffix, single line)'),
311+
dnsTxt: Joi.object({
312+
name: Joi.string().required().description('Is the domain name of TXT'),
313+
value: Joi.string().required().description('Is the value of TXT')
314+
})
315+
.required()
316+
.description('Value for DNS TXT entry')
317+
.$_setFlag('objectName', 'DnsTxt')
318+
})
319+
}
320+
}
321+
}
322+
},
188323
tools.responseWrapper(async (req, res) => {
189324
res.charSet('utf-8');
190325

191-
const schema = Joi.object().keys({
192-
domain: Joi.string()
193-
.max(255)
194-
//.hostname()
195-
.required(),
196-
selector: Joi.string()
197-
.max(255)
198-
//.hostname()
199-
.trim()
200-
.required(),
201-
privateKey: Joi.alternatives().try(
202-
Joi.string()
203-
.empty('')
204-
.trim()
205-
.regex(/^-----BEGIN (RSA )?PRIVATE KEY-----/, 'DKIM key format')
206-
.description('PEM format RSA or ED25519 string'),
207-
Joi.string().empty('').trim().base64().length(44).description('Raw ED25519 key 44 bytes long if using base64')
208-
),
209-
description: Joi.string()
210-
.max(255)
211-
//.hostname()
212-
.trim(),
213-
sess: sessSchema,
214-
ip: sessIPSchema
326+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
327+
328+
const schema = Joi.object({
329+
...pathParams,
330+
...queryParams,
331+
...requestBody
215332
});
216333

217334
const result = schema.validate(req.params, {
@@ -252,14 +369,52 @@ module.exports = (db, server) => {
252369
);
253370

254371
server.get(
255-
'/dkim/:dkim',
372+
{
373+
path: '/dkim/:dkim',
374+
tags: ['DKIM'],
375+
summary: 'Request DKIM information',
376+
validationObjs: {
377+
requestBody: {},
378+
queryParams: {
379+
sess: sessSchema,
380+
ip: sessIPSchema
381+
},
382+
pathParams: {
383+
dkim: Joi.string().hex().lowercase().length(24).required().description('ID of the DKIM')
384+
},
385+
response: {
386+
200: {
387+
description: 'Success',
388+
model: Joi.object({
389+
success: successRes,
390+
id: Joi.string().required().description('ID of the DKIM'),
391+
domain: Joi.string().required().description('The domain this DKIM key applies to'),
392+
selector: Joi.string().required().description('DKIM selector'),
393+
description: Joi.string().required().description('Key description'),
394+
fingerprint: Joi.string().required().description('Key fingerprint (SHA1)'),
395+
publicKey: Joi.string().required().description('Public key in DNS format (no prefix/suffix, single line)'),
396+
dnsTxt: Joi.object({
397+
name: Joi.string().required().description('Is the domain name of TXT'),
398+
value: Joi.string().required().description('Is the value of TXT')
399+
})
400+
.required()
401+
.description('Value for DNS TXT entry')
402+
.$_setFlag('objectName', 'DnsTxt'),
403+
created: Joi.date().required().description('DKIM created datestring')
404+
})
405+
}
406+
}
407+
}
408+
},
256409
tools.responseWrapper(async (req, res) => {
257410
res.charSet('utf-8');
258411

259-
const schema = Joi.object().keys({
260-
dkim: Joi.string().hex().lowercase().length(24).required(),
261-
sess: sessSchema,
262-
ip: sessIPSchema
412+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
413+
414+
const schema = Joi.object({
415+
...pathParams,
416+
...queryParams,
417+
...requestBody
263418
});
264419

265420
const result = schema.validate(req.params, {
@@ -301,16 +456,32 @@ module.exports = (db, server) => {
301456
);
302457

303458
server.del(
304-
'/dkim/:dkim',
459+
{
460+
path: '/dkim/:dkim',
461+
tags: ['DKIM'],
462+
summary: 'Delete a DKIM key',
463+
validationObjs: {
464+
requestBody: {},
465+
queryParams: {
466+
sess: sessSchema,
467+
ip: sessIPSchema
468+
},
469+
pathParams: {
470+
dkim: Joi.string().hex().lowercase().length(24).required().description('ID of the DKIM')
471+
},
472+
response: { 200: { description: 'Success', model: Joi.object({ success: successRes }) } }
473+
}
474+
},
305475
tools.responseWrapper(async (req, res) => {
306476
res.charSet('utf-8');
307477

308-
const schema = Joi.object().keys({
309-
dkim: Joi.string().hex().lowercase().length(24).required(),
310-
sess: sessSchema,
311-
ip: sessIPSchema
312-
});
478+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
313479

480+
const schema = Joi.object({
481+
...pathParams,
482+
...queryParams,
483+
...requestBody
484+
});
314485
const result = schema.validate(req.params, {
315486
abortEarly: false,
316487
convert: true

0 commit comments

Comments
 (0)