fleet/website/api/helpers/create-license-key.js
Eric 112dffbd1e
Website: Update license key generator action and helper inputs (#9265)
Changes:
- Updated the `expiresAt` input description in
`api/controllers/admin/generate-license-key.js` and
`api/helpers/create-license-key.js`
- Updated timestamps sent to `generate-license-key` and
`create-license-key` to be in seconds.

 . .

Co-authored-by: Mike McNeil <[email protected]>
2023-01-11 11:11:43 -06:00

68 lines
1.1 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Create license key',
description: '',
inputs: {
numberOfHosts: {
type: 'number',
required: true,
},
organization: {
type: 'string',
required: true,
},
expiresAt: {
type: 'number',
required: true,
description: 'A JS timestamp representing when this license will expire.'
}
},
exits: {
success: {
outputType: 'string',
},
},
fn: async function ({numberOfHosts, organization, expiresAt}) {
let jwt = require('jsonwebtoken');
let expirationTimestampInSeconds = (expiresAt / 1000);
let token = jwt.sign(
{
iss: 'Fleet Device Management Inc.',
exp: expirationTimestampInSeconds,
sub: organization,
devices: numberOfHosts,
note: 'Created with Fleet License key dispenser',
tier: 'premium',
},
{
key: sails.config.custom.licenseKeyGeneratorPrivateKey,
passphrase: sails.config.custom.licenseKeyGeneratorPassphrase
},
{ algorithm: 'ES256' }
);
return token;
}
};