@rockcarver/frodo-cli 2.0.0-4 → 2.0.0-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -1
- package/esm/app.js +2 -2
- package/esm/app.js.map +1 -1
- package/esm/cli/admin/admin-federation-export.js +42 -0
- package/esm/cli/admin/admin-federation-export.js.map +1 -0
- package/esm/cli/admin/admin-federation-import.js +46 -0
- package/esm/cli/admin/admin-federation-import.js.map +1 -0
- package/esm/cli/admin/admin-federation-list.js +26 -0
- package/esm/cli/admin/admin-federation-list.js.map +1 -0
- package/esm/cli/admin/admin-federation.js +13 -0
- package/esm/cli/admin/admin-federation.js.map +1 -0
- package/esm/cli/admin/admin.js +1 -0
- package/esm/cli/admin/admin.js.map +1 -1
- package/esm/cli/conn/conn-save.js +6 -3
- package/esm/cli/conn/conn-save.js.map +1 -1
- package/esm/cli/info/info.js +2 -3
- package/esm/cli/info/info.js.map +1 -1
- package/esm/cli/{logging/logs-fetch.js → log/log-fetch.js} +3 -3
- package/esm/cli/log/log-fetch.js.map +1 -0
- package/esm/cli/log/log-key-delete.js +32 -0
- package/esm/cli/log/log-key-delete.js.map +1 -0
- package/esm/cli/log/log-key-describe.js +19 -0
- package/esm/cli/log/log-key-describe.js.map +1 -0
- package/esm/cli/log/log-key-list.js +23 -0
- package/esm/cli/log/log-key-list.js.map +1 -0
- package/esm/cli/log/log-key.js +8 -0
- package/esm/cli/log/log-key.js.map +1 -0
- package/esm/cli/{logging/logs-list.js → log/log-list.js} +2 -2
- package/esm/cli/log/log-list.js.map +1 -0
- package/esm/cli/{logging/logs-tail.js → log/log-tail.js} +3 -3
- package/esm/cli/log/log-tail.js.map +1 -0
- package/esm/cli/{logging/logs.js → log/log.js} +5 -2
- package/esm/cli/log/log.js.map +1 -0
- package/esm/help/SampleData.js +7 -0
- package/esm/help/SampleData.js.map +1 -0
- package/esm/ops/AdminFederationOps.js +208 -0
- package/esm/ops/AdminFederationOps.js.map +1 -0
- package/esm/ops/IdpOps.js +22 -10
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/LogOps.js +77 -25
- package/esm/ops/LogOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +1 -1
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/RealmOps.js +6 -4
- package/esm/ops/RealmOps.js.map +1 -1
- package/package.json +2 -2
- package/esm/cli/logging/logs-fetch.js.map +0 -1
- package/esm/cli/logging/logs-list.js.map +0 -1
- package/esm/cli/logging/logs-tail.js.map +0 -1
- package/esm/cli/logging/logs.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FrodoCommand } from '../FrodoCommand';
|
|
2
|
+
import { Option } from 'commander';
|
|
3
|
+
import { frodo } from '@rockcarver/frodo-lib';
|
|
4
|
+
import { listLogApiKeys } from '../../ops/LogOps';
|
|
5
|
+
import { verboseMessage } from '../../utils/Console';
|
|
6
|
+
const program = new FrodoCommand('frodo log key list');
|
|
7
|
+
program.description('List log API keys.').addOption(new Option('-l, --long', 'Long with all fields.').default(false, 'false')).action(
|
|
8
|
+
// implement command logic inside action handler
|
|
9
|
+
async (host, realm, user, password, options, command) => {
|
|
10
|
+
command.handleDefaultArgsAndOpts(host, realm, user, password, options, command);
|
|
11
|
+
if (await frodo.login.getTokens(true)) {
|
|
12
|
+
verboseMessage(`Listing log API keys...`);
|
|
13
|
+
const outcome = await listLogApiKeys(options.long);
|
|
14
|
+
if (!outcome) process.exitCode = 1;
|
|
15
|
+
} else {
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// end command logic inside action handler
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
program.parse();
|
|
23
|
+
//# sourceMappingURL=log-key-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-key-list.js","names":["FrodoCommand","Option","frodo","listLogApiKeys","verboseMessage","program","description","addOption","default","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","login","getTokens","outcome","long","process","exitCode","parse"],"sources":["cli/log/log-key-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport { frodo } from '@rockcarver/frodo-lib';\nimport { listLogApiKeys } from '../../ops/LogOps';\nimport { verboseMessage } from '../../utils/Console';\n\nconst program = new FrodoCommand('frodo log key list');\n\nprogram\n .description('List log API keys.')\n .addOption(\n new Option('-l, --long', 'Long with all fields.').default(false, 'false')\n )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n if (await frodo.login.getTokens(true)) {\n verboseMessage(`Listing log API keys...`);\n const outcome = await listLogApiKeys(options.long);\n if (!outcome) process.exitCode = 1;\n } else {\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,KAAK,QAAQ,uBAAuB;AAC7C,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,cAAc,QAAQ,qBAAqB;AAEpD,MAAMC,OAAO,GAAG,IAAIL,YAAY,CAAC,oBAAoB,CAAC;AAEtDK,OAAO,CACJC,WAAW,CAAC,oBAAoB,CAAC,CACjCC,SAAS,CACR,IAAIN,MAAM,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAACO,OAAO,CAAC,KAAK,EAAE,OAAO,CAC1E,CAAC,CACAC,MAAM;AACL;AACA,OAAOC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,KAAK;EACvDA,OAAO,CAACC,wBAAwB,CAC9BN,IAAI,EACJC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,OACF,CAAC;EACD,IAAI,MAAMb,KAAK,CAACe,KAAK,CAACC,SAAS,CAAC,IAAI,CAAC,EAAE;IACrCd,cAAc,CAAE,yBAAwB,CAAC;IACzC,MAAMe,OAAO,GAAG,MAAMhB,cAAc,CAACW,OAAO,CAACM,IAAI,CAAC;IAClD,IAAI,CAACD,OAAO,EAAEE,OAAO,CAACC,QAAQ,GAAG,CAAC;EACpC,CAAC,MAAM;IACLD,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AACF,CAAC;;AAEHjB,OAAO,CAACkB,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FrodoStubCommand } from '../FrodoCommand';
|
|
2
|
+
const program = new FrodoStubCommand('frodo log key');
|
|
3
|
+
program.description('Manage Identity Cloud log API keys.');
|
|
4
|
+
program.command('list', 'List log API keys.');
|
|
5
|
+
program.command('describe', 'Describe log API keys.');
|
|
6
|
+
program.command('delete', 'Delete log API keys.');
|
|
7
|
+
program.parse();
|
|
8
|
+
//# sourceMappingURL=log-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-key.js","names":["FrodoStubCommand","program","description","command","parse"],"sources":["cli/log/log-key.ts"],"sourcesContent":["import { FrodoStubCommand } from '../FrodoCommand';\n\nconst program = new FrodoStubCommand('frodo log key');\n\nprogram.description('Manage Identity Cloud log API keys.');\n\nprogram.command('list', 'List log API keys.');\n\nprogram.command('describe', 'Describe log API keys.');\n\nprogram.command('delete', 'Delete log API keys.');\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,iBAAiB;AAElD,MAAMC,OAAO,GAAG,IAAID,gBAAgB,CAAC,eAAe,CAAC;AAErDC,OAAO,CAACC,WAAW,CAAC,qCAAqC,CAAC;AAE1DD,OAAO,CAACE,OAAO,CAAC,MAAM,EAAE,oBAAoB,CAAC;AAE7CF,OAAO,CAACE,OAAO,CAAC,UAAU,EAAE,wBAAwB,CAAC;AAErDF,OAAO,CAACE,OAAO,CAAC,QAAQ,EAAE,sBAAsB,CAAC;AAEjDF,OAAO,CAACG,KAAK,CAAC,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { FrodoCommand } from '../FrodoCommand';
|
|
|
2
2
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
3
3
|
import { printMessage, verboseMessage } from '../../utils/Console';
|
|
4
4
|
import { provisionCreds } from '../../ops/LogOps';
|
|
5
|
-
const program = new FrodoCommand('frodo
|
|
5
|
+
const program = new FrodoCommand('frodo log list', ['realm', 'type']);
|
|
6
6
|
program.description('List available ID Cloud log sources.').action(async (host, user, password, options, command) => {
|
|
7
7
|
command.handleDefaultArgsAndOpts(host, user, password, options, command);
|
|
8
8
|
let credsFromParameters = true;
|
|
@@ -46,4 +46,4 @@ program.description('List available ID Cloud log sources.').action(async (host,
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
program.parse();
|
|
49
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=log-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-list.js","names":["FrodoCommand","frodo","state","printMessage","verboseMessage","provisionCreds","program","description","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","getConnectionProfile","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","login","getTokens","creds","api_key_id","api_key_secret","sources","cloud","log","getLogSources","length","saveConnectionProfile","forEach","source","parse"],"sources":["cli/log/log-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { frodo, state } from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport { provisionCreds } from '../../ops/LogOps';\n\nconst program = new FrodoCommand('frodo log list', ['realm', 'type']);\nprogram\n .description('List available ID Cloud log sources.')\n .action(async (host, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(host, user, password, options, command);\n let credsFromParameters = true;\n verboseMessage('Listing available ID Cloud log sources...');\n const conn = await frodo.conn.getConnectionProfile();\n if (conn) {\n state.setHost(conn.tenant);\n if (conn.logApiKey != null && conn.logApiSecret != null) {\n credsFromParameters = false;\n state.setLogApiKey(conn.logApiKey);\n state.setLogApiSecret(conn.logApiSecret);\n } else {\n if (conn.username == null && conn.password == null) {\n if (!state.getUsername() && !state.getPassword()) {\n credsFromParameters = false;\n printMessage(\n 'User credentials not specified as parameters and no saved API key and secret found!',\n 'warn'\n );\n return;\n }\n } else {\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n }\n if (await frodo.login.getTokens(true)) {\n const creds = await provisionCreds();\n state.setLogApiKey(creds.api_key_id as string);\n state.setLogApiSecret(creds.api_key_secret as string);\n }\n }\n\n const sources = await frodo.cloud.log.getLogSources();\n if (sources.length === 0) {\n printMessage(\n \"Can't get sources, possible cause - wrong API key or secret\",\n 'error'\n );\n } else {\n if (credsFromParameters) await frodo.conn.saveConnectionProfile(host); // save new values if they were specified on CLI\n printMessage(`Log sources from ${conn.tenant}`);\n sources.forEach((source) => {\n printMessage(`${source}`, 'data');\n });\n printMessage(\n 'Use any combination of comma separated sources, example:',\n 'info'\n );\n printMessage(`$ frodo logs tail -c am-core,idm-core ${host}`, 'text');\n }\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,MAAMC,OAAO,GAAG,IAAIN,YAAY,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrEM,OAAO,CACJC,WAAW,CAAC,sCAAsC,CAAC,CACnDC,MAAM,CAAC,OAAOC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,KAAK;EACxDA,OAAO,CAACC,wBAAwB,CAACL,IA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AAG,MAAMjC,KAAK,CAACkC,KAAK,CAACC,GAAG,CAACC,aAAa,CAAC,CAAC;IACrD,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACxBnC,YAAY,CACV,6DAA6D,EAC7D,OACF,CAAC;IACH,CAAC,MAAM;MACL,IAAIY,mBAAmB,EAAE,MAAMd,KAAK,CAACe,IAAI,CAACuB,qBAAqB,CAAC9B,IAAI,CAAC,CAAC,CAAC;MACvEN,YAAY,CAAE,oBAAmBa,IAAI,CAACG,MAAO,EAAC,CAAC;MAC/Ce,OAAO,CAACM,OAAO,CAAEC,MAAM,IAAK;QAC1BtC,YAAY,CAAE,GAAEsC,MAAO,EAAC,EAAE,MAAM,CAAC;MACnC,CAAC,CAAC;MACFtC,YAAY,CACV,0DAA0D,EAC1D,MACF,CAAC;MACDA,YAAY,CAAE,yCAAwCM,IAAK,EAAC,EAAE,MAAM,CAAC;IACvE;EACF;AACF,CAAC,CAAC;AAEJH,OAAO,CAACoC,KAAK,CAAC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FrodoCommand } from '../FrodoCommand';
|
|
2
|
-
import { sourcesOptionM } from './
|
|
2
|
+
import { sourcesOptionM } from './log';
|
|
3
3
|
import { Option } from 'commander';
|
|
4
4
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
5
5
|
import * as config from '../../utils/Config';
|
|
6
6
|
import { printMessage } from '../../utils/Console';
|
|
7
7
|
import { provisionCreds, tailLogs } from '../../ops/LogOps';
|
|
8
|
-
const program = new FrodoCommand('frodo
|
|
8
|
+
const program = new FrodoCommand('frodo log tail', ['realm', 'type']);
|
|
9
9
|
program.description('Tail Identity Cloud logs.').addOption(sourcesOptionM).addOption(new Option('-l, --level <level>', 'Set log level filter. You can specify the level as a number or a string. \
|
|
10
10
|
Following values are possible (values on the same line are equivalent): \
|
|
11
11
|
\n0, SEVERE, FATAL, or ERROR\n1, WARNING, WARN or CONFIG\
|
|
@@ -43,4 +43,4 @@ Following values are possible (values on the same line are equivalent): \
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
program.parse();
|
|
46
|
-
//# sourceMappingURL=
|
|
46
|
+
//# sourceMappingURL=log-tail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-tail.js","names":["FrodoCommand","sourcesOptionM","Option","frodo","state","config","printMessage","provisionCreds","tailLogs","program","description","addOption","default","cloud","log","resolveLevel","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","getConnectionProfile","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","login","getTokens","creds","api_key_id","api_key_secret","opts","sources","level","saveConnectionProfile","transactionId","getNoiseFilters","defaults","parse"],"sources":["cli/log/log-tail.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './log';\nimport { Option } from 'commander';\nimport { frodo, state } from '@rockcarver/frodo-lib';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\nimport { provisionCreds, tailLogs } from '../../ops/LogOps';\n\nconst program = new FrodoCommand('frodo log tail', ['realm', 'type']);\nprogram\n .description('Tail Identity Cloud logs.')\n .addOption(sourcesOptionM)\n .addOption(\n new Option(\n '-l, --level <level>',\n 'Set log level filter. You can specify the level as a number or a string. \\\nFollowing values are possible (values on the same line are equivalent): \\\n\\n0, SEVERE, FATAL, or ERROR\\n1, WARNING, WARN or CONFIG\\\n\\n2, INFO or INFORMATION\\n3, DEBUG, FINE, FINER or FINEST\\\n\\n4 or ALL'\n ).default('ERROR', `${frodo.cloud.log.resolveLevel('ERROR')}`)\n )\n .addOption(\n new Option('-t, --transaction-id <txid>', 'Filter by transactionId')\n )\n .addOption(\n new Option('-d, --defaults', 'Use default logging noise filters').default(\n false,\n `Use custom logging noise filters defined in $HOME/${config.FRODO_LOG_NOISEFILTER_FILENAME}`\n )\n )\n .action(async (host, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(host, user, password, options, command);\n let credsFromParameters = true;\n const conn = await frodo.conn.getConnectionProfile();\n if (conn) {\n state.setHost(conn.tenant);\n if (conn.logApiKey != null && conn.logApiSecret != null) {\n credsFromParameters = false;\n state.setLogApiKey(conn.logApiKey);\n state.setLogApiSecret(conn.logApiSecret);\n } else {\n if (conn.username == null && conn.password == null) {\n if (!state.getUsername() && !state.getPassword()) {\n credsFromParameters = false;\n printMessage(\n 'User credentials not specified as parameters and no saved API key and secret found!',\n 'warn'\n );\n return;\n }\n } else {\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n }\n if (await frodo.login.getTokens(true)) {\n const creds = await provisionCreds();\n state.setLogApiKey(creds.api_key_id as string);\n state.setLogApiSecret(creds.api_key_secret as string);\n }\n }\n printMessage(\n `Tailing ID Cloud logs from the following sources: ${\n command.opts().sources\n } and levels [${frodo.cloud.log.resolveLevel(\n command.opts().level\n )}] of ${conn.tenant}...`\n );\n if (credsFromParameters) await frodo.conn.saveConnectionProfile(host); // save new values if they were specified on CLI\n await tailLogs(\n command.opts().sources,\n frodo.cloud.log.resolveLevel(command.opts().level),\n command.opts().transactionId,\n null,\n config.getNoiseFilters(options.defaults)\n );\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,OAAO;AACtC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAC5C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,cAAc,EAAEC,QAAQ,QAAQ,kBAAkB;AAE3D,MAAMC,OAAO,GAAG,IAAIT,YAAY,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrES,OAAO,CACJC,WAAW,CAAC,2BAA2B,CAAC,CACxCC,SA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 @@ import { fileURLToPath } from 'url';
|
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
export const sourcesOptionM = new Option('-c, --sources <sources>', 'Comma separated list of log sources').makeOptionMandatory().default('am-everything,idm-everything', 'Log everything');
|
|
7
7
|
export default function setup() {
|
|
8
|
-
const program = new FrodoStubCommand('
|
|
8
|
+
const program = new FrodoStubCommand('log')
|
|
9
|
+
// for backwards compatibility
|
|
10
|
+
.alias('logs').summary('List/View Identity Cloud logs').description(`View Identity Cloud logs. If valid tenant admin credentials are specified, a log API key and secret are automatically created for that admin user.`).executableDir(__dirname);
|
|
9
11
|
program.command('list', 'List available ID Cloud log sources.');
|
|
10
12
|
program.command('tail', 'Tail Identity Cloud logs.');
|
|
11
13
|
program.command('fetch', 'Fetch Identity Cloud logs for a time window.');
|
|
14
|
+
program.command('key', 'Manage Identity Cloud log API keys.');
|
|
12
15
|
return program;
|
|
13
16
|
}
|
|
14
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","names":["FrodoStubCommand","Option","path","fileURLToPath","__dirname","dirname","import","meta","url","sourcesOptionM","makeOptionMandatory","default","setup","program","alias","summary","description","executableDir","command"],"sources":["cli/log/log.ts"],"sourcesContent":["import { FrodoStubCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport const sourcesOptionM = new Option(\n '-c, --sources <sources>',\n 'Comma separated list of log sources'\n)\n .makeOptionMandatory()\n .default('am-everything,idm-everything', 'Log everything');\n\nexport default function setup() {\n const program = new FrodoStubCommand('log')\n // for backwards compatibility\n .alias('logs')\n .summary('List/View Identity Cloud logs')\n .description(\n `View Identity Cloud logs. If valid tenant admin credentials are specified, a log API key and secret are automatically created for that admin user.`\n )\n .executableDir(__dirname);\n\n program.command('list', 'List available ID Cloud log sources.');\n\n program.command('tail', 'Tail Identity Cloud logs.');\n\n program.command('fetch', 'Fetch Identity Cloud logs for a time window.');\n\n program.command('key', 'Manage Identity Cloud log API keys.');\n\n return program;\n}\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,MAAM,QAAQ,WAAW;AAClC,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AAEnC,MAAMC,SAAS,GAAGF,IAAI,CAACG,OAAO,CAACF,aAAa,CAACG,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAE9D,OAAO,MAAMC,cAAc,GAAG,IAAIR,MAAM,CACtC,yBAAyB,EACzB,qCACF,CAAC,CACES,mBAAmB,CAAC,CAAC,CACrBC,OAAO,CAAC,8BAA8B,EAAE,gBAAgB,CAAC;AAE5D,eAAe,SAASC,KAAKA,CAAA,EAAG;EAC9B,MAAMC,OAAO,GAAG,IAAIb,gBAAgB,CAAC,KAAK;EACxC;EAAA,CACCc,KAAK,CAAC,MAAM,CAAC,CACbC,OAAO,CAAC,+BAA+B,CAAC,CACxCC,WAAW,CACT,oJACH,CAAC,CACAC,aAAa,CAACb,SAAS,CAAC;EAE3BS,OAAO,CAACK,OAAO,CAAC,MAAM,EAAE,sCAAsC,CAAC;EAE/DL,OAAO,CAACK,OAAO,CAAC,MAAM,EAAE,2BAA2B,CAAC;EAEpDL,OAAO,CAACK,OAAO,CAAC,OAAO,EAAE,8CAA8C,CAAC;EAExEL,OAAO,CAACK,OAAO,CAAC,KAAK,EAAE,qCAAqC,CAAC;EAE7D,OAAOL,OAAO;AAChB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const amBaseUrl = 'https://openam-matrix.id.forgerock.io/am';
|
|
2
|
+
export const connId = 'matrix';
|
|
3
|
+
export const username = 'thomas.anderson@metacortex.com';
|
|
4
|
+
export const password = 'Blu3P!ll3d';
|
|
5
|
+
export const saId = 'b672336b-41ef-428d-ae4a-e0c082875377';
|
|
6
|
+
export const saJwkFile = './matrix-sa_privateKey.jwk';
|
|
7
|
+
//# sourceMappingURL=SampleData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SampleData.js","names":["amBaseUrl","connId","username","password","saId","saJwkFile"],"sources":["help/SampleData.ts"],"sourcesContent":["export const amBaseUrl = 'https://openam-matrix.id.forgerock.io/am';\nexport const connId = 'matrix';\nexport const username = 'thomas.anderson@metacortex.com';\nexport const password = 'Blu3P!ll3d';\nexport const saId = 'b672336b-41ef-428d-ae4a-e0c082875377';\nexport const saJwkFile = './matrix-sa_privateKey.jwk';\n"],"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG,0CAA0C;AACnE,OAAO,MAAMC,MAAM,GAAG,QAAQ;AAC9B,OAAO,MAAMC,QAAQ,GAAG,gCAAgC;AACxD,OAAO,MAAMC,QAAQ,GAAG,YAAY;AACpC,OAAO,MAAMC,IAAI,GAAG,sCAAsC;AAC1D,OAAO,MAAMC,SAAS,GAAG,4BAA4B"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { createProgressBar, debugMessage, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
|
|
4
|
+
import { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* List providers
|
|
8
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export async function listAdminFederationProviders() {
|
|
11
|
+
let outcome = false;
|
|
12
|
+
try {
|
|
13
|
+
const providers = await frodo.cloud.adminFed.getAdminFederationProviders();
|
|
14
|
+
providers.sort((a, b) => a._id.localeCompare(b._id));
|
|
15
|
+
providers.forEach(socialIdentityProvider => {
|
|
16
|
+
printMessage(`${socialIdentityProvider._id}`, 'data');
|
|
17
|
+
});
|
|
18
|
+
outcome = true;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
printMessage(`listAdminFederationProviders ERROR: ${err.message}`, 'error');
|
|
21
|
+
printMessage(err, 'error');
|
|
22
|
+
}
|
|
23
|
+
return outcome;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Export provider by id
|
|
28
|
+
* @param {string} providerId provider id/name
|
|
29
|
+
* @param {string} file optional export file name
|
|
30
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
export async function exportAdminFederationProviderToFile(providerId, file = '') {
|
|
33
|
+
let outcome = false;
|
|
34
|
+
let fileName = file;
|
|
35
|
+
if (!fileName) {
|
|
36
|
+
fileName = getTypedFilename(providerId, 'admin.federation');
|
|
37
|
+
}
|
|
38
|
+
createProgressBar(1, `Exporting ${providerId}`);
|
|
39
|
+
try {
|
|
40
|
+
updateProgressBar(`Writing file ${fileName}`);
|
|
41
|
+
const fileData = await frodo.cloud.adminFed.exportAdminFederationProvider(providerId);
|
|
42
|
+
saveJsonToFile(fileData, fileName);
|
|
43
|
+
stopProgressBar(`Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`);
|
|
44
|
+
outcome = true;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
stopProgressBar(`${err}`);
|
|
47
|
+
printMessage(`${err}`, 'error');
|
|
48
|
+
}
|
|
49
|
+
return outcome;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Export all providers
|
|
54
|
+
* @param {string} file optional export file name
|
|
55
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
export async function exportAdminFederationProvidersToFile(file = '') {
|
|
58
|
+
let outcome = false;
|
|
59
|
+
showSpinner(`Exporting all providers...`);
|
|
60
|
+
try {
|
|
61
|
+
let fileName = file;
|
|
62
|
+
if (!fileName) {
|
|
63
|
+
fileName = getTypedFilename(`allProviders`, 'admin.federation');
|
|
64
|
+
}
|
|
65
|
+
const fileData = await frodo.cloud.adminFed.exportAdminFederationProviders();
|
|
66
|
+
saveJsonToFile(fileData, fileName);
|
|
67
|
+
succeedSpinner(`Exported all providers to ${fileName}`);
|
|
68
|
+
outcome = true;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
var _error$response;
|
|
71
|
+
failSpinner(`Error exporting all providers.`);
|
|
72
|
+
printMessage(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error, 'error');
|
|
73
|
+
}
|
|
74
|
+
return outcome;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Export all providers to individual files
|
|
79
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
export async function exportAdminFederationProvidersToFiles() {
|
|
82
|
+
let outcome = false;
|
|
83
|
+
try {
|
|
84
|
+
const allIdpsData = await frodo.cloud.adminFed.getAdminFederationProviders();
|
|
85
|
+
createProgressBar(allIdpsData.length, 'Exporting providers');
|
|
86
|
+
for (const idpData of allIdpsData) {
|
|
87
|
+
updateProgressBar(`Writing provider ${idpData._id}`);
|
|
88
|
+
const fileName = getTypedFilename(idpData._id, 'admin.federation');
|
|
89
|
+
const fileData = await frodo.cloud.adminFed.exportAdminFederationProvider(idpData._id);
|
|
90
|
+
saveJsonToFile(fileData, fileName);
|
|
91
|
+
}
|
|
92
|
+
stopProgressBar(`${allIdpsData.length} providers exported.`);
|
|
93
|
+
outcome = true;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
var _error$response2;
|
|
96
|
+
failSpinner(`Error exporting all providers.`);
|
|
97
|
+
printMessage(((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error, 'error');
|
|
98
|
+
}
|
|
99
|
+
return outcome;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Import provider by id/name
|
|
104
|
+
* @param {string} providerId provider id/name
|
|
105
|
+
* @param {string} file import file name
|
|
106
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
107
|
+
*/
|
|
108
|
+
export async function importAdminFederationProviderFromFile(providerId, file) {
|
|
109
|
+
let outcome = false;
|
|
110
|
+
showSpinner(`Importing provider ${providerId} from ${file}...`);
|
|
111
|
+
try {
|
|
112
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
113
|
+
const fileData = JSON.parse(data);
|
|
114
|
+
await frodo.cloud.adminFed.importAdminFederationProvider(providerId, fileData);
|
|
115
|
+
succeedSpinner(`Successfully imported provider ${providerId} from ${file}.`);
|
|
116
|
+
outcome = true;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
var _error$response3;
|
|
119
|
+
failSpinner(`Error importing provider ${providerId} from ${file}.`);
|
|
120
|
+
printMessage(((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data) || error, 'error');
|
|
121
|
+
}
|
|
122
|
+
return outcome;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Import first provider from file
|
|
127
|
+
* @param {String} file import file name
|
|
128
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
129
|
+
*/
|
|
130
|
+
export async function importFirstAdminFederationProviderFromFile(file) {
|
|
131
|
+
let outcome = false;
|
|
132
|
+
debugMessage(`cli.AdminFederationOps.importFirstAdminFederationProviderFromFile: begin`);
|
|
133
|
+
showSpinner(`Importing first provider from ${file}...`);
|
|
134
|
+
try {
|
|
135
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
136
|
+
const fileData = JSON.parse(data);
|
|
137
|
+
await frodo.cloud.adminFed.importFirstAdminFederationProvider(fileData);
|
|
138
|
+
succeedSpinner(`Successfully imported first provider from ${file}.`);
|
|
139
|
+
outcome = true;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
var _error$response4;
|
|
142
|
+
failSpinner(`Error importing first provider from ${file}.`);
|
|
143
|
+
printMessage(((_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.data) || error, 'error');
|
|
144
|
+
}
|
|
145
|
+
debugMessage(`cli.AdminFederationOps.importFirstAdminFederationProviderFromFile: end`);
|
|
146
|
+
return outcome;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Import all providers from file
|
|
151
|
+
* @param {string} file import file name
|
|
152
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
153
|
+
*/
|
|
154
|
+
export async function importAdminFederationProvidersFromFile(file) {
|
|
155
|
+
let outcome = false;
|
|
156
|
+
debugMessage(`cli.AdminFederationOps.importAdminFederationProvidersFromFile: begin`);
|
|
157
|
+
showSpinner(`Importing providers from ${file}...`);
|
|
158
|
+
try {
|
|
159
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
160
|
+
const fileData = JSON.parse(data);
|
|
161
|
+
await frodo.cloud.adminFed.importAdminFederationProviders(fileData);
|
|
162
|
+
succeedSpinner(`Imported providers from ${file}.`);
|
|
163
|
+
outcome = true;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
var _error$response5;
|
|
166
|
+
failSpinner(`Error importing ${file}.`);
|
|
167
|
+
printMessage(((_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : _error$response5.data) || error, 'error');
|
|
168
|
+
}
|
|
169
|
+
debugMessage(`cli.AdminFederationOps.importAdminFederationProvidersFromFile: end`);
|
|
170
|
+
return outcome;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Import providers from *.idp.json files in current working directory
|
|
175
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
176
|
+
*/
|
|
177
|
+
export async function importAdminFederationProvidersFromFiles() {
|
|
178
|
+
const errors = [];
|
|
179
|
+
try {
|
|
180
|
+
debugMessage(`cli.AdminFederationOps.importAdminFederationProvidersFromFiles: begin`);
|
|
181
|
+
const names = fs.readdirSync('.');
|
|
182
|
+
const files = names.filter(name => name.toLowerCase().endsWith('.admin.federation.json'));
|
|
183
|
+
createProgressBar(files.length, 'Importing providers...');
|
|
184
|
+
let total = 0;
|
|
185
|
+
for (const file of files) {
|
|
186
|
+
try {
|
|
187
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
188
|
+
const fileData = JSON.parse(data);
|
|
189
|
+
const count = Object.keys(fileData.idp).length;
|
|
190
|
+
total += count;
|
|
191
|
+
await frodo.cloud.adminFed.importAdminFederationProviders(fileData);
|
|
192
|
+
updateProgressBar(`Imported ${count} provider(s) from ${file}`);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
errors.push(error);
|
|
195
|
+
updateProgressBar(`Error importing provider(s) from ${file}`);
|
|
196
|
+
printMessage(error, 'error');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
stopProgressBar(`Finished importing ${total} provider(s) from ${files.length} file(s).`);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
errors.push(error);
|
|
202
|
+
stopProgressBar(`Error importing provider(s) from file(s).`);
|
|
203
|
+
printMessage(error, 'error');
|
|
204
|
+
}
|
|
205
|
+
debugMessage(`cli.AdminFederationOps.importAdminFederationProvidersFromFiles: end`);
|
|
206
|
+
return 0 === errors.length;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=AdminFederationOps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdminFederationOps.js","names":["frodo","fs","createProgressBar","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getTypedFilename","saveJsonToFile","listAdminFederationProviders","outcome","providers","cloud","adminFed","getAdminFederationProviders","sort","a","b","_id","localeCompare","forEach","socialIdentityProvider","err","message","exportAdminFederationProviderToFile","providerId","file","fileName","fileData","exportAdminFederationProvider","exportAdminFederationProvidersToFile","exportAdminFederationProviders","error","_error$response","response","data","exportAdminFederationProvidersToFiles","allIdpsData","length","idpData","_error$response2","importAdminFederationProviderFromFile","readFileSync","JSON","parse","importAdminFederationProvider","_error$response3","importFirstAdminFederationProviderFromFile","importFirstAdminFederationProvider","_error$response4","importAdminFederationProvidersFromFile","importAdminFederationProviders","_error$response5","importAdminFederationProvidersFromFiles","errors","names","readdirSync","files","filter","name","toLowerCase","endsWith","total","count","Object","keys","idp","push"],"sources":["ops/AdminFederationOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport {\n createProgressBar,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\n\n/**\n * List providers\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listAdminFederationProviders(): Promise<boolean> {\n let outcome = false;\n try {\n const providers = await frodo.cloud.adminFed.getAdminFederationProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n outcome = true;\n } catch (err) {\n printMessage(`listAdminFederationProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportAdminFederationProviderToFile(\n providerId: string,\n file = ''\n): Promise<boolean> {\n let outcome = false;\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'admin.federation');\n }\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${fileName}`);\n const fileData = await frodo.cloud.adminFed.exportAdminFederationProvider(\n providerId\n );\n saveJsonToFile(fileData, fileName);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n outcome = true;\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n return outcome;\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportAdminFederationProvidersToFile(\n file = ''\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Exporting all providers...`);\n try {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allProviders`, 'admin.federation');\n }\n const fileData =\n await frodo.cloud.adminFed.exportAdminFederationProviders();\n saveJsonToFile(fileData, fileName);\n succeedSpinner(`Exported all providers to ${fileName}`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting all providers.`);\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Export all providers to individual files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportAdminFederationProvidersToFiles(): Promise<boolean> {\n let outcome = false;\n try {\n const allIdpsData =\n await frodo.cloud.adminFed.getAdminFederationProviders();\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressBar(`Writing provider ${idpData._id}`);\n const fileName = getTypedFilename(idpData._id, 'admin.federation');\n const fileData = await frodo.cloud.adminFed.exportAdminFederationProvider(\n idpData._id\n );\n saveJsonToFile(fileData, fileName);\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting all providers.`);\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importAdminFederationProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing provider ${providerId} from ${file}...`);\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n await frodo.cloud.adminFed.importAdminFederationProvider(\n providerId,\n fileData\n );\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${file}.`\n );\n outcome = true;\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstAdminFederationProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(\n `cli.AdminFederationOps.importFirstAdminFederationProviderFromFile: begin`\n );\n showSpinner(`Importing first provider from ${file}...`);\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n await frodo.cloud.adminFed.importFirstAdminFederationProvider(fileData);\n succeedSpinner(`Successfully imported first provider from ${file}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error importing first provider from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n debugMessage(\n `cli.AdminFederationOps.importFirstAdminFederationProviderFromFile: end`\n );\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importAdminFederationProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(\n `cli.AdminFederationOps.importAdminFederationProvidersFromFile: begin`\n );\n showSpinner(`Importing providers from ${file}...`);\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n await frodo.cloud.adminFed.importAdminFederationProviders(fileData);\n succeedSpinner(`Imported providers from ${file}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error importing ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n debugMessage(\n `cli.AdminFederationOps.importAdminFederationProvidersFromFile: end`\n );\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importAdminFederationProvidersFromFiles(): Promise<boolean> {\n const errors = [];\n try {\n debugMessage(\n `cli.AdminFederationOps.importAdminFederationProvidersFromFiles: begin`\n );\n const names = fs.readdirSync('.');\n const files = names.filter((name) =>\n name.toLowerCase().endsWith('.admin.federation.json')\n );\n createProgressBar(files.length, 'Importing providers...');\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await frodo.cloud.adminFed.importAdminFederationProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error importing provider(s) from ${file}`);\n printMessage(error, 'error');\n }\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${files.length} file(s).`\n );\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error importing provider(s) from file(s).`);\n printMessage(error, 'error');\n }\n debugMessage(\n `cli.AdminFederationOps.importAdminFederationProvidersFromFiles: end`\n );\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SACEC,iBAAiB,EACjBC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;;AAE7E;AACA;AACA;AACA;AACA,OAAO,eAAeC,4BAA4BA,CAAA,EAAqB;EACrE,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAI;IACF,MAAMC,SAAS,GAAG,MAAMd,KAAK,CAACe,KAAK,CAACC,QAAQ,CAACC,2BAA2B,CAAC,CAAC;IAC1EH,SAAS,CAACI,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,GAAG,CAACC,aAAa,CAACF,CAAC,CAACC,GAAG,CAAC,CAAC;IACpDP,SAAS,CAACS,OAAO,CAAEC,sBAAsB,IAAK;MAC5CnB,YAAY,CAAE,GAAEmB,sBAAsB,CAACH,GAAI,EAAC,EAAE,MAAM,CAAC;IACvD,CAAC,CAAC;IACFR,OAAO,GAAG,IAAI;EAChB,CAAC,CAAC,OAAOY,GAAG,E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,iBAAiB,CAAE,oCAAmCoB,IAAK,EAAC,CAAC;QAC7DxB,YAAY,CAAC8B,KAAK,EAAE,OAAO,CAAC;MAC9B;IACF;IACA5B,eAAe,CACZ,sBAAqB0D,KAAM,qBAAoBL,KAAK,CAACnB,MAAO,WAC/D,CAAC;EACH,CAAC,CAAC,OAAON,KAAK,EAAE;IACdsB,MAAM,CAACa,IAAI,CAACnC,KAAK,CAAC;IAClB5B,eAAe,CAAE,2CAA0C,CAAC;IAC5DF,YAAY,CAAC8B,KAAK,EAAE,OAAO,CAAC;EAC9B;EACAhC,YAAY,CACT,qEACH,CAAC;EACD,OAAO,CAAC,KAAKsD,MAAM,CAAChB,MAAM;AAC5B"}
|
package/esm/ops/IdpOps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import { createProgressBar, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
|
|
3
|
+
import { createProgressBar, debugMessage, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
|
|
4
4
|
import { getRealmString, getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -56,6 +56,7 @@ export async function listSocialProviders() {
|
|
|
56
56
|
* @param {string} file optional export file name
|
|
57
57
|
*/
|
|
58
58
|
export async function exportSocialProviderToFile(providerId, file = '') {
|
|
59
|
+
debugMessage(`cli.IdpOps.exportSocialProviderToFile: start`);
|
|
59
60
|
let fileName = file;
|
|
60
61
|
if (!fileName) {
|
|
61
62
|
fileName = getTypedFilename(providerId, 'idp');
|
|
@@ -70,6 +71,7 @@ export async function exportSocialProviderToFile(providerId, file = '') {
|
|
|
70
71
|
stopProgressBar(`${err}`);
|
|
71
72
|
printMessage(`${err}`, 'error');
|
|
72
73
|
}
|
|
74
|
+
debugMessage(`cli.IdpOps.exportSocialProviderToFile: end`);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
@@ -89,16 +91,26 @@ export async function exportSocialProvidersToFile(file = '') {
|
|
|
89
91
|
* Export all providers to individual files
|
|
90
92
|
*/
|
|
91
93
|
export async function exportSocialProvidersToFiles() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
debugMessage(`cli.IdpOps.exportSocialProvidersToFiles: start`);
|
|
95
|
+
try {
|
|
96
|
+
const allIdpsData = await frodo.oauth2oidc.external.getSocialIdentityProviders();
|
|
97
|
+
createProgressBar(allIdpsData.length, 'Exporting providers');
|
|
98
|
+
for (const idpData of allIdpsData) {
|
|
99
|
+
try {
|
|
100
|
+
const fileName = getTypedFilename(idpData._id, 'idp');
|
|
101
|
+
const fileData = await frodo.oauth2oidc.external.exportSocialProvider(idpData._id);
|
|
102
|
+
saveJsonToFile(fileData, fileName);
|
|
103
|
+
updateProgressBar(`Exported provider ${idpData._id}`);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
stopProgressBar(`${allIdpsData.length} providers exported.`);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
stopProgressBar(`${error}`);
|
|
111
|
+
printMessage(`${error}`, 'error');
|
|
100
112
|
}
|
|
101
|
-
|
|
113
|
+
debugMessage(`cli.IdpOps.exportSocialProvidersToFiles: end`);
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
/**
|
package/esm/ops/IdpOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressBar","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getRealmString","getTypedFilename","saveJsonToFile","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","oauth2oidc","external","getSocialIdentityProviders","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialProviderToFile","providerId","file","fileName","fileData","exportSocialProvider","exportSocialProvidersToFile","exportSocialProviders","exportSocialProvidersToFiles","allIdpsData","length","idpData","importSocialProviderFromFile","outcome","readFile","data","JSON","parse","importSocialProvider","error","_error$response","response","importFirstSocialProviderFromFile","importFirstSocialProvider","_error$response2","importSocialProvidersFromFile","importSocialProviders","_error$response3","importSocialProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","total","readFileSync","count","Object","keys","idp"],"sources":["ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport type { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport {\n createProgressBar,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers =\n await frodo.oauth2oidc.external.getSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialProviderToFile(\n providerId: string,\n file = ''\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${fileName}`);\n const fileData = await frodo.oauth2oidc.external.exportSocialProvider(\n providerId\n );\n saveJsonToFile(fileData, fileName);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await frodo.oauth2oidc.external.exportSocialProviders();\n saveJsonToFile(fileData, fileName);\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialProvidersToFiles() {\n const allIdpsData =\n await frodo.oauth2oidc.external.getSocialIdentityProviders();\n // printMessage(allIdpsData, 'data');\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressBar(`Writing provider ${idpData._id}`);\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await frodo.oauth2oidc.external.exportSocialProvider(\n idpData._id\n );\n saveJsonToFile(fileData, fileName);\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing provider ${providerId} from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importSocialProvider(\n providerId,\n fileData\n );\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${file}.`\n );\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing first provider from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importFirstSocialProvider(\n fileData\n );\n succeedSpinner(`Successfully imported first provider from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing first provider from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing providers from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importSocialProviders(fileData);\n succeedSpinner(`Successfully imported providers from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing providers from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialProvidersFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.idp.json')\n );\n\n createProgressBar(jsonFiles.length, 'Importing providers...');\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await frodo.oauth2oidc.external.importSocialProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;;AAEnC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+BAA+B;EAC3CA,QAAQ,IAAI,6BAA6B;EACzC,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACN,YAA+B,EAAU;EACrE,MAAMO,GAAG,GAAI,KAAIP,YAAY,CAACE,GAAI,MAChCF,YAAY,CAACQ,OAAO,KAAK,KAAK,GAC1B,gBAAg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OAAON,OAAO;AAChB;;AAEA;AACA;AACA;AACA,OAAO,eAAee,8BAA8BA,CAAA,EAAG;EACrD,MAAMC,KAAK,GAAGhE,EAAE,CAACiE,WAAW,CAAC,GAAG,CAAC;EACjC,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAE9C,IAAI,IAClCA,IAAI,CAAC+C,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,WAAW,CACzC,CAAC;EAEDpE,iBAAiB,CAACiE,SAAS,CAACrB,MAAM,EAAE,wBAAwB,CAAC;EAC7D,IAAIyB,KAAK,GAAG,CAAC;EACb,KAAK,MAAMjC,IAAI,IAAI6B,SAAS,EAAE;IAC5B,MAAMhB,IAAI,GAAGlD,EAAE,CAACuE,YAAY,CAAClC,IAAI,EAAE,MAAM,CAAC;IAC1C,MAAME,QAAQ,GAAGY,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;IACjC,MAAMsB,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACnC,QAAQ,CAACoC,GAAG,CAAC,CAAC9B,MAAM;IAC9CyB,KAAK,IAAIE,KAAK;IACd,MAAMzE,KAAK,CAACyB,UAAU,CAACC,QAAQ,CAACoC,qBAAqB,CAACtB,QAAQ,CAAC;IAC/DhC,iBAAiB,CAAE,YAAWiE,KAAM,qBAAoBnC,IAAK,EAAC,CAAC;EACjE;EACAhC,eAAe,CACZ,sBAAqBiE,KAAM,qBAAoBJ,SAAS,CAACrB,MAAO,WACnE,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressBar","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getRealmString","getTypedFilename","saveJsonToFile","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","oauth2oidc","external","getSocialIdentityProviders","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialProviderToFile","providerId","file","fileName","fileData","exportSocialProvider","exportSocialProvidersToFile","exportSocialProviders","exportSocialProvidersToFiles","allIdpsData","length","idpData","error","importSocialProviderFromFile","outcome","readFile","data","JSON","parse","importSocialProvider","_error$response","response","importFirstSocialProviderFromFile","importFirstSocialProvider","_error$response2","importSocialProvidersFromFile","importSocialProviders","_error$response3","importSocialProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","total","readFileSync","count","Object","keys","idp"],"sources":["ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport type { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport {\n createProgressBar,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers =\n await frodo.oauth2oidc.external.getSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialProviderToFile(\n providerId: string,\n file = ''\n) {\n debugMessage(`cli.IdpOps.exportSocialProviderToFile: start`);\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${fileName}`);\n const fileData = await frodo.oauth2oidc.external.exportSocialProvider(\n providerId\n );\n saveJsonToFile(fileData, fileName);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialProviderToFile: end`);\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await frodo.oauth2oidc.external.exportSocialProviders();\n saveJsonToFile(fileData, fileName);\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialProvidersToFiles() {\n debugMessage(`cli.IdpOps.exportSocialProvidersToFiles: start`);\n try {\n const allIdpsData =\n await frodo.oauth2oidc.external.getSocialIdentityProviders();\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n try {\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await frodo.oauth2oidc.external.exportSocialProvider(\n idpData._id\n );\n saveJsonToFile(fileData, fileName);\n updateProgressBar(`Exported provider ${idpData._id}`);\n } catch (error) {\n printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');\n }\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n } catch (error) {\n stopProgressBar(`${error}`);\n printMessage(`${error}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialProvidersToFiles: end`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing provider ${providerId} from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importSocialProvider(\n providerId,\n fileData\n );\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${file}.`\n );\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing first provider from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importFirstSocialProvider(\n fileData\n );\n succeedSpinner(`Successfully imported first provider from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing first provider from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing providers from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await frodo.oauth2oidc.external.importSocialProviders(fileData);\n succeedSpinner(`Successfully imported providers from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing providers from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialProvidersFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.idp.json')\n );\n\n createProgressBar(jsonFiles.length, 'Importing providers...');\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await frodo.oauth2oidc.external.importSocialProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;;AAEnC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+BAA+B;EAC3CA,QAAQ,IAAI,6BAA6B;EACzC,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,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