-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathimport.ts
59 lines (47 loc) · 1.66 KB
/
import.ts
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
import nconf from 'nconf';
import { configFactory } from '../configFactory';
import { setupProxy } from '../utils';
import { deploy as toolsDeploy } from '../tools';
import log from '../logger';
import { setupContext } from '../context';
import { ImportParams } from '../args';
export default async function importCMD(params: ImportParams) {
const {
input_file: inputFile,
base_path: basePath,
config_file: configFile,
config: configObj,
env: shouldInheritEnv = false,
secret: clientSecret,
proxy_url: proxyUrl,
} = params;
if (shouldInheritEnv) {
nconf.env().use('memory');
const mappings = nconf.get('AUTH0_KEYWORD_REPLACE_MAPPINGS') || {};
nconf.set('AUTH0_KEYWORD_REPLACE_MAPPINGS', Object.assign(mappings, process.env));
}
if (configFile) {
nconf.file(configFile);
}
const overrides = {
AUTH0_INPUT_FILE: inputFile,
AUTH0_BASE_PATH: basePath,
AUTH0_KEYWORD_REPLACE_MAPPINGS: {},
...(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;
}
nconf.overrides(overrides);
setupProxy(proxyUrl);
// Setup context and load
const context = await setupContext(nconf.get(), 'import');
await context.loadAssetsFromLocal();
const config = configFactory();
config.setProvider((key) => nconf.get(key));
//@ts-ignore because context and assets still need to be typed TODO: type assets and type context
await toolsDeploy(context.assets, context.mgmtClient, config);
log.info('Import Successful');
}