import { red, yellow } from 'chalk'; import { CommandModule } from 'yargs'; import { synchronizePermissions, validateArgs } from './sync-permissions'; import { GetSyncPermissionsOptions } from './sync-permissions-options'; export const syncPermissionsCommand: CommandModule< unknown, GetSyncPermissionsOptions > = { builder: (yargs) => { return yargs .option('serviceId', { describe: 'Service ID the permissions should be synchronized to. If no value is explicity given, environment variable SERVICE_ID will be used.', alias: 'i', string: true, }) .option('idServiceAuthBaseURL', { describe: 'ID Service Authentication Endpoint Base URL. If no value is explicity given, environment variable ID_SERVICE_AUTH_BASE_URL will be used.', alias: 'a', string: true, }) .option('permissionDefinitionJsonPath', { describe: 'Path to permission-definition.json file. The default location is src/generated/security/permission-definition.json', alias: 'p', string: true, }) .option('clientId', { describe: 'Client ID of a Service Account which has Synchronize Permission permission assigned. If no value is explicity given, environment variable SERVICE_ACCOUNT_CLIENT_ID will be used.', alias: 'c', string: true, }) .option('clientSecret', { describe: 'Client Secret for the above Client ID. If no value is explicity given, environment variable SERVICE_ACCOUNT_CLIENT_SECRET will be used.', alias: 's', string: true, }); }, handler: async (args) => { const [validatedArgs, errorMessages] = validateArgs(args); if (errorMessages.length > 0) { console.log( red('Some required arguments are missing and/or are erroneous.'), ); errorMessages.map((message) => { console.log(yellow(`${message}`)); }); console.log(); } else { await synchronizePermissions(validatedArgs); } }, };