All files / src/commands export.ts

26.92% Statements 7/26
0% Branches 0/15
0% Functions 0/1
26.92% Lines 7/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x 1x   1x 1x 1x       1x                                                                                                          
import path from 'path';
import nconf from 'nconf';
import mkdirp from 'mkdirp';
 
import log from '../logger';
import { isDirectory } from '../utils';
import { setupContext } from '../context/index';
import { Config } from '../types';
import { ExportParams } from '../args';
 
export default async function exportCMD(params: ExportParams) {
  const {
    output_folder: outputFolder,
    base_path: basePath,
    config_file: configFile,
    config: configObj,
    export_ids: exportIds,
    secret: clientSecret,
    env: shouldInheritEnv = false,
  } = params;
 
  if (shouldInheritEnv) {
    nconf.env().use('memory');
  }
 
  if (configFile) {
    nconf.file(configFile);
  }
 
  const overrides: Partial<Config> = {
    AUTH0_INPUT_FILE: outputFolder,
    AUTH0_BASE_PATH: basePath,
    ...(configObj || {}),
  };
 
  // Prepare configuration by initializing nconf, then passing that as the provider to the config object
  // Allow passed in secret to override the configured one
  if (clientSecret) {
    overrides.AUTH0_CLIENT_SECRET = clientSecret;
  }
 
  // Allow passed in export_ids to override the configured one
  if (exportIds) {
    overrides.AUTH0_EXPORT_IDENTIFIERS = exportIds;
  }
 
  // Check output folder
  if (!isDirectory(outputFolder)) {
    log.info(`Creating ${outputFolder}`);
    mkdirp.sync(outputFolder);
  }
 
  if (params.format === 'yaml') {
    overrides.AUTH0_INPUT_FILE = path.join(outputFolder, 'tenant.yaml');
  }
 
  nconf.overrides(overrides);
 
  // Setup context and load
  const context = await setupContext(nconf.get(), 'export');
  await context.dump();
  log.info('Export Successful');
}