2022-12-22 18:41:19 +01:00
|
|
|
import { jwt, key, fields, parameters, response, errorExamples, jsonResponse } from './lib.mjs'
|
2022-12-19 11:36:09 +01:00
|
|
|
|
|
|
|
const common = {
|
|
|
|
tags: ['API keys'],
|
|
|
|
security: [jwt, key],
|
|
|
|
}
|
|
|
|
|
2022-12-19 12:27:08 +01:00
|
|
|
const local = {
|
|
|
|
params: {
|
|
|
|
key: {
|
|
|
|
in: 'path',
|
|
|
|
name: 'key',
|
|
|
|
required: true,
|
|
|
|
description: "The API key's UUID (the part you use as username)",
|
|
|
|
schema: {
|
|
|
|
example: 'c00475bd-3002-4baa-80ad-0145cd6a646c',
|
|
|
|
type: 'string',
|
|
|
|
},
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
2022-12-18 20:04:52 +01:00
|
|
|
},
|
2022-12-19 12:27:08 +01:00
|
|
|
response: {
|
|
|
|
body: {
|
2022-12-22 18:41:19 +01:00
|
|
|
regular: {
|
|
|
|
...response.body.apikey,
|
|
|
|
properties: { ...response.body.apikey.properties },
|
2022-12-19 12:27:08 +01:00
|
|
|
},
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-12-19 12:27:08 +01:00
|
|
|
delete local.response.body.regular.properties.secret
|
|
|
|
|
|
|
|
// Paths
|
|
|
|
export const paths = {}
|
2022-12-19 11:36:09 +01:00
|
|
|
|
|
|
|
// Create API key
|
2022-12-19 12:27:08 +01:00
|
|
|
paths['/apikeys/{auth}'] = {
|
2023-04-22 15:37:39 +02:00
|
|
|
get: {
|
|
|
|
...common,
|
|
|
|
summary: 'Retrieves list of API keys',
|
|
|
|
description: 'Returns a list of API keys for the user making the API request',
|
|
|
|
parameters: [parameters.auth],
|
|
|
|
responses: {
|
|
|
|
200: {
|
|
|
|
description:
|
|
|
|
'**Success - List of API keys returned**\n\n' +
|
|
|
|
'Status code `200` indicates that the resource was returned successfully.',
|
|
|
|
...jsonResponse({
|
|
|
|
result: {
|
|
|
|
...fields.result,
|
|
|
|
example: 'success',
|
|
|
|
},
|
|
|
|
apikeys: {
|
|
|
|
type: 'array',
|
|
|
|
items: local.response.body.regular,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
401: response.status['401'],
|
|
|
|
403: {
|
|
|
|
...response.status['403'],
|
|
|
|
description:
|
|
|
|
response.status['403'].description +
|
|
|
|
errorExamples(['accountStatusLacking', 'insufficientAccessLevel']),
|
|
|
|
},
|
|
|
|
500: response.status['500'],
|
|
|
|
},
|
|
|
|
},
|
2022-12-19 11:36:09 +01:00
|
|
|
post: {
|
|
|
|
...common,
|
|
|
|
summary: 'Create a new API key',
|
|
|
|
description:
|
|
|
|
'Creates a new API key and returns it. ' +
|
|
|
|
'requires a `name`, `level`, and `expiresIn` field in the POST body.',
|
|
|
|
parameters: [parameters.auth],
|
2022-12-18 20:04:52 +01:00
|
|
|
requestBody: {
|
|
|
|
required: true,
|
|
|
|
content: {
|
|
|
|
'application/json': {
|
|
|
|
schema: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
expiresIn: {
|
|
|
|
description: `
|
|
|
|
mber of seconds the API key will remain valid before expiring.
|
|
|
|
n never be higher than the \`apikeys.maxExpirySeconds\` configuration setting.`,
|
|
|
|
type: 'number',
|
|
|
|
example: 3600,
|
|
|
|
},
|
|
|
|
level: fields.level,
|
2022-12-22 18:41:19 +01:00
|
|
|
name: {
|
|
|
|
description: `
|
|
|
|
Th e name of the API key exists solely to help you differentiate between your API keys.`,
|
|
|
|
type: 'string',
|
|
|
|
example: 'My first API key',
|
|
|
|
},
|
2022-12-18 20:04:52 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
responses: {
|
|
|
|
201: {
|
2022-12-22 18:41:19 +01:00
|
|
|
...response.status['201'],
|
|
|
|
...jsonResponse({
|
|
|
|
result: fields.result,
|
|
|
|
apikey: response.body.apikey,
|
|
|
|
}),
|
2022-12-18 20:04:52 +01:00
|
|
|
},
|
|
|
|
400: {
|
2022-12-22 18:41:19 +01:00
|
|
|
...response.status['400'],
|
2022-12-18 20:04:52 +01:00
|
|
|
description:
|
2022-12-22 18:41:19 +01:00
|
|
|
response.status['400'].description +
|
|
|
|
errorExamples([
|
|
|
|
'postBodyMissing',
|
|
|
|
'nameMissing',
|
|
|
|
'levelMissing',
|
|
|
|
'expiresInMissing',
|
|
|
|
'levelNotNumeric',
|
|
|
|
'invalidLevel',
|
|
|
|
'expiresInNotNumeric',
|
|
|
|
'expiresInHigherThanMaximum',
|
|
|
|
'keyLevelExceedsRoleLevel',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
500: response.status['500'],
|
2022-12-18 20:04:52 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-12-19 11:36:09 +01:00
|
|
|
// Get/Remove API key
|
2022-12-19 12:27:08 +01:00
|
|
|
paths['/apikeys/{key}/{auth}'] = {
|
2022-12-19 11:36:09 +01:00
|
|
|
// Get API key
|
|
|
|
get: {
|
|
|
|
...common,
|
|
|
|
summary: 'Retrieve an API key',
|
|
|
|
description: 'Retrieves information about the API key `key`.',
|
2022-12-19 12:27:08 +01:00
|
|
|
parameters: [parameters.auth, local.params.key],
|
2022-12-19 11:36:09 +01:00
|
|
|
responses: {
|
|
|
|
200: {
|
|
|
|
description:
|
|
|
|
'**Success - API key returned**\n\n' +
|
|
|
|
'Status code `200` indicates that the resource was returned successfully.',
|
2022-12-22 18:41:19 +01:00
|
|
|
...jsonResponse({
|
|
|
|
result: {
|
|
|
|
...fields.result,
|
|
|
|
example: 'success',
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
2022-12-22 18:41:19 +01:00
|
|
|
apikey: local.response.body.regular,
|
|
|
|
}),
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
2022-12-22 18:41:19 +01:00
|
|
|
401: response.status['401'],
|
2022-12-19 11:36:09 +01:00
|
|
|
403: {
|
2022-12-22 18:41:19 +01:00
|
|
|
...response.status['403'],
|
2022-12-19 11:36:09 +01:00
|
|
|
description:
|
2022-12-22 18:41:19 +01:00
|
|
|
response.status['403'].description +
|
2022-12-19 11:36:09 +01:00
|
|
|
errorExamples(['accountStatusLacking', 'insufficientAccessLevel']),
|
|
|
|
},
|
2022-12-22 18:41:19 +01:00
|
|
|
404: response.status['404'],
|
|
|
|
500: response.status['500'],
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
// Remove API key
|
|
|
|
delete: {
|
|
|
|
...common,
|
|
|
|
summary: 'Remove an API key',
|
|
|
|
description: 'Removes the API key `key`.',
|
2022-12-19 12:27:08 +01:00
|
|
|
parameters: [parameters.auth, local.params.key],
|
2022-12-19 11:36:09 +01:00
|
|
|
responses: {
|
2022-12-22 18:41:19 +01:00
|
|
|
204: response.status['204'],
|
|
|
|
401: response.status['401'],
|
2022-12-19 11:36:09 +01:00
|
|
|
403: {
|
2022-12-22 18:41:19 +01:00
|
|
|
...response.status['403'],
|
2022-12-19 11:36:09 +01:00
|
|
|
description:
|
2022-12-22 18:41:19 +01:00
|
|
|
response.status['403'].description +
|
2022-12-19 11:36:09 +01:00
|
|
|
errorExamples(['accountStatusLacking', 'insufficientAccessLevel']),
|
|
|
|
},
|
2022-12-22 18:41:19 +01:00
|
|
|
404: response.status['404'],
|
|
|
|
500: response.status['500'],
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-12-18 20:04:52 +01:00
|
|
|
|
2022-12-19 11:36:09 +01:00
|
|
|
// Get current API key
|
2022-12-19 12:27:08 +01:00
|
|
|
paths['/whoami/key'] = {
|
2022-12-19 11:36:09 +01:00
|
|
|
get: {
|
|
|
|
tags: ['Whoami', ...common.tags],
|
|
|
|
security: [key],
|
|
|
|
summary: 'Retrieve the API key used in the request',
|
|
|
|
description:
|
|
|
|
'Retrieves information about the API key that ' +
|
|
|
|
'was used to authenticate the request.\n\n' +
|
|
|
|
'**Note:** _See `GET /whoami/jwt` for the JWT equivalent._',
|
|
|
|
responses: {
|
2022-12-22 18:41:19 +01:00
|
|
|
200: paths['/apikeys/{key}/{auth}'].get.responses['200'],
|
|
|
|
401: response.status['401'],
|
2022-12-24 14:47:43 +01:00
|
|
|
403: paths['/apikeys/{key}/{auth}'].get.responses['403'],
|
2022-12-22 18:41:19 +01:00
|
|
|
500: response.status['500'],
|
2022-12-19 11:36:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|