@rockcarver/frodo-cli 2.0.0-16 → 2.0.0-18
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 +9 -1
- package/esm/cli/FrodoCommand.js +1 -1
- package/esm/cli/FrodoCommand.js.map +1 -1
- package/esm/cli/log/log-fetch.js +48 -26
- package/esm/cli/log/log-fetch.js.map +1 -1
- package/esm/cli/log/log-list.js +49 -28
- package/esm/cli/log/log-list.js.map +1 -1
- package/esm/cli/log/log-tail.js +47 -26
- package/esm/cli/log/log-tail.js.map +1 -1
- package/esm/ops/SecretsOps.js +3 -3
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ServiceOps.js +1 -1
- package/esm/ops/ServiceOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +3 -3
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/ExportImportUtils.js +8 -78
- package/esm/utils/ExportImportUtils.js.map +1 -1
- package/package.json +2 -2
- package/esm/cli/theme/theme-list.e2e.test_.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.0.0-17] - 2023-09-29
|
|
11
|
+
|
|
12
|
+
## [2.0.0-16] - 2023-09-08
|
|
13
|
+
|
|
10
14
|
## [2.0.0-15] - 2023-08-17
|
|
11
15
|
|
|
12
16
|
### Fixed
|
|
@@ -1345,7 +1349,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1345
1349
|
- Fixed problem with adding connection profiles
|
|
1346
1350
|
- Miscellaneous bug fixes
|
|
1347
1351
|
|
|
1348
|
-
[Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v2.0.0-
|
|
1352
|
+
[Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v2.0.0-17...HEAD
|
|
1353
|
+
|
|
1354
|
+
[2.0.0-17]: https://github.com/rockcarver/frodo-cli/compare/v2.0.0-16...v2.0.0-17
|
|
1355
|
+
|
|
1356
|
+
[2.0.0-16]: https://github.com/rockcarver/frodo-cli/compare/v2.0.0-15...v2.0.0-16
|
|
1349
1357
|
|
|
1350
1358
|
[2.0.0-15]: https://github.com/rockcarver/frodo-cli/compare/v2.0.0-14...v2.0.0-15
|
|
1351
1359
|
|
package/esm/cli/FrodoCommand.js
CHANGED
|
@@ -110,7 +110,7 @@ export class FrodoCommand extends FrodoStubCommand {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// additional help
|
|
113
|
-
this.addHelpText('after', `\nEvironment Variables:\n` + ` FRODO_HOST: Access Management base URL. Overrides 'host' argument.\n` + ` FRODO_REALM: Realm. Overrides 'realm' argument.\n` + ` FRODO_USERNAME: Username. Overrides 'username' argument.\n` + ` FRODO_PASSWORD: Password. Overrides 'password' argument.\n` + ` FRODO_SA_ID: Service account uuid. Overrides '--sa-id' option.\n` + ` FRODO_SA_JWK: Service account JWK. Overrides '--sa-jwk-file' option but takes the actual JWK as a value, not a file name.\n` + ('frodo conn save' === this.name() ? ` FRODO_LOG_KEY: Log API key. Overrides '--log-api-key' option.\n` + ` FRODO_LOG_SECRET: Log API secret. Overrides '--log-api-secret' option.\n` : ``) + (this.name().startsWith('frodo
|
|
113
|
+
this.addHelpText('after', `\nEvironment Variables:\n` + ` FRODO_HOST: Access Management base URL. Overrides 'host' argument.\n` + ` FRODO_REALM: Realm. Overrides 'realm' argument.\n` + ` FRODO_USERNAME: Username. Overrides 'username' argument.\n` + ` FRODO_PASSWORD: Password. Overrides 'password' argument.\n` + ` FRODO_SA_ID: Service account uuid. Overrides '--sa-id' option.\n` + ` FRODO_SA_JWK: Service account JWK. Overrides '--sa-jwk-file' option but takes the actual JWK as a value, not a file name.\n` + ('frodo conn save' === this.name() ? ` FRODO_LOG_KEY: Log API key. Overrides '--log-api-key' option.\n` + ` FRODO_LOG_SECRET: Log API secret. Overrides '--log-api-secret' option.\n` : ``) + (this.name().startsWith('frodo log') ? ` FRODO_LOG_KEY: Log API key. Overrides 'username' argument.\n` + ` FRODO_LOG_SECRET: Log API secret. Overrides 'password' argument.\n` : ``) + ` FRODO_CONNECTION_PROFILES_PATH: Use this connection profiles file instead of '~/.frodo/Connections.json'.\n` + ` FRODO_AUTHENTICATION_SERVICE: Name of a login journey to use.\n` + ` FRODO_DEBUG: Set to any value to enable debug output. Same as '--debug'.\n` + ` FRODO_MASTER_KEY_PATH: Use this master key file instead of '~/.frodo/masterkey.key' file.\n` + ` FRODO_MASTER_KEY: Use this master key instead of '~/.frodo/masterkey.key' file. Takes precedence over FRODO_MASTER_KEY_PATH.\n`);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrodoCommand.js","names":["state","Argument","Command","Option","fs","globalConfig","createProgressIndicator","curlirizeMessage","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","verboseMessage","hostArgument","realmArgument","default","process","env","FRODO_REALM","DEFAULT_REALM_KEY","usernameArgument","passwordArgument","serviceAccountIdOption","serviceAccountJwkFileOption","deploymentOption","choices","DEPLOYMENT_TYPES","insecureOption","verboseOption","debugOption","curlirizeOption","defaultArgs","defaultOpts","stateMap","name","host","setHost","realm","setRealm","username","setUsername","password","setPassword","attributeName","saId","setServiceAccountId","file","data","readFileSync","jwk","JSON","parse","toString","setServiceAccountJwk","error","message","type","setDeploymentType","insecure","setAllowInsecureConnection","verbose","setVerbose","debug","setDebug","curlirize","setCurlirize","FrodoStubCommand","constructor","on","_error$config","_error$config2","_error$response","config","method","url","response","stack","exitCode","helpOption","showHelpAfterError","configureHelp","sortSubcommands","sortOptions","setPrintHandler","setVerboseHandler","setDebugHandler","setCurlirizeHandler","setCreateProgressHandler","setUpdateProgressHandler","setStopProgressHandler","FrodoCommand","omits","arg","includes","addArgument","opt","addOption","addHelpText","startsWith","handleDefaultArgsAndOpts","args","command","pop","options","i","v","entries","_args","length","Object","keys","handler","k"],"sources":["../../src/cli/FrodoCommand.ts"],"sourcesContent":["import { state } from '@rockcarver/frodo-lib';\nimport { Argument, Command, Option } from 'commander';\nimport fs from 'fs';\n\nimport * as globalConfig from '../storage/StaticStorage';\nimport {\n createProgressIndicator,\n curlirizeMessage,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n verboseMessage,\n} from '../utils/Console.js';\n\nconst hostArgument = new Argument(\n '[host]',\n 'Access Management base URL, e.g.: https://cdk.iam.example.com/am. To use a connection profile, just specify a unique substring.'\n);\n\nconst realmArgument = new Argument(\n '[realm]',\n \"Realm. Specify realm as '/' for the root realm or 'realm' or '/parent/child' otherwise.\"\n).default(\n // must check for FRODO_REALM env variable here because otherwise cli will overwrite realm with default value\n process.env.FRODO_REALM || globalConfig.DEFAULT_REALM_KEY,\n '\"alpha\" for Identity Cloud tenants, \"/\" otherwise.'\n);\n\nconst usernameArgument = new Argument(\n '[username]',\n 'Username to login with. Must be an admin user with appropriate rights to manage authentication journeys/trees.'\n);\n\nconst passwordArgument = new Argument('[password]', 'Password.');\n\nconst serviceAccountIdOption = new Option(\n '--sa-id <sa-id>',\n 'Service account id.'\n);\n\nconst serviceAccountJwkFileOption = new Option(\n '--sa-jwk-file <file>',\n 'File containing the JSON Web Key (JWK) associated with the the service account.'\n);\n\nconst deploymentOption = new Option(\n '-m, --type <type>',\n 'Override auto-detected deployment type. Valid values for type: \\n\\\nclassic: A classic Access Management-only deployment with custom layout and configuration. \\n\\\ncloud: A ForgeRock Identity Cloud environment. \\n\\\nforgeops: A ForgeOps CDK or CDM deployment. \\n\\\nThe detected or provided deployment type controls certain behavior like obtaining an Identity \\\nManagement admin token or not and whether to export/import referenced email templates or how \\\nto walk through the tenant admin login flow of Identity Cloud and handle MFA'\n).choices(globalConfig.DEPLOYMENT_TYPES);\n\nconst insecureOption = new Option(\n '-k, --insecure',\n 'Allow insecure connections when using SSL/TLS. Has no effect when using a network proxy for https (HTTPS_PROXY=http://<host>:<port>), in that case the proxy must provide this capability.'\n).default(false, \"Don't allow insecure connections\");\n\nconst verboseOption = new Option(\n '--verbose',\n 'Verbose output during command execution. If specified, may or may not produce additional output.'\n);\n\nconst debugOption = new Option(\n '--debug',\n 'Debug output during command execution. If specified, may or may not produce additional output helpful for troubleshooting.'\n);\n\nconst curlirizeOption = new Option(\n '--curlirize',\n 'Output all network calls in curl format.'\n);\n\nconst defaultArgs = [\n hostArgument,\n realmArgument,\n usernameArgument,\n passwordArgument,\n];\n\nconst defaultOpts = [\n serviceAccountIdOption,\n serviceAccountJwkFileOption,\n deploymentOption,\n insecureOption,\n verboseOption,\n debugOption,\n curlirizeOption,\n];\n\nconst stateMap = {\n [hostArgument.name()]: (host: string) => state.setHost(host),\n [realmArgument.name()]: (realm: string) => state.setRealm(realm),\n [usernameArgument.name()]: (username: string) => state.setUsername(username),\n [passwordArgument.name()]: (password: string) => state.setPassword(password),\n [serviceAccountIdOption.attributeName()]: (saId: string) =>\n state.setServiceAccountId(saId),\n [serviceAccountJwkFileOption.attributeName()]: (file: string) => {\n try {\n const data = fs.readFileSync(file);\n const jwk = JSON.parse(data.toString());\n state.setServiceAccountJwk(jwk);\n } catch (error) {\n printMessage(\n `Error parsing JWK from file ${file}: ${error.message}`,\n 'error'\n );\n }\n },\n [deploymentOption.attributeName()]: (type: string) =>\n state.setDeploymentType(type),\n [insecureOption.attributeName()]: (insecure: boolean) =>\n state.setAllowInsecureConnection(insecure),\n [verboseOption.attributeName()]: (verbose: boolean) =>\n state.setVerbose(verbose),\n [debugOption.attributeName()]: (debug: boolean) => state.setDebug(debug),\n [curlirizeOption.attributeName()]: (curlirize: boolean) =>\n state.setCurlirize(curlirize),\n};\n\n/**\n * Command with default options\n */\nexport class FrodoStubCommand extends Command {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string) {\n super(name);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n process.on('unhandledRejection', (error: any) => {\n printMessage(\n `${error.config?.method ? error.config.method + ' ' : ''}${\n error.config?.url ? error.config.url : ''\n }`,\n 'error'\n );\n printMessage(error.response?.data, 'error');\n printMessage(error.stack, 'error');\n printMessage(\n `Please report this unhandled error here: https://github.com/rockcarver/frodo-cli/issues`,\n 'error'\n );\n process.exitCode = 1;\n });\n\n // other default settings\n this.helpOption('-h, --help', 'Help');\n this.showHelpAfterError();\n this.configureHelp({\n sortSubcommands: true,\n sortOptions: true,\n });\n\n // register default handlers\n state.setPrintHandler(printMessage);\n state.setVerboseHandler(verboseMessage);\n state.setDebugHandler(debugMessage);\n state.setCurlirizeHandler(curlirizeMessage);\n state.setCreateProgressHandler(createProgressIndicator);\n state.setUpdateProgressHandler(updateProgressIndicator);\n state.setStopProgressHandler(stopProgressIndicator);\n }\n}\n\n/**\n * Command with default options\n */\nexport class FrodoCommand extends FrodoStubCommand {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string, omits: string[] = []) {\n super(name);\n\n // register default arguments\n for (const arg of defaultArgs) {\n if (!omits.includes(arg.name())) this.addArgument(arg);\n }\n\n // register default options\n for (const opt of defaultOpts) {\n if (!omits.includes(opt.name())) this.addOption(opt);\n }\n\n // additional help\n this.addHelpText(\n 'after',\n `\\nEvironment Variables:\\n` +\n ` FRODO_HOST: Access Management base URL. Overrides 'host' argument.\\n` +\n ` FRODO_REALM: Realm. Overrides 'realm' argument.\\n` +\n ` FRODO_USERNAME: Username. Overrides 'username' argument.\\n` +\n ` FRODO_PASSWORD: Password. Overrides 'password' argument.\\n` +\n ` FRODO_SA_ID: Service account uuid. Overrides '--sa-id' option.\\n` +\n ` FRODO_SA_JWK: Service account JWK. Overrides '--sa-jwk-file' option but takes the actual JWK as a value, not a file name.\\n` +\n ('frodo conn save' === this.name()\n ? ` FRODO_LOG_KEY: Log API key. Overrides '--log-api-key' option.\\n` +\n ` FRODO_LOG_SECRET: Log API secret. Overrides '--log-api-secret' option.\\n`\n : ``) +\n (this.name().startsWith('frodo logs')\n ? ` FRODO_LOG_KEY: Log API key. Overrides 'username' argument.\\n` +\n ` FRODO_LOG_SECRET: Log API secret. Overrides 'password' argument.\\n`\n : ``) +\n ` FRODO_AUTHENTICATION_SERVICE: Name of a login journey to use.\\n` +\n ` FRODO_DEBUG: Set to any value to enable debug output. Same as '--debug'.\\n` +\n ` FRODO_MASTER_KEY_PATH: Use this master key file instead of '~/.frodo/masterkey.key' file.\\n` +\n ` FRODO_MASTER_KEY: Use this master key instead of '~/.frodo/masterkey.key' file. Takes precedence over FRODO_MASTER_KEY_PATH.\\n`\n );\n }\n\n /**\n *\n * @param args\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handleDefaultArgsAndOpts(...args: any) {\n const command = args.pop();\n const options = args.pop();\n\n // handle arguments first\n for (const [i, v] of command.args.entries()) {\n if (!command._args[i]) {\n printMessage(\n `${command.args.length} arguments supplied but command only supports ${command._args.length}.`,\n 'warn'\n );\n break;\n }\n const arg = command._args[i].name();\n // handle only default arguments\n if (Object.keys(stateMap).includes(arg)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default argument '${arg}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[arg];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default argument '${arg}'.`\n );\n }\n }\n\n // handle options\n for (const [k, v] of Object.entries(options)) {\n // handle only default options\n if (Object.keys(stateMap).includes(k)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default option '${k}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[k];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default option '${k}'.`\n );\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E;QACvCpF,YAAY,CACT,qEAAoEoF,GAAI,IAC3E,CAAC;QACD;QACA,MAAMmB,OAAY,GAAG9E,QAAQ,CAAC2D,GAAG,CAAC;QAClCmB,OAAO,CAACN,CAAC,CAAC;MACZ,CAAC,MAAM;QACLjG,YAAY,CACT,yEAAwEoF,GAAI,IAC/E,CAAC;MACH;IACF;;IAEA;IACA,KAAK,MAAM,CAACoB,CAAC,EAAEP,CAAC,CAAC,IAAII,MAAM,CAACH,OAAO,CAACH,OAAO,CAAC,EAAE;MAC5C;MACA,IAAIM,MAAM,CAACC,IAAI,CAAC7E,QAAQ,CAAC,CAAC4D,QAAQ,CAACmB,CAAC,CAAC,EAAE;QACrCxG,YAAY,CACT,mEAAkEwG,CAAE,IACvE,CAAC;QACD;QACA,MAAMD,OAAY,GAAG9E,QAAQ,CAAC+E,CAAC,CAAC;QAChCD,OAAO,CAACN,CAAC,CAAC;MACZ,CAAC,MAAM;QACLjG,YAAY,CACT,uEAAsEwG,CAAE,IAC3E,CAAC;MACH;IACF;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"FrodoCommand.js","names":["state","Argument","Command","Option","fs","globalConfig","createProgressIndicator","curlirizeMessage","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","verboseMessage","hostArgument","realmArgument","default","process","env","FRODO_REALM","DEFAULT_REALM_KEY","usernameArgument","passwordArgument","serviceAccountIdOption","serviceAccountJwkFileOption","deploymentOption","choices","DEPLOYMENT_TYPES","insecureOption","verboseOption","debugOption","curlirizeOption","defaultArgs","defaultOpts","stateMap","name","host","setHost","realm","setRealm","username","setUsername","password","setPassword","attributeName","saId","setServiceAccountId","file","data","readFileSync","jwk","JSON","parse","toString","setServiceAccountJwk","error","message","type","setDeploymentType","insecure","setAllowInsecureConnection","verbose","setVerbose","debug","setDebug","curlirize","setCurlirize","FrodoStubCommand","constructor","on","_error$config","_error$config2","_error$response","config","method","url","response","stack","exitCode","helpOption","showHelpAfterError","configureHelp","sortSubcommands","sortOptions","setPrintHandler","setVerboseHandler","setDebugHandler","setCurlirizeHandler","setCreateProgressHandler","setUpdateProgressHandler","setStopProgressHandler","FrodoCommand","omits","arg","includes","addArgument","opt","addOption","addHelpText","startsWith","handleDefaultArgsAndOpts","args","command","pop","options","i","v","entries","_args","length","Object","keys","handler","k"],"sources":["../../src/cli/FrodoCommand.ts"],"sourcesContent":["import { state } from '@rockcarver/frodo-lib';\nimport { Argument, Command, Option } from 'commander';\nimport fs from 'fs';\n\nimport * as globalConfig from '../storage/StaticStorage';\nimport {\n createProgressIndicator,\n curlirizeMessage,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n verboseMessage,\n} from '../utils/Console.js';\n\nconst hostArgument = new Argument(\n '[host]',\n 'Access Management base URL, e.g.: https://cdk.iam.example.com/am. To use a connection profile, just specify a unique substring.'\n);\n\nconst realmArgument = new Argument(\n '[realm]',\n \"Realm. Specify realm as '/' for the root realm or 'realm' or '/parent/child' otherwise.\"\n).default(\n // must check for FRODO_REALM env variable here because otherwise cli will overwrite realm with default value\n process.env.FRODO_REALM || globalConfig.DEFAULT_REALM_KEY,\n '\"alpha\" for Identity Cloud tenants, \"/\" otherwise.'\n);\n\nconst usernameArgument = new Argument(\n '[username]',\n 'Username to login with. Must be an admin user with appropriate rights to manage authentication journeys/trees.'\n);\n\nconst passwordArgument = new Argument('[password]', 'Password.');\n\nconst serviceAccountIdOption = new Option(\n '--sa-id <sa-id>',\n 'Service account id.'\n);\n\nconst serviceAccountJwkFileOption = new Option(\n '--sa-jwk-file <file>',\n 'File containing the JSON Web Key (JWK) associated with the the service account.'\n);\n\nconst deploymentOption = new Option(\n '-m, --type <type>',\n 'Override auto-detected deployment type. Valid values for type: \\n\\\nclassic: A classic Access Management-only deployment with custom layout and configuration. \\n\\\ncloud: A ForgeRock Identity Cloud environment. \\n\\\nforgeops: A ForgeOps CDK or CDM deployment. \\n\\\nThe detected or provided deployment type controls certain behavior like obtaining an Identity \\\nManagement admin token or not and whether to export/import referenced email templates or how \\\nto walk through the tenant admin login flow of Identity Cloud and handle MFA'\n).choices(globalConfig.DEPLOYMENT_TYPES);\n\nconst insecureOption = new Option(\n '-k, --insecure',\n 'Allow insecure connections when using SSL/TLS. Has no effect when using a network proxy for https (HTTPS_PROXY=http://<host>:<port>), in that case the proxy must provide this capability.'\n).default(false, \"Don't allow insecure connections\");\n\nconst verboseOption = new Option(\n '--verbose',\n 'Verbose output during command execution. If specified, may or may not produce additional output.'\n);\n\nconst debugOption = new Option(\n '--debug',\n 'Debug output during command execution. If specified, may or may not produce additional output helpful for troubleshooting.'\n);\n\nconst curlirizeOption = new Option(\n '--curlirize',\n 'Output all network calls in curl format.'\n);\n\nconst defaultArgs = [\n hostArgument,\n realmArgument,\n usernameArgument,\n passwordArgument,\n];\n\nconst defaultOpts = [\n serviceAccountIdOption,\n serviceAccountJwkFileOption,\n deploymentOption,\n insecureOption,\n verboseOption,\n debugOption,\n curlirizeOption,\n];\n\nconst stateMap = {\n [hostArgument.name()]: (host: string) => state.setHost(host),\n [realmArgument.name()]: (realm: string) => state.setRealm(realm),\n [usernameArgument.name()]: (username: string) => state.setUsername(username),\n [passwordArgument.name()]: (password: string) => state.setPassword(password),\n [serviceAccountIdOption.attributeName()]: (saId: string) =>\n state.setServiceAccountId(saId),\n [serviceAccountJwkFileOption.attributeName()]: (file: string) => {\n try {\n const data = fs.readFileSync(file);\n const jwk = JSON.parse(data.toString());\n state.setServiceAccountJwk(jwk);\n } catch (error) {\n printMessage(\n `Error parsing JWK from file ${file}: ${error.message}`,\n 'error'\n );\n }\n },\n [deploymentOption.attributeName()]: (type: string) =>\n state.setDeploymentType(type),\n [insecureOption.attributeName()]: (insecure: boolean) =>\n state.setAllowInsecureConnection(insecure),\n [verboseOption.attributeName()]: (verbose: boolean) =>\n state.setVerbose(verbose),\n [debugOption.attributeName()]: (debug: boolean) => state.setDebug(debug),\n [curlirizeOption.attributeName()]: (curlirize: boolean) =>\n state.setCurlirize(curlirize),\n};\n\n/**\n * Command with default options\n */\nexport class FrodoStubCommand extends Command {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string) {\n super(name);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n process.on('unhandledRejection', (error: any) => {\n printMessage(\n `${error.config?.method ? error.config.method + ' ' : ''}${\n error.config?.url ? error.config.url : ''\n }`,\n 'error'\n );\n printMessage(error.response?.data, 'error');\n printMessage(error.stack, 'error');\n printMessage(\n `Please report this unhandled error here: https://github.com/rockcarver/frodo-cli/issues`,\n 'error'\n );\n process.exitCode = 1;\n });\n\n // other default settings\n this.helpOption('-h, --help', 'Help');\n this.showHelpAfterError();\n this.configureHelp({\n sortSubcommands: true,\n sortOptions: true,\n });\n\n // register default handlers\n state.setPrintHandler(printMessage);\n state.setVerboseHandler(verboseMessage);\n state.setDebugHandler(debugMessage);\n state.setCurlirizeHandler(curlirizeMessage);\n state.setCreateProgressHandler(createProgressIndicator);\n state.setUpdateProgressHandler(updateProgressIndicator);\n state.setStopProgressHandler(stopProgressIndicator);\n }\n}\n\n/**\n * Command with default options\n */\nexport class FrodoCommand extends FrodoStubCommand {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string, omits: string[] = []) {\n super(name);\n\n // register default arguments\n for (const arg of defaultArgs) {\n if (!omits.includes(arg.name())) this.addArgument(arg);\n }\n\n // register default options\n for (const opt of defaultOpts) {\n if (!omits.includes(opt.name())) this.addOption(opt);\n }\n\n // additional help\n this.addHelpText(\n 'after',\n `\\nEvironment Variables:\\n` +\n ` FRODO_HOST: Access Management base URL. Overrides 'host' argument.\\n` +\n ` FRODO_REALM: Realm. Overrides 'realm' argument.\\n` +\n ` FRODO_USERNAME: Username. Overrides 'username' argument.\\n` +\n ` FRODO_PASSWORD: Password. Overrides 'password' argument.\\n` +\n ` FRODO_SA_ID: Service account uuid. Overrides '--sa-id' option.\\n` +\n ` FRODO_SA_JWK: Service account JWK. Overrides '--sa-jwk-file' option but takes the actual JWK as a value, not a file name.\\n` +\n ('frodo conn save' === this.name()\n ? ` FRODO_LOG_KEY: Log API key. Overrides '--log-api-key' option.\\n` +\n ` FRODO_LOG_SECRET: Log API secret. Overrides '--log-api-secret' option.\\n`\n : ``) +\n (this.name().startsWith('frodo log')\n ? ` FRODO_LOG_KEY: Log API key. Overrides 'username' argument.\\n` +\n ` FRODO_LOG_SECRET: Log API secret. Overrides 'password' argument.\\n`\n : ``) +\n ` FRODO_CONNECTION_PROFILES_PATH: Use this connection profiles file instead of '~/.frodo/Connections.json'.\\n` +\n ` FRODO_AUTHENTICATION_SERVICE: Name of a login journey to use.\\n` +\n ` FRODO_DEBUG: Set to any value to enable debug output. Same as '--debug'.\\n` +\n ` FRODO_MASTER_KEY_PATH: Use this master key file instead of '~/.frodo/masterkey.key' file.\\n` +\n ` FRODO_MASTER_KEY: Use this master key instead of '~/.frodo/masterkey.key' file. Takes precedence over FRODO_MASTER_KEY_PATH.\\n`\n );\n }\n\n /**\n *\n * @param args\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handleDefaultArgsAndOpts(...args: any) {\n const command = args.pop();\n const options = args.pop();\n\n // handle arguments first\n for (const [i, v] of command.args.entries()) {\n if (!command._args[i]) {\n printMessage(\n `${command.args.length} arguments supplied but command only supports ${command._args.length}.`,\n 'warn'\n );\n break;\n }\n const arg = command._args[i].name();\n // handle only default arguments\n if (Object.keys(stateMap).includes(arg)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default argument '${arg}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[arg];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default argument '${arg}'.`\n );\n }\n }\n\n // handle options\n for (const [k, v] of Object.entries(options)) {\n // handle only default options\n if (Object.keys(stateMap).includes(k)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default option '${k}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[k];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default option '${k}'.`\n );\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,SAASC,QAAQ,EAAEC,OAAO,EAAEC,MAAM,QAAQ,WAAW;AACrD,OAAOC,EAAE,MAAM,IAAI;AAEnB,OAAO,KAAKC,YAAY,MAAM,0BAA0B;AACxD,SACEC,uBAAuB,EACvBC,gBAAgB,EAChBC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,EACvBC,cAAc,QACT,qBAAqB;AAE5B,MAAMC,YAAY,GAAG,IAAIZ,QAAQ,CAC/B,QAAQ,EACR,iIACF,CAAC;AAED,MAAMa,aAAa,GAAG,IAAIb,QAAQ,CAChC,SAAS,EACT,yFACF,CAAC,CAACc,OAAO;AACP;AACAC,OAAO,CAACC,GAAG,CAACC,WAAW,IAAIb,YAAY,CAACc,iBAAiB,EACzD,oDACF,CAAC;AAED,MAAMC,gBAAgB,GAAG,IAAInB,QAAQ,CACnC,YAAY,EACZ,gHACF,CAAC;AAED,MAAMoB,gBAAgB,GAAG,IAAIpB,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;AAEhE,MAAMqB,sBAAsB,GAAG,IAAInB,MAAM,CACvC,iBAAiB,EACjB,qBACF,CAAC;AAED,MAAMoB,2BAA2B,GAAG,IAAIpB,MAAM,CAC5C,sBAAsB,EACtB,iFACF,CAAC;AAED,MAAMqB,gBAAgB,GAAG,IAAIrB,MAAM,CACjC,mBAAmB,EACnB;AACF;AACA;AACA;AACA;AACA;AACA,6EACA,CAAC,CAACsB,OAAO,CAACpB,YAAY,CAACqB,gBAAgB,CAAC;AAExC,MAAMC,cAAc,GAAG,IAAIxB,MAAM,CAC/B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F,MACF,CAAC;QACD;MACF;MACA,MAAMhB,GAAG,GAAGS,OAAO,CAACM,KAAK,CAACH,CAAC,CAAC,CAACtE,IAAI,CAAC,CAAC;MACnC;MACA,IAAI2E,MAAM,CAACC,IAAI,CAAC7E,QAAQ,CAAC,CAAC4D,QAAQ,CAACD,GAAG,CAAC,EAAE;QACvCpF,YAAY,CACT,qEAAoEoF,GAAI,IAC3E,CAAC;QACD;QACA,MAAMmB,OAAY,GAAG9E,QAAQ,CAAC2D,GAAG,CAAC;QAClCmB,OAAO,CAACN,CAAC,CAAC;MACZ,CAAC,MAAM;QACLjG,YAAY,CACT,yEAAwEoF,GAAI,IAC/E,CAAC;MACH;IACF;;IAEA;IACA,KAAK,MAAM,CAACoB,CAAC,EAAEP,CAAC,CAAC,IAAII,MAAM,CAACH,OAAO,CAACH,OAAO,CAAC,EAAE;MAC5C;MACA,IAAIM,MAAM,CAACC,IAAI,CAAC7E,QAAQ,CAAC,CAAC4D,QAAQ,CAACmB,CAAC,CAAC,EAAE;QACrCxG,YAAY,CACT,mEAAkEwG,CAAE,IACvE,CAAC;QACD;QACA,MAAMD,OAAY,GAAG9E,QAAQ,CAAC+E,CAAC,CAAC;QAChCD,OAAO,CAACN,CAAC,CAAC;MACZ,CAAC,MAAM;QACLjG,YAAY,CACT,uEAAsEwG,CAAE,IAC3E,CAAC;MACH;IACF;EACF;AACF"}
|
package/esm/cli/log/log-fetch.js
CHANGED
|
@@ -2,7 +2,7 @@ import { frodo, state } from '@rockcarver/frodo-lib';
|
|
|
2
2
|
import { Option } from 'commander';
|
|
3
3
|
import { fetchLogs, provisionCreds } from '../../ops/LogOps';
|
|
4
4
|
import * as config from '../../utils/Config';
|
|
5
|
-
import { printMessage } from '../../utils/Console';
|
|
5
|
+
import { printMessage, verboseMessage } from '../../utils/Console';
|
|
6
6
|
import { FrodoCommand } from '../FrodoCommand';
|
|
7
7
|
import { sourcesOptionM } from './log';
|
|
8
8
|
const {
|
|
@@ -29,31 +29,47 @@ Following values are possible (values on the same line are equivalent): \
|
|
|
29
29
|
Cannot be more than 30 days in the past. If not specified, logs from one hour ago are fetched \
|
|
30
30
|
(-e is ignored)')).addOption(new Option('-e, --end-timestamp <endTs>', 'End timestamp for period. Default: "now"')).addOption(new Option('-s, --search-string <ss>', 'Filter by a specific string (ANDed with transactionID filter)')).addOption(new Option('-d, --defaults', 'Use default logging noise filters').default(false, `Use custom logging noise filters defined in $HOME/${config.FRODO_LOG_NOISEFILTER_FILENAME}`)).action(async (host, user, password, options, command) => {
|
|
31
31
|
command.handleDefaultArgsAndOpts(host, user, password, options, command);
|
|
32
|
-
let
|
|
32
|
+
let foundCredentials = false;
|
|
33
33
|
const conn = await getConnectionProfile();
|
|
34
|
-
if (conn)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
if (conn) state.setHost(conn.tenant);
|
|
35
|
+
|
|
36
|
+
// log api creds have been supplied as username and password arguments
|
|
37
|
+
if (state.getUsername() && state.getPassword()) {
|
|
38
|
+
verboseMessage(`Using log api credentials from command line.`);
|
|
39
|
+
state.setLogApiKey(state.getUsername());
|
|
40
|
+
state.setLogApiSecret(state.getPassword());
|
|
41
|
+
foundCredentials = true;
|
|
42
|
+
}
|
|
43
|
+
// log api creds from connection profile
|
|
44
|
+
else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {
|
|
45
|
+
verboseMessage(`Using log api credentials from connection profile.`);
|
|
46
|
+
state.setLogApiKey(conn.logApiKey);
|
|
47
|
+
state.setLogApiSecret(conn.logApiSecret);
|
|
48
|
+
foundCredentials = true;
|
|
49
|
+
}
|
|
50
|
+
// log api creds have been supplied via env variables
|
|
51
|
+
else if (state.getLogApiKey() && state.getLogApiSecret()) {
|
|
52
|
+
verboseMessage(`Using log api credentials from environment variables.`);
|
|
53
|
+
foundCredentials = true;
|
|
54
|
+
}
|
|
55
|
+
// no log api creds but got username and password, so can try to create them
|
|
56
|
+
else if (conn && conn.username && conn.password) {
|
|
57
|
+
printMessage(`Found admin credentials in connection profile, attempting to create log api credentials...`);
|
|
58
|
+
state.setUsername(conn.username);
|
|
59
|
+
state.setPassword(conn.password);
|
|
60
|
+
if (await getTokens(true)) {
|
|
61
|
+
const creds = await provisionCreds();
|
|
62
|
+
state.setLogApiKey(creds.api_key_id);
|
|
63
|
+
state.setLogApiSecret(creds.api_key_secret);
|
|
64
|
+
await saveConnectionProfile(state.getHost());
|
|
65
|
+
foundCredentials = true;
|
|
56
66
|
}
|
|
67
|
+
// unable to create credentials
|
|
68
|
+
else {
|
|
69
|
+
printMessage(`Unable to create log api credentials.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (foundCredentials) {
|
|
57
73
|
const now = Date.now() / 1000;
|
|
58
74
|
const nowString = new Date(now * 1000).toISOString();
|
|
59
75
|
if (typeof options.beginTimestamp === 'undefined' || !options.beginTimestamp) {
|
|
@@ -76,16 +92,16 @@ Cannot be more than 30 days in the past. If not specified, logs from one hour ag
|
|
|
76
92
|
const endTs = Date.parse(options.endTimestamp) / 1000;
|
|
77
93
|
if (endTs < beginTs) {
|
|
78
94
|
printMessage('End timestamp can not be before begin timestamp', 'error');
|
|
95
|
+
process.exitCode = 1;
|
|
79
96
|
return;
|
|
80
97
|
}
|
|
81
98
|
if (now - beginTs > LOG_TIME_WINDOW_MAX) {
|
|
82
99
|
printMessage('Begin timestamp can not be more than 30 days in the past', 'error');
|
|
100
|
+
process.exitCode = 1;
|
|
83
101
|
return;
|
|
84
102
|
}
|
|
85
103
|
let intermediateEndTs = 0;
|
|
86
104
|
printMessage(`Fetching ID Cloud logs from the following sources: ${command.opts().sources} and levels [${resolveLevel(command.opts().level)}] of ${conn.tenant}...`);
|
|
87
|
-
if (credsFromParameters) await saveConnectionProfile(host); // save new values if they were specified on CLI
|
|
88
|
-
|
|
89
105
|
let timeIncrement = LOG_TIME_WINDOW_INCREMENT;
|
|
90
106
|
if (endTs - beginTs > 30) {
|
|
91
107
|
timeIncrement = timeIncrement * 30;
|
|
@@ -96,6 +112,12 @@ Cannot be more than 30 days in the past. If not specified, logs from one hour ag
|
|
|
96
112
|
beginTs = intermediateEndTs;
|
|
97
113
|
} while (intermediateEndTs < endTs);
|
|
98
114
|
}
|
|
115
|
+
// no log api credentials
|
|
116
|
+
else {
|
|
117
|
+
printMessage('No log api credentials found!');
|
|
118
|
+
program.help();
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
}
|
|
99
121
|
});
|
|
100
122
|
program.parse();
|
|
101
123
|
//# sourceMappingURL=log-fetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-fetch.js","names":["frodo","state","Option","fetchLogs","provisionCreds","config","printMessage","FrodoCommand","sourcesOptionM","getTokens","login","resolveLevel","cloud","log","getConnectionProfile","saveConnectionProfile","conn","SECONDS_IN_30_DAYS","SECONDS_IN_1_HOUR","LOG_TIME_WINDOW_MAX","LOG_TIME_WINDOW_INCREMENT","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","creds","api_key_id","api_key_secret","now","Date","nowString","toISOString","beginTimestamp","tempStartDate","setTime","tempEndDate","endTimestamp","beginTs","parse","endTs","intermediateEndTs","opts","sources","level","timeIncrement","transactionId","searchString","getNoiseFilters","defaults"],"sources":["../../../src/cli/log/log-fetch.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { Option } from 'commander';\n\nimport { fetchLogs, provisionCreds } from '../../ops/LogOps';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\nimport { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './log';\n\nconst { getTokens } = frodo.login;\nconst { resolveLevel } = frodo.cloud.log;\nconst { getConnectionProfile, saveConnectionProfile } = frodo.conn;\n\nconst SECONDS_IN_30_DAYS = 2592000;\nconst SECONDS_IN_1_HOUR = 3600;\nconst LOG_TIME_WINDOW_MAX = SECONDS_IN_30_DAYS;\nconst LOG_TIME_WINDOW_INCREMENT = 1;\n\nconst program = new FrodoCommand('frodo log fetch', ['realm', 'type']);\nprogram\n .description(\n 'Fetch Identity Cloud logs between a specified begin and end time period.\\\n WARNING: depending on filters and time period specified, this could take substantial time to complete.'\n )\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', `${resolveLevel('ERROR')}`)\n )\n .addOption(\n new Option('-t, --transaction-id <txid>', 'Filter by transactionId')\n )\n .addOption(\n new Option(\n '-b, --begin-timestamp <beginTs>',\n 'Begin timestamp for period (in ISO8601, example: \"2022-10-13T19:06:28Z\", or \"2022-09.30\". \\\nCannot be more than 30 days in the past. If not specified, logs from one hour ago are fetched \\\n(-e is ignored)'\n )\n )\n .addOption(\n new Option(\n '-e, --end-timestamp <endTs>',\n 'End timestamp for period. Default: \"now\"'\n )\n )\n .addOption(\n new Option(\n '-s, --search-string <ss>',\n 'Filter by a specific string (ANDed with transactionID filter)'\n )\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 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 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 const now = Date.now() / 1000;\n const nowString = new Date(now * 1000).toISOString();\n if (\n typeof options.beginTimestamp === 'undefined' ||\n !options.beginTimestamp\n ) {\n // no beginTimestamp value specified, default is 1 hour ago\n const tempStartDate = new Date();\n tempStartDate.setTime((now - SECONDS_IN_1_HOUR) * 1000);\n options.beginTimestamp = tempStartDate.toISOString();\n // also override endTimestamp to now\n const tempEndDate = new Date();\n tempEndDate.setTime(now * 1000);\n options.endTimestamp = tempEndDate;\n printMessage(\n 'No timestamps specified, defaulting to logs from 1 hour ago',\n 'info'\n );\n }\n if (\n typeof options.endTimestamp === 'undefined' ||\n !options.endTimestamp\n ) {\n // no endTimestamp value specified, default is now\n options.endTimestamp = nowString;\n printMessage(\n 'No end timestamp specified, defaulting end timestamp to \"now\"',\n 'info'\n );\n }\n let beginTs = Date.parse(options.beginTimestamp) / 1000;\n const endTs = Date.parse(options.endTimestamp) / 1000;\n if (endTs < beginTs) {\n printMessage(\n 'End timestamp can not be before begin timestamp',\n 'error'\n );\n return;\n }\n if (now - beginTs > LOG_TIME_WINDOW_MAX) {\n printMessage(\n 'Begin timestamp can not be more than 30 days in the past',\n 'error'\n );\n return;\n }\n let intermediateEndTs = 0;\n printMessage(\n `Fetching ID Cloud logs from the following sources: ${\n command.opts().sources\n } and levels [${resolveLevel(command.opts().level)}] of ${\n conn.tenant\n }...`\n );\n if (credsFromParameters) await saveConnectionProfile(host); // save new values if they were specified on CLI\n\n let timeIncrement = LOG_TIME_WINDOW_INCREMENT;\n if (endTs - beginTs > 30) {\n timeIncrement = timeIncrement * 30;\n }\n do {\n intermediateEndTs = beginTs + timeIncrement;\n await fetchLogs(\n command.opts().sources,\n new Date(beginTs * 1000).toISOString(),\n new Date(intermediateEndTs * 1000).toISOString(),\n resolveLevel(command.opts().level),\n command.opts().transactionId,\n command.opts().searchString,\n null,\n config.getNoiseFilters(options.defaults)\n );\n beginTs = intermediateEndTs;\n } while (intermediateEndTs < endTs);\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,SAAS,EAAEC,cAAc,QAAQ,kBAAkB;AAC5D,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAC5C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,OAAO;AAEtC,MAAM;EAAEC;AAAU,CAAC,GAAGT,KAAK,CAACU,KAAK;AACjC,MAAM;EAAEC;AAAa,CAAC,GAAGX,KAAK,CAACY,KAAK,CAACC,GAAG;AACxC,MAAM;EAAEC,oBAAoB;EAAEC;AAAsB,CAAC,GAAGf,KAAK,CAACgB,IAAI;AAElE,MAAMC,kBAAkB,GAAG,OAAO;AAClC,MAAMC,iBAAiB,GAAG,IAAI;AAC9B,MAAMC,mBAAmB,GAAGF,kBAAkB;AAC9C,MAAMG,yBAAyB,GAAG,CAAC;AAEnC,MAAMC,OAAO,GAAG,IAAId,YAAY,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtEc,OAAO,CACJC,WAAW,CACV;AACJ,wGACE,CAAC,CACAC,SAAS,CAACf,cAAc,CA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AG,IAAI,CAAC,CAACN,WAAW,CAAC,CAAC,EACtC,IAAIF,IAAI,CAACW,iBAAiB,GAAG,IAAI,CAAC,CAACT,WAAW,CAAC,CAAC,EAChDxC,YAAY,CAACoB,OAAO,CAAC8B,IAAI,CAAC,CAAC,CAACE,KAAK,CAAC,EAClChC,OAAO,CAAC8B,IAAI,CAAC,CAAC,CAACI,aAAa,EAC5BlC,OAAO,CAAC8B,IAAI,CAAC,CAAC,CAACK,YAAY,EAC3B,IAAI,EACJ7D,MAAM,CAAC8D,eAAe,CAACrC,OAAO,CAACsC,QAAQ,CACzC,CAAC;MACDX,OAAO,GAAGG,iBAAiB;IAC7B,CAAC,QAAQA,iBAAiB,GAAGD,KAAK;EACpC;AACF,CAAC,CAAC;AAEJtC,OAAO,CAACqC,KAAK,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"log-fetch.js","names":["frodo","state","Option","fetchLogs","provisionCreds","config","printMessage","verboseMessage","FrodoCommand","sourcesOptionM","getTokens","login","resolveLevel","cloud","log","getConnectionProfile","saveConnectionProfile","conn","SECONDS_IN_30_DAYS","SECONDS_IN_1_HOUR","LOG_TIME_WINDOW_MAX","LOG_TIME_WINDOW_INCREMENT","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","foundCredentials","setHost","tenant","getUsername","getPassword","setLogApiKey","setLogApiSecret","logApiKey","logApiSecret","getLogApiKey","getLogApiSecret","username","setUsername","setPassword","creds","api_key_id","api_key_secret","getHost","now","Date","nowString","toISOString","beginTimestamp","tempStartDate","setTime","tempEndDate","endTimestamp","beginTs","parse","endTs","process","exitCode","intermediateEndTs","opts","sources","level","timeIncrement","transactionId","searchString","getNoiseFilters","defaults","help"],"sources":["../../../src/cli/log/log-fetch.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { Option } from 'commander';\n\nimport { fetchLogs, provisionCreds } from '../../ops/LogOps';\nimport * as config from '../../utils/Config';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './log';\n\nconst { getTokens } = frodo.login;\nconst { resolveLevel } = frodo.cloud.log;\nconst { getConnectionProfile, saveConnectionProfile } = frodo.conn;\n\nconst SECONDS_IN_30_DAYS = 2592000;\nconst SECONDS_IN_1_HOUR = 3600;\nconst LOG_TIME_WINDOW_MAX = SECONDS_IN_30_DAYS;\nconst LOG_TIME_WINDOW_INCREMENT = 1;\n\nconst program = new FrodoCommand('frodo log fetch', ['realm', 'type']);\nprogram\n .description(\n 'Fetch Identity Cloud logs between a specified begin and end time period.\\\n WARNING: depending on filters and time period specified, this could take substantial time to complete.'\n )\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', `${resolveLevel('ERROR')}`)\n )\n .addOption(\n new Option('-t, --transaction-id <txid>', 'Filter by transactionId')\n )\n .addOption(\n new Option(\n '-b, --begin-timestamp <beginTs>',\n 'Begin timestamp for period (in ISO8601, example: \"2022-10-13T19:06:28Z\", or \"2022-09.30\". \\\nCannot be more than 30 days in the past. If not specified, logs from one hour ago are fetched \\\n(-e is ignored)'\n )\n )\n .addOption(\n new Option(\n '-e, --end-timestamp <endTs>',\n 'End timestamp for period. Default: \"now\"'\n )\n )\n .addOption(\n new Option(\n '-s, --search-string <ss>',\n 'Filter by a specific string (ANDed with transactionID filter)'\n )\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\n let foundCredentials = false;\n\n const conn = await getConnectionProfile();\n if (conn) state.setHost(conn.tenant);\n\n // log api creds have been supplied as username and password arguments\n if (state.getUsername() && state.getPassword()) {\n verboseMessage(`Using log api credentials from command line.`);\n state.setLogApiKey(state.getUsername());\n state.setLogApiSecret(state.getPassword());\n foundCredentials = true;\n }\n // log api creds from connection profile\n else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {\n verboseMessage(`Using log api credentials from connection profile.`);\n state.setLogApiKey(conn.logApiKey);\n state.setLogApiSecret(conn.logApiSecret);\n foundCredentials = true;\n }\n // log api creds have been supplied via env variables\n else if (state.getLogApiKey() && state.getLogApiSecret()) {\n verboseMessage(`Using log api credentials from environment variables.`);\n foundCredentials = true;\n }\n // no log api creds but got username and password, so can try to create them\n else if (conn && conn.username && conn.password) {\n printMessage(\n `Found admin credentials in connection profile, attempting to create log api credentials...`\n );\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n if (await 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 await saveConnectionProfile(state.getHost());\n foundCredentials = true;\n }\n // unable to create credentials\n else {\n printMessage(`Unable to create log api credentials.`);\n }\n }\n\n if (foundCredentials) {\n const now = Date.now() / 1000;\n const nowString = new Date(now * 1000).toISOString();\n if (\n typeof options.beginTimestamp === 'undefined' ||\n !options.beginTimestamp\n ) {\n // no beginTimestamp value specified, default is 1 hour ago\n const tempStartDate = new Date();\n tempStartDate.setTime((now - SECONDS_IN_1_HOUR) * 1000);\n options.beginTimestamp = tempStartDate.toISOString();\n // also override endTimestamp to now\n const tempEndDate = new Date();\n tempEndDate.setTime(now * 1000);\n options.endTimestamp = tempEndDate;\n printMessage(\n 'No timestamps specified, defaulting to logs from 1 hour ago',\n 'info'\n );\n }\n if (\n typeof options.endTimestamp === 'undefined' ||\n !options.endTimestamp\n ) {\n // no endTimestamp value specified, default is now\n options.endTimestamp = nowString;\n printMessage(\n 'No end timestamp specified, defaulting end timestamp to \"now\"',\n 'info'\n );\n }\n let beginTs = Date.parse(options.beginTimestamp) / 1000;\n const endTs = Date.parse(options.endTimestamp) / 1000;\n if (endTs < beginTs) {\n printMessage(\n 'End timestamp can not be before begin timestamp',\n 'error'\n );\n process.exitCode = 1;\n return;\n }\n if (now - beginTs > LOG_TIME_WINDOW_MAX) {\n printMessage(\n 'Begin timestamp can not be more than 30 days in the past',\n 'error'\n );\n process.exitCode = 1;\n return;\n }\n let intermediateEndTs = 0;\n printMessage(\n `Fetching ID Cloud logs from the following sources: ${\n command.opts().sources\n } and levels [${resolveLevel(command.opts().level)}] of ${\n conn.tenant\n }...`\n );\n\n let timeIncrement = LOG_TIME_WINDOW_INCREMENT;\n if (endTs - beginTs > 30) {\n timeIncrement = timeIncrement * 30;\n }\n do {\n intermediateEndTs = beginTs + timeIncrement;\n await fetchLogs(\n command.opts().sources,\n new Date(beginTs * 1000).toISOString(),\n new Date(intermediateEndTs * 1000).toISOString(),\n resolveLevel(command.opts().level),\n command.opts().transactionId,\n command.opts().searchString,\n null,\n config.getNoiseFilters(options.defaults)\n );\n beginTs = intermediateEndTs;\n } while (intermediateEndTs < endTs);\n }\n // no log api credentials\n else {\n printMessage('No log api credentials found!');\n program.help();\n process.exitCode = 1;\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,SAAS,EAAEC,cAAc,QAAQ,kBAAkB;AAC5D,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAC5C,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,OAAO;AAEtC,MAAM;EAAEC;AAAU,CAAC,GAAGV,KAAK,CAACW,KAAK;AACjC,MAAM;EAAEC;AAAa,CAAC,GAAGZ,KAAK,CAACa,KAAK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JnE,MAAM,CAACoE,eAAe,CAAC1C,OAAO,CAAC2C,QAAQ,CACzC,CAAC;MACDb,OAAO,GAAGK,iBAAiB;IAC7B,CAAC,QAAQA,iBAAiB,GAAGH,KAAK;EACpC;EACA;EAAA,KACK;IACHzD,YAAY,CAAC,+BAA+B,CAAC;IAC7CgB,OAAO,CAACqD,IAAI,CAAC,CAAC;IACdX,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF,CAAC,CAAC;AAEJ3C,OAAO,CAACwC,KAAK,CAAC,CAAC"}
|
package/esm/cli/log/log-list.js
CHANGED
|
@@ -15,45 +15,66 @@ const {
|
|
|
15
15
|
const program = new FrodoCommand('frodo log list', ['realm', 'type']);
|
|
16
16
|
program.description('List available ID Cloud log sources.').action(async (host, user, password, options, command) => {
|
|
17
17
|
command.handleDefaultArgsAndOpts(host, user, password, options, command);
|
|
18
|
-
let credsFromParameters = true;
|
|
19
18
|
verboseMessage('Listing available ID Cloud log sources...');
|
|
19
|
+
let foundCredentials = false;
|
|
20
20
|
const conn = await getConnectionProfile();
|
|
21
|
-
if (conn)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
21
|
+
if (conn) state.setHost(conn.tenant);
|
|
22
|
+
|
|
23
|
+
// log api creds have been supplied as username and password arguments
|
|
24
|
+
if (state.getUsername() && state.getPassword()) {
|
|
25
|
+
verboseMessage(`Using log api credentials from command line.`);
|
|
26
|
+
state.setLogApiKey(state.getUsername());
|
|
27
|
+
state.setLogApiSecret(state.getPassword());
|
|
28
|
+
foundCredentials = true;
|
|
29
|
+
}
|
|
30
|
+
// log api creds from connection profile
|
|
31
|
+
else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {
|
|
32
|
+
verboseMessage(`Using log api credentials from connection profile.`);
|
|
33
|
+
state.setLogApiKey(conn.logApiKey);
|
|
34
|
+
state.setLogApiSecret(conn.logApiSecret);
|
|
35
|
+
foundCredentials = true;
|
|
36
|
+
}
|
|
37
|
+
// log api creds have been supplied via env variables
|
|
38
|
+
else if (state.getLogApiKey() && state.getLogApiSecret()) {
|
|
39
|
+
verboseMessage(`Using log api credentials from environment variables.`);
|
|
40
|
+
foundCredentials = true;
|
|
41
|
+
}
|
|
42
|
+
// no log api creds but got username and password, so can try to create them
|
|
43
|
+
else if (conn && conn.username && conn.password) {
|
|
44
|
+
printMessage(`Found admin credentials in connection profile, attempting to create log api credentials...`);
|
|
45
|
+
state.setUsername(conn.username);
|
|
46
|
+
state.setPassword(conn.password);
|
|
47
|
+
if (await getTokens(true)) {
|
|
48
|
+
const creds = await provisionCreds();
|
|
49
|
+
state.setLogApiKey(creds.api_key_id);
|
|
50
|
+
state.setLogApiSecret(creds.api_key_secret);
|
|
51
|
+
await saveConnectionProfile(state.getHost());
|
|
52
|
+
foundCredentials = true;
|
|
53
|
+
}
|
|
54
|
+
// unable to create credentials
|
|
55
|
+
else {
|
|
56
|
+
printMessage(`Unable to create log api credentials.`);
|
|
43
57
|
}
|
|
58
|
+
}
|
|
59
|
+
if (foundCredentials) {
|
|
44
60
|
const sources = await getLogSources();
|
|
45
61
|
if (sources.length === 0) {
|
|
46
62
|
printMessage("Can't get sources, possible cause - wrong API key or secret", 'error');
|
|
47
63
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sources.forEach(source => {
|
|
64
|
+
printMessage(`Log sources from ${state.getHost()}`);
|
|
65
|
+
for (const source of sources) {
|
|
51
66
|
printMessage(`${source}`, 'data');
|
|
52
|
-
}
|
|
67
|
+
}
|
|
53
68
|
printMessage('Use any combination of comma separated sources, example:', 'info');
|
|
54
|
-
printMessage(`$ frodo logs tail -c am-core,idm-core ${
|
|
69
|
+
printMessage(`$ frodo logs tail -c am-core,idm-core ${state.getHost()}`, 'text');
|
|
55
70
|
}
|
|
56
71
|
}
|
|
72
|
+
// no log api credentials
|
|
73
|
+
else {
|
|
74
|
+
printMessage('No log api credentials found!');
|
|
75
|
+
program.help();
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
}
|
|
57
78
|
});
|
|
58
79
|
program.parse();
|
|
59
80
|
//# sourceMappingURL=log-list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-list.js","names":["frodo","state","provisionCreds","printMessage","verboseMessage","FrodoCommand","getTokens","login","getConnectionProfile","saveConnectionProfile","conn","getLogSources","cloud","log","program","description","action","host","user","password","options","command","handleDefaultArgsAndOpts","
|
|
1
|
+
{"version":3,"file":"log-list.js","names":["frodo","state","provisionCreds","printMessage","verboseMessage","FrodoCommand","getTokens","login","getConnectionProfile","saveConnectionProfile","conn","getLogSources","cloud","log","program","description","action","host","user","password","options","command","handleDefaultArgsAndOpts","foundCredentials","setHost","tenant","getUsername","getPassword","setLogApiKey","setLogApiSecret","logApiKey","logApiSecret","getLogApiKey","getLogApiSecret","username","setUsername","setPassword","creds","api_key_id","api_key_secret","getHost","sources","length","source","help","process","exitCode","parse"],"sources":["../../../src/cli/log/log-list.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\n\nimport { provisionCreds } from '../../ops/LogOps';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport { FrodoCommand } from '../FrodoCommand';\n\nconst { getTokens } = frodo.login;\nconst { getConnectionProfile, saveConnectionProfile } = frodo.conn;\nconst { getLogSources } = frodo.cloud.log;\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\n verboseMessage('Listing available ID Cloud log sources...');\n\n let foundCredentials = false;\n\n const conn = await getConnectionProfile();\n if (conn) state.setHost(conn.tenant);\n\n // log api creds have been supplied as username and password arguments\n if (state.getUsername() && state.getPassword()) {\n verboseMessage(`Using log api credentials from command line.`);\n state.setLogApiKey(state.getUsername());\n state.setLogApiSecret(state.getPassword());\n foundCredentials = true;\n }\n // log api creds from connection profile\n else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {\n verboseMessage(`Using log api credentials from connection profile.`);\n state.setLogApiKey(conn.logApiKey);\n state.setLogApiSecret(conn.logApiSecret);\n foundCredentials = true;\n }\n // log api creds have been supplied via env variables\n else if (state.getLogApiKey() && state.getLogApiSecret()) {\n verboseMessage(`Using log api credentials from environment variables.`);\n foundCredentials = true;\n }\n // no log api creds but got username and password, so can try to create them\n else if (conn && conn.username && conn.password) {\n printMessage(\n `Found admin credentials in connection profile, attempting to create log api credentials...`\n );\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n if (await 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 await saveConnectionProfile(state.getHost());\n foundCredentials = true;\n }\n // unable to create credentials\n else {\n printMessage(`Unable to create log api credentials.`);\n }\n }\n\n if (foundCredentials) {\n const sources = await 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 printMessage(`Log sources from ${state.getHost()}`);\n for (const source of sources) {\n printMessage(`${source}`, 'data');\n }\n printMessage(\n 'Use any combination of comma separated sources, example:',\n 'info'\n );\n printMessage(\n `$ frodo logs tail -c am-core,idm-core ${state.getHost()}`,\n 'text'\n );\n }\n }\n // no log api credentials\n else {\n printMessage('No log api credentials found!');\n program.help();\n process.exitCode = 1;\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SAASC,YAAY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,IAAIF,OAAO,EAAE;QAC5BtC,YAAY,CAAE,GAAEwC,MAAO,EAAC,EAAE,MAAM,CAAC;MACnC;MACAxC,YAAY,CACV,0DAA0D,EAC1D,MACF,CAAC;MACDA,YAAY,CACT,yCAAwCF,KAAK,CAACuC,OAAO,CAAC,CAAE,EAAC,EAC1D,MACF,CAAC;IACH;EACF;EACA;EAAA,KACK;IACHrC,YAAY,CAAC,+BAA+B,CAAC;IAC7CW,OAAO,CAAC8B,IAAI,CAAC,CAAC;IACdC,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF,CAAC,CAAC;AAEJhC,OAAO,CAACiC,KAAK,CAAC,CAAC"}
|
package/esm/cli/log/log-tail.js
CHANGED
|
@@ -2,7 +2,7 @@ import { frodo, state } from '@rockcarver/frodo-lib';
|
|
|
2
2
|
import { Option } from 'commander';
|
|
3
3
|
import { provisionCreds, tailLogs } from '../../ops/LogOps';
|
|
4
4
|
import * as config from '../../utils/Config';
|
|
5
|
-
import { printMessage } from '../../utils/Console';
|
|
5
|
+
import { printMessage, verboseMessage } from '../../utils/Console';
|
|
6
6
|
import { FrodoCommand } from '../FrodoCommand';
|
|
7
7
|
import { sourcesOptionM } from './log';
|
|
8
8
|
const {
|
|
@@ -22,35 +22,56 @@ Following values are possible (values on the same line are equivalent): \
|
|
|
22
22
|
\n2, INFO or INFORMATION\n3, DEBUG, FINE, FINER or FINEST\
|
|
23
23
|
\n4 or ALL').default('ERROR', `${resolveLevel('ERROR')}`)).addOption(new Option('-t, --transaction-id <txid>', 'Filter by transactionId')).addOption(new Option('-d, --defaults', 'Use default logging noise filters').default(false, `Use custom logging noise filters defined in $HOME/${config.FRODO_LOG_NOISEFILTER_FILENAME}`)).action(async (host, user, password, options, command) => {
|
|
24
24
|
command.handleDefaultArgsAndOpts(host, user, password, options, command);
|
|
25
|
-
let
|
|
25
|
+
let foundCredentials = false;
|
|
26
26
|
const conn = await getConnectionProfile();
|
|
27
|
-
if (conn)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
27
|
+
if (conn) state.setHost(conn.tenant);
|
|
28
|
+
|
|
29
|
+
// log api creds have been supplied as username and password arguments
|
|
30
|
+
if (state.getUsername() && state.getPassword()) {
|
|
31
|
+
verboseMessage(`Using log api credentials from command line.`);
|
|
32
|
+
state.setLogApiKey(state.getUsername());
|
|
33
|
+
state.setLogApiSecret(state.getPassword());
|
|
34
|
+
foundCredentials = true;
|
|
35
|
+
}
|
|
36
|
+
// log api creds from connection profile
|
|
37
|
+
else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {
|
|
38
|
+
verboseMessage(`Using log api credentials from connection profile.`);
|
|
39
|
+
state.setLogApiKey(conn.logApiKey);
|
|
40
|
+
state.setLogApiSecret(conn.logApiSecret);
|
|
41
|
+
foundCredentials = true;
|
|
42
|
+
}
|
|
43
|
+
// log api creds have been supplied via env variables
|
|
44
|
+
else if (state.getLogApiKey() && state.getLogApiSecret()) {
|
|
45
|
+
verboseMessage(`Using log api credentials from environment variables.`);
|
|
46
|
+
foundCredentials = true;
|
|
47
|
+
}
|
|
48
|
+
// no log api creds but got username and password, so can try to create them
|
|
49
|
+
else if (conn && conn.username && conn.password) {
|
|
50
|
+
printMessage(`Found admin credentials in connection profile, attempting to create log api credentials...`);
|
|
51
|
+
state.setUsername(conn.username);
|
|
52
|
+
state.setPassword(conn.password);
|
|
53
|
+
if (await getTokens(true)) {
|
|
54
|
+
const creds = await provisionCreds();
|
|
55
|
+
state.setLogApiKey(creds.api_key_id);
|
|
56
|
+
state.setLogApiSecret(creds.api_key_secret);
|
|
57
|
+
await saveConnectionProfile(state.getHost());
|
|
58
|
+
foundCredentials = true;
|
|
49
59
|
}
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
// unable to create credentials
|
|
61
|
+
else {
|
|
62
|
+
printMessage(`Unable to create log api credentials.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (foundCredentials) {
|
|
66
|
+
printMessage(`Tailing ID Cloud logs from the following sources: ${options.sources} and levels [${resolveLevel(options.level)}] of ${state.getHost()}...`);
|
|
52
67
|
await tailLogs(command.opts().sources, resolveLevel(command.opts().level), command.opts().transactionId, null, config.getNoiseFilters(options.defaults));
|
|
53
68
|
}
|
|
69
|
+
// no log api credentials
|
|
70
|
+
else {
|
|
71
|
+
printMessage('No log api credentials found!');
|
|
72
|
+
program.help();
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
54
75
|
});
|
|
55
76
|
program.parse();
|
|
56
77
|
//# sourceMappingURL=log-tail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-tail.js","names":["frodo","state","Option","provisionCreds","tailLogs","config","printMessage","FrodoCommand","sourcesOptionM","getTokens","login","resolveLevel","cloud","log","getConnectionProfile","saveConnectionProfile","conn","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","
|
|
1
|
+
{"version":3,"file":"log-tail.js","names":["frodo","state","Option","provisionCreds","tailLogs","config","printMessage","verboseMessage","FrodoCommand","sourcesOptionM","getTokens","login","resolveLevel","cloud","log","getConnectionProfile","saveConnectionProfile","conn","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","foundCredentials","setHost","tenant","getUsername","getPassword","setLogApiKey","setLogApiSecret","logApiKey","logApiSecret","getLogApiKey","getLogApiSecret","username","setUsername","setPassword","creds","api_key_id","api_key_secret","getHost","sources","level","opts","transactionId","getNoiseFilters","defaults","help","process","exitCode","parse"],"sources":["../../../src/cli/log/log-tail.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { Option } from 'commander';\n\nimport { provisionCreds, tailLogs } from '../../ops/LogOps';\nimport * as config from '../../utils/Config';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './log';\n\nconst { getTokens } = frodo.login;\nconst { resolveLevel } = frodo.cloud.log;\nconst { getConnectionProfile, saveConnectionProfile } = frodo.conn;\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', `${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\n let foundCredentials = false;\n\n const conn = await getConnectionProfile();\n if (conn) state.setHost(conn.tenant);\n\n // log api creds have been supplied as username and password arguments\n if (state.getUsername() && state.getPassword()) {\n verboseMessage(`Using log api credentials from command line.`);\n state.setLogApiKey(state.getUsername());\n state.setLogApiSecret(state.getPassword());\n foundCredentials = true;\n }\n // log api creds from connection profile\n else if (conn && conn.logApiKey != null && conn.logApiSecret != null) {\n verboseMessage(`Using log api credentials from connection profile.`);\n state.setLogApiKey(conn.logApiKey);\n state.setLogApiSecret(conn.logApiSecret);\n foundCredentials = true;\n }\n // log api creds have been supplied via env variables\n else if (state.getLogApiKey() && state.getLogApiSecret()) {\n verboseMessage(`Using log api credentials from environment variables.`);\n foundCredentials = true;\n }\n // no log api creds but got username and password, so can try to create them\n else if (conn && conn.username && conn.password) {\n printMessage(\n `Found admin credentials in connection profile, attempting to create log api credentials...`\n );\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n if (await 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 await saveConnectionProfile(state.getHost());\n foundCredentials = true;\n }\n // unable to create credentials\n else {\n printMessage(`Unable to create log api credentials.`);\n }\n }\n\n if (foundCredentials) {\n printMessage(\n `Tailing ID Cloud logs from the following sources: ${\n options.sources\n } and levels [${resolveLevel(options.level)}] of ${state.getHost()}...`\n );\n await tailLogs(\n command.opts().sources,\n resolveLevel(command.opts().level),\n command.opts().transactionId,\n null,\n config.getNoiseFilters(options.defaults)\n );\n }\n // no log api credentials\n else {\n printMessage('No log api credentials found!');\n program.help();\n process.exitCode = 1;\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,cAAc,EAAEC,QAAQ,QAAQ,kBAAkB;AAC3D,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAC5C,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,OAAO;AAEtC,MAAM;EAAEC;AAAU,CAAC,GAAGV,KAAK,CAACW,KAAK;AACjC,MAAM;EAAEC;AAAa,CAAC,GAAGZ,KAAK,CAACa,KAAK,CAACC,GAAG;AACxC,MAAM;EAAEC,oBAAoB;EAAEC;AAAsB,CAAC,GAAGhB,KAAK,CAACiB,IAAI;AAElE,MAAMC,OAAO,GAAG,IAAIV,YAAY,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC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AC,CAACF,OAAO,EACtBpC,YAAY,CAACgB,OAAO,CAACsB,IAAI,CAAC,CAAC,CAACD,KAAK,CAAC,EAClCrB,OAAO,CAACsB,IAAI,CAAC,CAAC,CAACC,aAAa,EAC5B,IAAI,EACJ9C,MAAM,CAAC+C,eAAe,CAACzB,OAAO,CAAC0B,QAAQ,CACzC,CAAC;EACH;EACA;EAAA,KACK;IACH/C,YAAY,CAAC,+BAA+B,CAAC;IAC7CY,OAAO,CAACoC,IAAI,CAAC,CAAC;IACdC,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF,CAAC,CAAC;AAEJtC,OAAO,CAACuC,KAAK,CAAC,CAAC"}
|
package/esm/ops/SecretsOps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { frodo } from '@rockcarver/frodo-lib';
|
|
1
|
+
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import { createKeyValueTable, createProgressBar, createTable, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
|
|
3
3
|
import wordwrap from './utils/Wordwrap';
|
|
4
4
|
const {
|
|
@@ -37,7 +37,7 @@ export async function listSecrets(long) {
|
|
|
37
37
|
}, {
|
|
38
38
|
hAlign: 'right',
|
|
39
39
|
content: 'Loaded\nVersion'['brightCyan']
|
|
40
|
-
}, 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified'['brightCyan']]);
|
|
40
|
+
}, 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified (UTC)'['brightCyan']]);
|
|
41
41
|
for (const secret of secrets) {
|
|
42
42
|
table.push([secret._id, {
|
|
43
43
|
hAlign: 'right',
|
|
@@ -45,7 +45,7 @@ export async function listSecrets(long) {
|
|
|
45
45
|
}, {
|
|
46
46
|
hAlign: 'right',
|
|
47
47
|
content: secret.loadedVersion
|
|
48
|
-
}, secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(secret.description, 40), await resolveUserName('teammember', secret.lastChangedBy), new Date(secret.lastChangeDate).
|
|
48
|
+
}, secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(secret.description, 40), state.getUseBearerTokenForAmApis() ? secret.lastChangedBy : await resolveUserName('teammember', secret.lastChangedBy), new Date(secret.lastChangeDate).toUTCString()]);
|
|
49
49
|
}
|
|
50
50
|
printMessage(table.toString(), 'data');
|
|
51
51
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecretsOps.js","names":["frodo","createKeyValueTable","createProgressBar","createTable","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","wordwrap","resolveUserName","idm","managed","readSecrets","createSecret","_createSecret","readVersionsOfSecret","readSecret","enableVersionOfSecret","disableVersionOfSecret","createVersionOfSecret","_createVersionOfSecret","updateSecretDescription","deleteSecret","_deleteSecret","deleteVersionOfSecret","_deleteVersionOfSecret","cloud","secret","listSecrets","long","secrets","sort","a","b","_id","localeCompare","error","message","response","data","table","hAlign","content","push","activeVersion","loadedVersion","loaded","description","lastChangedBy","Date","lastChangeDate","toLocaleString","toString","forEach","id","value","encoding","useInPlaceholders","code","setSecretDescription","secretId","deleteSecrets","length","listSecretVersions","versions","statusMap","ENABLED","DISABLED","DESTROYED","version","status","createDate","describeSecret","activateVersionOfSecret","deactivateVersionOfSecret"],"sources":["../../src/ops/SecretsOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\n\nimport {\n createKeyValueTable,\n createProgressBar,\n createTable,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst { resolveUserName } = frodo.idm.managed;\nconst {\n readSecrets,\n createSecret: _createSecret,\n readVersionsOfSecret,\n readSecret,\n enableVersionOfSecret,\n disableVersionOfSecret,\n createVersionOfSecret: _createVersionOfSecret,\n updateSecretDescription,\n deleteSecret: _deleteSecret,\n deleteVersionOfSecret: _deleteVersionOfSecret,\n} = frodo.cloud.secret;\n\n/**\n * List secrets\n * @param {boolean} long Long version, all the fields\n */\nexport async function listSecrets(long) {\n let secrets = [];\n try {\n secrets = await readSecrets();\n secrets.sort((a, b) => a._id.localeCompare(b._id));\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n if (long) {\n const table = createTable([\n 'Id'['brightCyan'],\n { hAlign: 'right', content: 'Active\\nVersion'['brightCyan'] },\n { hAlign: 'right', content: 'Loaded\\nVersion'['brightCyan'] },\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified'['brightCyan'],\n ]);\n for (const secret of secrets) {\n table.push([\n secret._id,\n { hAlign: 'right', content: secret.activeVersion },\n { hAlign: 'right', content: secret.loadedVersion },\n secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(secret.description, 40),\n await resolveUserName('teammember', secret.lastChangedBy),\n new Date(secret.lastChangeDate).toLocaleString(),\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n secrets.forEach((secret) => {\n printMessage(secret._id, 'data');\n });\n }\n}\n\n/**\n * Create secret\n * @param {String} id secret id\n * @param {String} value secret value\n * @param {String} description secret description\n * @param {String} encoding secret encoding\n * @param {boolean} useInPlaceholders use secret in placeholders\n */\nexport async function createSecret(\n id,\n value,\n description,\n encoding,\n useInPlaceholders\n) {\n showSpinner(`Creating secret ${id}...`);\n try {\n await _createSecret(id, value, description, encoding, useInPlaceholders);\n succeedSpinner(`Created secret ${id}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Set description of secret\n * @param {String} secretId secret id\n * @param {String} description secret description\n */\nexport async function setSecretDescription(secretId, description) {\n showSpinner(`Setting description of secret ${secretId}...`);\n try {\n await updateSecretDescription(secretId, description);\n succeedSpinner(`Set description of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete a secret\n * @param {String} secretId secret id\n */\nexport async function deleteSecret(secretId) {\n showSpinner(`Deleting secret ${secretId}...`);\n try {\n await _deleteSecret(secretId);\n succeedSpinner(`Deleted secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete all secrets\n */\nexport async function deleteSecrets() {\n try {\n const secrets = await readSecrets();\n createProgressBar(secrets.length, `Deleting secrets...`);\n for (const secret of secrets) {\n try {\n await _deleteSecret(secret._id);\n updateProgressBar(`Deleted secret ${secret._id}`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n stopProgressBar(`Secrets deleted.`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all the versions of the secret\n * @param {String} secretId secret id\n */\nexport async function listSecretVersions(secretId) {\n let versions = [];\n try {\n versions = await readVersionsOfSecret(secretId);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n const table = createTable([\n { hAlign: 'right', content: 'Version'['brightCyan'] },\n 'Status'['brightCyan'],\n 'Loaded'['brightCyan'],\n 'Created'['brightCyan'],\n ]);\n // versions.sort((a, b) => a._id.localeCompare(b._id));\n const statusMap = {\n ENABLED: 'active'['brightGreen'],\n DISABLED: 'inactive'['brightRed'],\n DESTROYED: 'deleted'['brightRed'],\n };\n for (const version of versions) {\n table.push([\n { hAlign: 'right', content: version.version },\n statusMap[version.status],\n version.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n new Date(version.createDate).toLocaleString(),\n ]);\n }\n printMessage(table.toString());\n}\n\n/**\n * Describe a secret\n * @param {String} secretId Secret id\n */\nexport async function describeSecret(secretId) {\n const secret = await readSecret(secretId);\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], secret._id]);\n table.push(['Active Version'['brightCyan'], secret.activeVersion]);\n table.push(['Loaded Version'['brightCyan'], secret.loadedVersion]);\n table.push([\n 'Status'['brightCyan'],\n secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push(['Description'['brightCyan'], wordwrap(secret.description, 60)]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(secret.lastChangeDate).toLocaleString(),\n ]);\n table.push([\n 'Modifier'['brightCyan'],\n await resolveUserName('teammember', secret.lastChangedBy),\n ]);\n table.push(['Modifier UUID'['brightCyan'], secret.lastChangedBy]);\n table.push(['Encoding'['brightCyan'], secret.encoding]);\n table.push(['Use In Placeholders'['brightCyan'], secret.useInPlaceholders]);\n printMessage(table.toString());\n printMessage('\\nSecret Versions:');\n await listSecretVersions(secretId);\n}\n\n/**\n * Create new version of secret\n * @param {String} secretId secret id\n * @param {String} value secret value\n */\nexport async function createVersionOfSecret(secretId, value) {\n showSpinner(`Creating new version of secret ${secretId}...`);\n try {\n const version = await _createVersionOfSecret(secretId, value);\n succeedSpinner(`Created version ${version.version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Activate a version of a secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function activateVersionOfSecret(secretId, version) {\n showSpinner(`Activating version ${version} of secret ${secretId}...`);\n try {\n await enableVersionOfSecret(secretId, version);\n succeedSpinner(`Activated version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Deactivate a version of a secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function deactivateVersionOfSecret(secretId, version) {\n showSpinner(`Deactivating version ${version} of secret ${secretId}...`);\n try {\n await disableVersionOfSecret(secretId, version);\n succeedSpinner(`Deactivated version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete version of secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function deleteVersionOfSecret(secretId, version) {\n showSpinner(`Deleting version ${version} of secret ${secretId}...`);\n try {\n await _deleteVersionOfSecret(secretId, version);\n succeedSpinner(`Deleted version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC;AAAgB,CAAC,GAAGX,KAAK,CAACY,GAAG,CAACC,OAAO;AAC7C,MAAM;EACJC,WAAW;EACXC,YAAY,EAAEC,aAAa;EAC3BC,oBAAoB;EACpBC,UAAU;EACVC,qBAAqB;EACrBC,sBAAsB;EACtBC,qBAAqB,EAAEC,sBAAsB;EAC7CC,uBAAuB;EACvBC,YAAY,EAAEC,aAAa;EAC3BC,qBAAqB,EAAEC;AACzB,CAAC,GAAG3B,KAAK,CAAC4B,KAAK,CAACC,MAAM;;AAEtB;AACA;AACA;AACA;AACA,OAAO,eAAeC,WAAWA,CAACC,IAAI,EAAE;EACtC,IAAIC,OAAO,GAAG,EAAE;EAChB,IAAI;IACFA,OAAO,GAAG,MAAMlB,WAAW,CAAC,CAAC;IAC7BkB,OAAO,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,GAAG,CAACC,aAAa,CAACF,CAAC,CAACC,GAAG,CAAC,CAAC;EACpD,CAAC,CAAC,OAAOE,KAAK,EAAE;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B+D,OAAQ,cAAaT,QAAS,EAAC,CAAC;EACxE,CAAC,CAAC,OAAOxB,KAAK,EAAE;IACdlC,WAAW,CACR,UAASkC,KAAK,CAACE,QAAQ,CAACC,IAAI,CAACmB,IAAK,MAAKtB,KAAK,CAACE,QAAQ,CAACC,IAAI,CAACF,OAAQ,EACtE,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeb,qBAAqBA,CAACoC,QAAQ,EAAES,OAAO,EAAE;EAC7DjE,WAAW,CAAE,oBAAmBiE,OAAQ,cAAaT,QAAS,KAAI,CAAC;EACnE,IAAI;IACF,MAAMnC,sBAAsB,CAACmC,QAAQ,EAAES,OAAO,CAAC;IAC/C/D,cAAc,CAAE,mBAAkB+D,OAAQ,cAAaT,QAAS,EAAC,CAAC;EACpE,CAAC,CAAC,OAAOxB,KAAK,EAAE;IACdlC,WAAW,CACR,UAASkC,KAAK,CAACE,QAAQ,CAACC,IAAI,CAACmB,IAAK,MAAKtB,KAAK,CAACE,QAAQ,CAACC,IAAI,CAACF,OAAQ,EACtE,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"SecretsOps.js","names":["frodo","state","createKeyValueTable","createProgressBar","createTable","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","wordwrap","resolveUserName","idm","managed","readSecrets","createSecret","_createSecret","readVersionsOfSecret","readSecret","enableVersionOfSecret","disableVersionOfSecret","createVersionOfSecret","_createVersionOfSecret","updateSecretDescription","deleteSecret","_deleteSecret","deleteVersionOfSecret","_deleteVersionOfSecret","cloud","secret","listSecrets","long","secrets","sort","a","b","_id","localeCompare","error","message","response","data","table","hAlign","content","push","activeVersion","loadedVersion","loaded","description","getUseBearerTokenForAmApis","lastChangedBy","Date","lastChangeDate","toUTCString","toString","forEach","id","value","encoding","useInPlaceholders","code","setSecretDescription","secretId","deleteSecrets","length","listSecretVersions","versions","statusMap","ENABLED","DISABLED","DESTROYED","version","status","createDate","toLocaleString","describeSecret","activateVersionOfSecret","deactivateVersionOfSecret"],"sources":["../../src/ops/SecretsOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\n\nimport {\n createKeyValueTable,\n createProgressBar,\n createTable,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst { resolveUserName } = frodo.idm.managed;\nconst {\n readSecrets,\n createSecret: _createSecret,\n readVersionsOfSecret,\n readSecret,\n enableVersionOfSecret,\n disableVersionOfSecret,\n createVersionOfSecret: _createVersionOfSecret,\n updateSecretDescription,\n deleteSecret: _deleteSecret,\n deleteVersionOfSecret: _deleteVersionOfSecret,\n} = frodo.cloud.secret;\n\n/**\n * List secrets\n * @param {boolean} long Long version, all the fields\n */\nexport async function listSecrets(long) {\n let secrets = [];\n try {\n secrets = await readSecrets();\n secrets.sort((a, b) => a._id.localeCompare(b._id));\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n if (long) {\n const table = createTable([\n 'Id'['brightCyan'],\n { hAlign: 'right', content: 'Active\\nVersion'['brightCyan'] },\n { hAlign: 'right', content: 'Loaded\\nVersion'['brightCyan'] },\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified (UTC)'['brightCyan'],\n ]);\n for (const secret of secrets) {\n table.push([\n secret._id,\n { hAlign: 'right', content: secret.activeVersion },\n { hAlign: 'right', content: secret.loadedVersion },\n secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(secret.description, 40),\n state.getUseBearerTokenForAmApis()\n ? secret.lastChangedBy\n : await resolveUserName('teammember', secret.lastChangedBy),\n new Date(secret.lastChangeDate).toUTCString(),\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n secrets.forEach((secret) => {\n printMessage(secret._id, 'data');\n });\n }\n}\n\n/**\n * Create secret\n * @param {String} id secret id\n * @param {String} value secret value\n * @param {String} description secret description\n * @param {String} encoding secret encoding\n * @param {boolean} useInPlaceholders use secret in placeholders\n */\nexport async function createSecret(\n id,\n value,\n description,\n encoding,\n useInPlaceholders\n) {\n showSpinner(`Creating secret ${id}...`);\n try {\n await _createSecret(id, value, description, encoding, useInPlaceholders);\n succeedSpinner(`Created secret ${id}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Set description of secret\n * @param {String} secretId secret id\n * @param {String} description secret description\n */\nexport async function setSecretDescription(secretId, description) {\n showSpinner(`Setting description of secret ${secretId}...`);\n try {\n await updateSecretDescription(secretId, description);\n succeedSpinner(`Set description of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete a secret\n * @param {String} secretId secret id\n */\nexport async function deleteSecret(secretId) {\n showSpinner(`Deleting secret ${secretId}...`);\n try {\n await _deleteSecret(secretId);\n succeedSpinner(`Deleted secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete all secrets\n */\nexport async function deleteSecrets() {\n try {\n const secrets = await readSecrets();\n createProgressBar(secrets.length, `Deleting secrets...`);\n for (const secret of secrets) {\n try {\n await _deleteSecret(secret._id);\n updateProgressBar(`Deleted secret ${secret._id}`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n stopProgressBar(`Secrets deleted.`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all the versions of the secret\n * @param {String} secretId secret id\n */\nexport async function listSecretVersions(secretId) {\n let versions = [];\n try {\n versions = await readVersionsOfSecret(secretId);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n const table = createTable([\n { hAlign: 'right', content: 'Version'['brightCyan'] },\n 'Status'['brightCyan'],\n 'Loaded'['brightCyan'],\n 'Created'['brightCyan'],\n ]);\n // versions.sort((a, b) => a._id.localeCompare(b._id));\n const statusMap = {\n ENABLED: 'active'['brightGreen'],\n DISABLED: 'inactive'['brightRed'],\n DESTROYED: 'deleted'['brightRed'],\n };\n for (const version of versions) {\n table.push([\n { hAlign: 'right', content: version.version },\n statusMap[version.status],\n version.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n new Date(version.createDate).toLocaleString(),\n ]);\n }\n printMessage(table.toString());\n}\n\n/**\n * Describe a secret\n * @param {String} secretId Secret id\n */\nexport async function describeSecret(secretId) {\n const secret = await readSecret(secretId);\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], secret._id]);\n table.push(['Active Version'['brightCyan'], secret.activeVersion]);\n table.push(['Loaded Version'['brightCyan'], secret.loadedVersion]);\n table.push([\n 'Status'['brightCyan'],\n secret.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push(['Description'['brightCyan'], wordwrap(secret.description, 60)]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(secret.lastChangeDate).toLocaleString(),\n ]);\n table.push([\n 'Modifier'['brightCyan'],\n await resolveUserName('teammember', secret.lastChangedBy),\n ]);\n table.push(['Modifier UUID'['brightCyan'], secret.lastChangedBy]);\n table.push(['Encoding'['brightCyan'], secret.encoding]);\n table.push(['Use In Placeholders'['brightCyan'], secret.useInPlaceholders]);\n printMessage(table.toString());\n printMessage('\\nSecret Versions:');\n await listSecretVersions(secretId);\n}\n\n/**\n * Create new version of secret\n * @param {String} secretId secret id\n * @param {String} value secret value\n */\nexport async function createVersionOfSecret(secretId, value) {\n showSpinner(`Creating new version of secret ${secretId}...`);\n try {\n const version = await _createVersionOfSecret(secretId, value);\n succeedSpinner(`Created version ${version.version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Activate a version of a secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function activateVersionOfSecret(secretId, version) {\n showSpinner(`Activating version ${version} of secret ${secretId}...`);\n try {\n await enableVersionOfSecret(secretId, version);\n succeedSpinner(`Activated version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Deactivate a version of a secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function deactivateVersionOfSecret(secretId, version) {\n showSpinner(`Deactivating version ${version} of secret ${secretId}...`);\n try {\n await disableVersionOfSecret(secretId, version);\n succeedSpinner(`Deactivated version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete version of secret\n * @param {String} secretId secret id\n * @param {Number} version version of secret\n */\nexport async function deleteVersionOfSecret(secretId, version) {\n showSpinner(`Deleting version ${version} of secret ${secretId}...`);\n try {\n await _deleteVersionOfSecret(secretId, version);\n succeedSpinner(`Deleted version ${version} of secret ${secretId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC;AAAgB,CAAC,GAAGZ,KAAK,CAACa,GAAG,CAACC,OAAO;AAC7C,MAAM;EACJC,WAAW;EACXC,YAAY,EAAEC,aAAa;EAC3BC,oBAAoB;EACpBC,UAAU;EACVC,qBAAqB;EACrBC,sBAAsB;EACtBC,qBAAqB,EAAEC,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ServiceOps.js
CHANGED
|
@@ -52,7 +52,7 @@ export async function listServices(long = false, globalConfig = false) {
|
|
|
52
52
|
*/
|
|
53
53
|
export async function exportServicesToFile(file, globalConfig = false) {
|
|
54
54
|
const exportData = await exportServices(globalConfig);
|
|
55
|
-
let fileName = getTypedFilename(`all${titleCase(getRealmName(state.getRealm()))}Services`, `service`);
|
|
55
|
+
let fileName = getTypedFilename(`all${globalConfig ? 'Global' : titleCase(getRealmName(state.getRealm()))}Services`, `service`);
|
|
56
56
|
if (file) {
|
|
57
57
|
fileName = file;
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceOps.js","names":["frodo","state","fs","createTable","debugMessage","failSpinner","printMessage","showSpinner","succeedSpinner","getRealmName","utils","getTypedFilename","titleCase","saveJsonToFile","getWorkingDirectory","getListOfServices","exportServices","exportService","getFullServices","createServiceExportTemplate","importService","importServices","deleteFullService","deleteFullServices","service","listServices","long","globalConfig","services","sort","a","b","_id","localeCompare","table","push","name","toString","error","stack","exportServicesToFile","file","exportData","fileName","getRealm","exportServiceToFile","serviceId","exportServicesToFiles","_type","importServiceFromFile","clean","verbose","getVerbose","readFile","err","data","importData","JSON","parse","importError","_importError$response","_importError$response2","message","response","detail","importFirstServiceFromFile","Object","keys","length","_importError$response3","_importError$response4","importServicesFromFile","status","importServicesFromFiles","names","readdirSync","agentFiles","filter","toLowerCase","endsWith","deleteService","_error$response","deleteServices"],"sources":["../../src/ops/ServiceOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ServiceExportInterface } from '@rockcarver/frodo-lib/types/ops/ServiceOps';\nimport fs from 'fs';\n\nimport {\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n succeedSpinner,\n} from '../utils/Console';\n\nconst { getRealmName } = frodo.utils;\nconst { getTypedFilename, titleCase, saveJsonToFile, getWorkingDirectory } =\n frodo.utils;\nconst {\n getListOfServices,\n exportServices,\n exportService,\n getFullServices,\n createServiceExportTemplate,\n importService,\n importServices,\n deleteFullService,\n deleteFullServices,\n} = frodo.service;\n\n/**\n * List services\n */\nexport async function listServices(long = false, globalConfig = false) {\n try {\n const services = await getListOfServices(globalConfig);\n services.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Service Id', 'Service Name']);\n for (const service of services) {\n table.push([service._id, service.name]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const service of services) {\n printMessage(`${service._id}`, 'data');\n }\n }\n } catch (error) {\n printMessage(`Error listing agents - ${error}`, 'error');\n printMessage(error.stack, 'error');\n }\n}\n\n/**\n * Export all services to file\n * @param {string} file file name\n */\nexport async function exportServicesToFile(file, globalConfig = false) {\n const exportData = await exportServices(globalConfig);\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}Services`,\n `service`\n );\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, fileName);\n}\n\n/**\n * Export service to file\n * @param {string} serviceId service id\n * @param {string} file file name\n */\nexport async function exportServiceToFile(\n serviceId: string,\n file: string,\n globalConfig = false\n) {\n const exportData = await exportService(serviceId, globalConfig);\n let fileName = getTypedFilename(serviceId, `service`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, fileName);\n}\n\n/**\n * Export all services to separate files\n */\nexport async function exportServicesToFiles(globalConfig = false) {\n debugMessage(`cli.ServiceOps.exportServicesToFiles: start`);\n const services = await getFullServices(globalConfig);\n for (const service of services) {\n const fileName = getTypedFilename(service._type._id, `service`);\n const exportData = createServiceExportTemplate();\n exportData.service[service._type._id] = service;\n debugMessage(\n `cli.ServiceOps.exportServicesToFiles: exporting ${service._type._id} to ${fileName}`\n );\n saveJsonToFile(exportData, fileName);\n }\n debugMessage(`cli.ServiceOps.exportServicesToFiles: end.`);\n}\n\n/**\n * Import a service from file\n * @param {string} serviceId service id/name\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServiceFromFile(\n serviceId: string,\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [serviceId=${serviceId}, file=${file}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && importData.service[serviceId]) {\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${serviceId} not found!`);\n }\n });\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [serviceId=${serviceId}, file=${file}]`\n );\n}\n\n/**\n * Import first service from file\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importFirstServiceFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: start [file=${file}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && Object.keys(importData.service).length) {\n const serviceId = Object.keys(importData.service)[0];\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing service...`);\n failSpinner(`No service found in ${file}!`);\n }\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: end [file=${file}]`\n );\n });\n}\n\n/**\n * Import services from file\n * @param {String} file file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServiceFromFile: start [file=${file}]`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n debugMessage(`cli.ServiceOps.importServiceFromFile: importing ${file}`);\n const importData = JSON.parse(data) as ServiceExportInterface;\n try {\n await importServices(importData, clean, globalConfig);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.status, 'error');\n }\n debugMessage(`cli.ServiceOps.importServiceFromFile: end [file=${file}]`);\n });\n}\n\n/**\n * Import all services from separate files\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFiles(\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServicesFromFiles: start`);\n const names = fs.readdirSync(getWorkingDirectory());\n const agentFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.service.json')\n );\n for (const file of agentFiles) {\n await importServicesFromFile(file, clean, globalConfig);\n }\n debugMessage(`cli.ServiceOps.importServicesFromFiles: end`);\n}\n\n/**\n * Delete a service by id/name\n * @param {string} serviceId Reference to the service to delete\n */\nexport async function deleteService(serviceId: string, globalConfig = false) {\n try {\n await deleteFullService(serviceId, globalConfig);\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Delete service '${serviceId}': ${message}`, 'error');\n }\n}\n\n/**\n * Delete all services\n */\nexport async function deleteServices(globalConfig = false) {\n await deleteFullServices(globalConfig);\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,cAAc,QACT,kBAAkB;AAEzB,MAAM;EAAEC;AAAa,CAAC,GAAGT,KAAK,CAACU,KAAK;AACpC,MAAM;EAAE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AApBA,eAAA,CAAsBnB,OAAO;IAC7CxD,YAAY,CAAE,mBAAkBwC,SAAU,MAAKgB,OAAQ,EAAC,EAAE,OAAO,CAAC;EACpE;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeoB,cAAcA,CAACvD,YAAY,GAAG,KAAK,EAAE;EACzD,MAAMJ,kBAAkB,CAACI,YAAY,CAAC;AACxC"}
|
|
1
|
+
{"version":3,"file":"ServiceOps.js","names":["frodo","state","fs","createTable","debugMessage","failSpinner","printMessage","showSpinner","succeedSpinner","getRealmName","utils","getTypedFilename","titleCase","saveJsonToFile","getWorkingDirectory","getListOfServices","exportServices","exportService","getFullServices","createServiceExportTemplate","importService","importServices","deleteFullService","deleteFullServices","service","listServices","long","globalConfig","services","sort","a","b","_id","localeCompare","table","push","name","toString","error","stack","exportServicesToFile","file","exportData","fileName","getRealm","exportServiceToFile","serviceId","exportServicesToFiles","_type","importServiceFromFile","clean","verbose","getVerbose","readFile","err","data","importData","JSON","parse","importError","_importError$response","_importError$response2","message","response","detail","importFirstServiceFromFile","Object","keys","length","_importError$response3","_importError$response4","importServicesFromFile","status","importServicesFromFiles","names","readdirSync","agentFiles","filter","toLowerCase","endsWith","deleteService","_error$response","deleteServices"],"sources":["../../src/ops/ServiceOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ServiceExportInterface } from '@rockcarver/frodo-lib/types/ops/ServiceOps';\nimport fs from 'fs';\n\nimport {\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n succeedSpinner,\n} from '../utils/Console';\n\nconst { getRealmName } = frodo.utils;\nconst { getTypedFilename, titleCase, saveJsonToFile, getWorkingDirectory } =\n frodo.utils;\nconst {\n getListOfServices,\n exportServices,\n exportService,\n getFullServices,\n createServiceExportTemplate,\n importService,\n importServices,\n deleteFullService,\n deleteFullServices,\n} = frodo.service;\n\n/**\n * List services\n */\nexport async function listServices(long = false, globalConfig = false) {\n try {\n const services = await getListOfServices(globalConfig);\n services.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Service Id', 'Service Name']);\n for (const service of services) {\n table.push([service._id, service.name]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const service of services) {\n printMessage(`${service._id}`, 'data');\n }\n }\n } catch (error) {\n printMessage(`Error listing agents - ${error}`, 'error');\n printMessage(error.stack, 'error');\n }\n}\n\n/**\n * Export all services to file\n * @param {string} file file name\n */\nexport async function exportServicesToFile(file, globalConfig = false) {\n const exportData = await exportServices(globalConfig);\n let fileName = getTypedFilename(\n `all${\n globalConfig ? 'Global' : titleCase(getRealmName(state.getRealm()))\n }Services`,\n `service`\n );\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, fileName);\n}\n\n/**\n * Export service to file\n * @param {string} serviceId service id\n * @param {string} file file name\n */\nexport async function exportServiceToFile(\n serviceId: string,\n file: string,\n globalConfig = false\n) {\n const exportData = await exportService(serviceId, globalConfig);\n let fileName = getTypedFilename(serviceId, `service`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, fileName);\n}\n\n/**\n * Export all services to separate files\n */\nexport async function exportServicesToFiles(globalConfig = false) {\n debugMessage(`cli.ServiceOps.exportServicesToFiles: start`);\n const services = await getFullServices(globalConfig);\n for (const service of services) {\n const fileName = getTypedFilename(service._type._id, `service`);\n const exportData = createServiceExportTemplate();\n exportData.service[service._type._id] = service;\n debugMessage(\n `cli.ServiceOps.exportServicesToFiles: exporting ${service._type._id} to ${fileName}`\n );\n saveJsonToFile(exportData, fileName);\n }\n debugMessage(`cli.ServiceOps.exportServicesToFiles: end.`);\n}\n\n/**\n * Import a service from file\n * @param {string} serviceId service id/name\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServiceFromFile(\n serviceId: string,\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [serviceId=${serviceId}, file=${file}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && importData.service[serviceId]) {\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${serviceId} not found!`);\n }\n });\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [serviceId=${serviceId}, file=${file}]`\n );\n}\n\n/**\n * Import first service from file\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importFirstServiceFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: start [file=${file}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && Object.keys(importData.service).length) {\n const serviceId = Object.keys(importData.service)[0];\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing service...`);\n failSpinner(`No service found in ${file}!`);\n }\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: end [file=${file}]`\n );\n });\n}\n\n/**\n * Import services from file\n * @param {String} file file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServiceFromFile: start [file=${file}]`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n debugMessage(`cli.ServiceOps.importServiceFromFile: importing ${file}`);\n const importData = JSON.parse(data) as ServiceExportInterface;\n try {\n await importServices(importData, clean, globalConfig);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.status, 'error');\n }\n debugMessage(`cli.ServiceOps.importServiceFromFile: end [file=${file}]`);\n });\n}\n\n/**\n * Import all services from separate files\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFiles(\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServicesFromFiles: start`);\n const names = fs.readdirSync(getWorkingDirectory());\n const agentFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.service.json')\n );\n for (const file of agentFiles) {\n await importServicesFromFile(file, clean, globalConfig);\n }\n debugMessage(`cli.ServiceOps.importServicesFromFiles: end`);\n}\n\n/**\n * Delete a service by id/name\n * @param {string} serviceId Reference to the service to delete\n */\nexport async function deleteService(serviceId: string, globalConfig = false) {\n try {\n await deleteFullService(serviceId, globalConfig);\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Delete service '${serviceId}': ${message}`, 'error');\n }\n}\n\n/**\n * Delete all services\n */\nexport async function deleteServices(globalConfig = false) {\n await deleteFullServices(globalConfig);\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,cAAc,QACT,kBAAkB;AAEzB,MAAM;EAAEC;AAAa,CAAC,GAAGT,KAAK,CAACU,KAAK;AACpC,MAAM;EAAEC,gBAAgB;EAAEC,SAAS;EAAEC,cAAc;EAAEC;AAAoB,CAAC,GACxEd,KAAK,CAACU,KAAK;AACb,MAAM;EACJK,iBAAiB;EACjBC,cAAc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AAO,CAAC;EACpE;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeoB,cAAcA,CAACvD,YAAY,GAAG,KAAK,EAAE;EACzD,MAAMJ,kBAAkB,CAACI,YAAY,CAAC;AACxC"}
|
package/esm/ops/VariablesOps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { frodo } from '@rockcarver/frodo-lib';
|
|
1
|
+
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import { createKeyValueTable, createProgressBar, createTable, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
|
|
3
3
|
import wordwrap from './utils/Wordwrap';
|
|
4
4
|
const {
|
|
@@ -27,9 +27,9 @@ export async function listVariables(long) {
|
|
|
27
27
|
printMessage(error.response.data, 'error');
|
|
28
28
|
}
|
|
29
29
|
if (long) {
|
|
30
|
-
const table = createTable(['Id'['brightCyan'], 'Value'['brightCyan'], 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified'['brightCyan']]);
|
|
30
|
+
const table = createTable(['Id'['brightCyan'], 'Value'['brightCyan'], 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified (UTC)'['brightCyan']]);
|
|
31
31
|
for (const variable of variables) {
|
|
32
|
-
table.push([variable._id, wordwrap(decodeBase64(variable.valueBase64), 40), variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(variable.description, 40), await resolveUserName('teammember', variable.lastChangedBy), new Date(variable.lastChangeDate).
|
|
32
|
+
table.push([variable._id, wordwrap(decodeBase64(variable.valueBase64), 40), variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(variable.description, 40), state.getUseBearerTokenForAmApis() ? variable.lastChangedBy : await resolveUserName('teammember', variable.lastChangedBy), new Date(variable.lastChangeDate).toUTCString()]);
|
|
33
33
|
}
|
|
34
34
|
printMessage(table.toString(), 'data');
|
|
35
35
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablesOps.js","names":["frodo","createKeyValueTable","createProgressBar","createTable","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","wordwrap","decodeBase64","utils","resolveUserName","idm","managed","readVariables","readVariable","updateVariable","_updateVariable","cloud","variable","listVariables","long","variables","sort","a","b","_id","localeCompare","error","message","response","data","table","push","valueBase64","loaded","description","lastChangedBy","Date","lastChangeDate","toLocaleString","toString","forEach","secret","createVariable","variableId","value","type","code","setVariableDescription","deleteVariable","deleteVariables","length","describeVariable"],"sources":["../../src/ops/VariablesOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { VariableExpressionType } from '@rockcarver/frodo-lib/types/api/cloud/VariablesApi';\n\nimport {\n createKeyValueTable,\n createProgressBar,\n createTable,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst { decodeBase64 } = frodo.utils;\nconst { resolveUserName } = frodo.idm.managed;\nconst {\n readVariables,\n readVariable,\n updateVariable: _updateVariable,\n} = frodo.cloud.variable;\n\n/**\n * List variables\n * @param {boolean} long Long version, all the fields\n */\nexport async function listVariables(long) {\n let variables = [];\n try {\n variables = await readVariables();\n variables.sort((a, b) => a._id.localeCompare(b._id));\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n if (long) {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Value'['brightCyan'],\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified'['brightCyan'],\n ]);\n for (const variable of variables) {\n table.push([\n variable._id,\n wordwrap(decodeBase64(variable.valueBase64), 40),\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(variable.description, 40),\n await resolveUserName('teammember', variable.lastChangedBy),\n new Date(variable.lastChangeDate).toLocaleString(),\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n variables.forEach((secret) => {\n printMessage(secret._id, 'data');\n });\n }\n}\n\n/**\n * Create variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @param {VariableExpressionType} type variable type\n */\nexport async function createVariable(\n variableId: string,\n value: string,\n description: string,\n type: VariableExpressionType = 'string'\n) {\n showSpinner(`Creating variable ${variableId}...`);\n try {\n await _updateVariable(variableId, value, description, type);\n succeedSpinner(`Created variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Update variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n */\nexport async function updateVariable(variableId, value, description) {\n showSpinner(`Updating variable ${variableId}...`);\n try {\n await _updateVariable(variableId, value, description);\n succeedSpinner(`Updated variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Set description of variable\n * @param {string} variableId variable id\n * @param {string} description variable description\n */\nexport async function setVariableDescription(variableId, description) {\n showSpinner(`Setting description of variable ${variableId}...`);\n try {\n await setVariableDescription(variableId, description);\n succeedSpinner(`Set description of variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete a variable\n * @param {string} variableId variable id\n */\nexport async function deleteVariable(variableId) {\n showSpinner(`Deleting variable ${variableId}...`);\n try {\n await deleteVariable(variableId);\n succeedSpinner(`Deleted variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete all variables\n */\nexport async function deleteVariables() {\n try {\n const variables = await readVariables();\n createProgressBar(variables.length, `Deleting variable...`);\n for (const variable of variables) {\n try {\n await deleteVariable(variable._id);\n updateProgressBar(`Deleted variable ${variable._id}`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n stopProgressBar(`Variables deleted.`);\n } catch (error) {\n stopProgressBar(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n}\n\n/**\n * Describe a variable\n * @param {string} variableId variable id\n */\nexport async function describeVariable(variableId) {\n const variable = await readVariable(variableId);\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], variable._id]);\n table.push([\n 'Value'['brightCyan'],\n wordwrap(decodeBase64(variable.valueBase64), 40),\n ]);\n table.push([\n 'Status'['brightCyan'],\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push(['Description'['brightCyan'], wordwrap(variable.description, 60)]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(variable.lastChangeDate).toLocaleString(),\n ]);\n table.push([\n 'Modifier'['brightCyan'],\n await resolveUserName('teammember', variable.lastChangedBy),\n ]);\n table.push(['Modifier UUID'['brightCyan'], variable.lastChangedBy]);\n printMessage(table.toString());\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAG7C,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC;AAAa,CAAC,GAAGX,KAAK,CAACY,KAAK;AACpC,MAAM;EAAEC;AAAgB,CAAC,GAAGb,KAAK,CAACc,GAAG,CAACC,OAAO;AAC7C,MAAM;EACJC,aAAa;EACbC,YAAY;EACZC,cAAc,EAAEC;AAClB,CAAC,GAAGnB,KAAK,CAACoB,KAAK,CAACC,QAAQ;;AAExB;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CAACC,IAAI,EAAE;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AC,CAACC,cAAc,CAAC,CAAC,CACnD,CAAC;EACFR,KAAK,CAACC,IAAI,CAAC,CACT,UAAU,CAAC,YAAY,CAAC,EACxB,MAAMtB,eAAe,CAAC,YAAY,EAAEQ,QAAQ,CAACkB,aAAa,CAAC,CAC5D,CAAC;EACFL,KAAK,CAACC,IAAI,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,EAAEd,QAAQ,CAACkB,aAAa,CAAC,CAAC;EACnElC,YAAY,CAAC6B,KAAK,CAACS,QAAQ,CAAC,CAAC,CAAC;AAChC"}
|
|
1
|
+
{"version":3,"file":"VariablesOps.js","names":["frodo","state","createKeyValueTable","createProgressBar","createTable","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","wordwrap","decodeBase64","utils","resolveUserName","idm","managed","readVariables","readVariable","updateVariable","_updateVariable","cloud","variable","listVariables","long","variables","sort","a","b","_id","localeCompare","error","message","response","data","table","push","valueBase64","loaded","description","getUseBearerTokenForAmApis","lastChangedBy","Date","lastChangeDate","toUTCString","toString","forEach","secret","createVariable","variableId","value","type","code","setVariableDescription","deleteVariable","deleteVariables","length","describeVariable","toLocaleString"],"sources":["../../src/ops/VariablesOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { VariableExpressionType } from '@rockcarver/frodo-lib/types/api/cloud/VariablesApi';\n\nimport {\n createKeyValueTable,\n createProgressBar,\n createTable,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst { decodeBase64 } = frodo.utils;\nconst { resolveUserName } = frodo.idm.managed;\nconst {\n readVariables,\n readVariable,\n updateVariable: _updateVariable,\n} = frodo.cloud.variable;\n\n/**\n * List variables\n * @param {boolean} long Long version, all the fields\n */\nexport async function listVariables(long) {\n let variables = [];\n try {\n variables = await readVariables();\n variables.sort((a, b) => a._id.localeCompare(b._id));\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n if (long) {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Value'['brightCyan'],\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified (UTC)'['brightCyan'],\n ]);\n for (const variable of variables) {\n table.push([\n variable._id,\n wordwrap(decodeBase64(variable.valueBase64), 40),\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(variable.description, 40),\n state.getUseBearerTokenForAmApis()\n ? variable.lastChangedBy\n : await resolveUserName('teammember', variable.lastChangedBy),\n new Date(variable.lastChangeDate).toUTCString(),\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n variables.forEach((secret) => {\n printMessage(secret._id, 'data');\n });\n }\n}\n\n/**\n * Create variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @param {VariableExpressionType} type variable type\n */\nexport async function createVariable(\n variableId: string,\n value: string,\n description: string,\n type: VariableExpressionType = 'string'\n) {\n showSpinner(`Creating variable ${variableId}...`);\n try {\n await _updateVariable(variableId, value, description, type);\n succeedSpinner(`Created variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Update variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n */\nexport async function updateVariable(variableId, value, description) {\n showSpinner(`Updating variable ${variableId}...`);\n try {\n await _updateVariable(variableId, value, description);\n succeedSpinner(`Updated variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Set description of variable\n * @param {string} variableId variable id\n * @param {string} description variable description\n */\nexport async function setVariableDescription(variableId, description) {\n showSpinner(`Setting description of variable ${variableId}...`);\n try {\n await setVariableDescription(variableId, description);\n succeedSpinner(`Set description of variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete a variable\n * @param {string} variableId variable id\n */\nexport async function deleteVariable(variableId) {\n showSpinner(`Deleting variable ${variableId}...`);\n try {\n await deleteVariable(variableId);\n succeedSpinner(`Deleted variable ${variableId}`);\n } catch (error) {\n failSpinner(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n }\n}\n\n/**\n * Delete all variables\n */\nexport async function deleteVariables() {\n try {\n const variables = await readVariables();\n createProgressBar(variables.length, `Deleting variable...`);\n for (const variable of variables) {\n try {\n await deleteVariable(variable._id);\n updateProgressBar(`Deleted variable ${variable._id}`);\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n stopProgressBar(`Variables deleted.`);\n } catch (error) {\n stopProgressBar(\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n}\n\n/**\n * Describe a variable\n * @param {string} variableId variable id\n */\nexport async function describeVariable(variableId) {\n const variable = await readVariable(variableId);\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], variable._id]);\n table.push([\n 'Value'['brightCyan'],\n wordwrap(decodeBase64(variable.valueBase64), 40),\n ]);\n table.push([\n 'Status'['brightCyan'],\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push(['Description'['brightCyan'], wordwrap(variable.description, 60)]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(variable.lastChangeDate).toLocaleString(),\n ]);\n table.push([\n 'Modifier'['brightCyan'],\n await resolveUserName('teammember', variable.lastChangedBy),\n ]);\n table.push(['Modifier UUID'['brightCyan'], variable.lastChangedBy]);\n printMessage(table.toString());\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAGpD,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,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rBzB,QAAQ,CAACC,YAAY,CAACU,QAAQ,CAACe,WAAW,CAAC,EAAE,EAAE,CAAC,CACjD,CAAC;EACFF,KAAK,CAACC,IAAI,CAAC,CACT,QAAQ,CAAC,YAAY,CAAC,EACtBd,QAAQ,CAACgB,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CACpE,CAAC;EACFH,KAAK,CAACC,IAAI,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,EAAEzB,QAAQ,CAACW,QAAQ,CAACiB,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;EAC7EJ,KAAK,CAACC,IAAI,CAAC,CACT,UAAU,CAAC,YAAY,CAAC,EACxB,IAAIM,IAAI,CAACpB,QAAQ,CAACqB,cAAc,CAAC,CAACe,cAAc,CAAC,CAAC,CACnD,CAAC;EACFvB,KAAK,CAACC,IAAI,CAAC,CACT,UAAU,CAAC,YAAY,CAAC,EACxB,MAAMtB,eAAe,CAAC,YAAY,EAAEQ,QAAQ,CAACmB,aAAa,CAAC,CAC5D,CAAC;EACFN,KAAK,CAACC,IAAI,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,EAAEd,QAAQ,CAACmB,aAAa,CAAC,CAAC;EACnEnC,YAAY,CAAC6B,KAAK,CAACU,QAAQ,CAAC,CAAC,CAAC;AAChC"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { frodo
|
|
1
|
+
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { lstat, readdir, readFile } from 'fs/promises';
|
|
4
4
|
import { join } from 'path';
|
|
5
|
-
import slugify from 'slugify';
|
|
6
5
|
import { printMessage } from './Console';
|
|
7
|
-
const {
|
|
8
|
-
stringify,
|
|
9
|
-
deleteDeepByKey
|
|
10
|
-
} = frodo.utils.json;
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* find all (nested) files in a directory
|
|
@@ -34,61 +29,14 @@ export async function readFiles(baseDirectory, childDirectory = '') {
|
|
|
34
29
|
return filePathsNested.flat();
|
|
35
30
|
}
|
|
36
31
|
const {
|
|
37
|
-
getMetadata
|
|
32
|
+
getMetadata,
|
|
33
|
+
getTypedFilename,
|
|
34
|
+
saveJsonToFile,
|
|
35
|
+
saveToFile,
|
|
36
|
+
titleCase,
|
|
37
|
+
getRealmString
|
|
38
38
|
} = frodo.utils;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get a typed filename. E.g. "my-script.script.json"
|
|
42
|
-
*
|
|
43
|
-
* @param name The name of the file
|
|
44
|
-
* @param type The type of the file, e.g. script, idp, etc.
|
|
45
|
-
* @param suffix The suffix of the file, e.g. json, xml, etc. Defaults to json.
|
|
46
|
-
* @returns The typed filename
|
|
47
|
-
*/
|
|
48
|
-
export function getTypedFilename(name, type, suffix = 'json') {
|
|
49
|
-
const slug = slugify(name.replace(/^http(s?):\/\//, ''));
|
|
50
|
-
return `${slug}.${type}.${suffix}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Save JSON object to file
|
|
55
|
-
*
|
|
56
|
-
* @param data data object
|
|
57
|
-
* @param filename file name
|
|
58
|
-
*/
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
export function saveJsonToFile(data, filename) {
|
|
61
|
-
const exportData = data;
|
|
62
|
-
if (!exportData.meta) {
|
|
63
|
-
exportData.meta = getMetadata();
|
|
64
|
-
}
|
|
65
|
-
deleteDeepByKey(exportData, '_rev');
|
|
66
|
-
fs.writeFile(filename, stringify(exportData), err => {
|
|
67
|
-
if (err) {
|
|
68
|
-
return printMessage(`ERROR - can't save ${filename}`, 'error');
|
|
69
|
-
}
|
|
70
|
-
return '';
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
export function saveToFile(type, data, identifier, filename) {
|
|
74
|
-
const exportData = {};
|
|
75
|
-
exportData['meta'] = getMetadata();
|
|
76
|
-
exportData[type] = {};
|
|
77
|
-
if (Array.isArray(data)) {
|
|
78
|
-
data.forEach(element => {
|
|
79
|
-
exportData[type][element[identifier]] = element;
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
exportData[type][data[identifier]] = data;
|
|
83
|
-
}
|
|
84
|
-
deleteDeepByKey(exportData, '_rev');
|
|
85
|
-
fs.writeFile(filename, stringify(exportData), err => {
|
|
86
|
-
if (err) {
|
|
87
|
-
return printMessage(`ERROR - can't save ${type} to file`, 'error');
|
|
88
|
-
}
|
|
89
|
-
return '';
|
|
90
|
-
});
|
|
91
|
-
}
|
|
39
|
+
export { getMetadata, getRealmString, getTypedFilename, saveJsonToFile, saveToFile, titleCase };
|
|
92
40
|
|
|
93
41
|
/**
|
|
94
42
|
* Save text data to file
|
|
@@ -105,22 +53,4 @@ export function saveTextToFile(data, filename) {
|
|
|
105
53
|
return false;
|
|
106
54
|
}
|
|
107
55
|
}
|
|
108
|
-
|
|
109
|
-
/*
|
|
110
|
-
* Output str in title case
|
|
111
|
-
*
|
|
112
|
-
* e.g.: 'ALL UPPERCASE AND all lowercase' = 'All Uppercase And All Lowercase'
|
|
113
|
-
*/
|
|
114
|
-
export function titleCase(input) {
|
|
115
|
-
const str = input.toString();
|
|
116
|
-
const splitStr = str.toLowerCase().split(' ');
|
|
117
|
-
for (let i = 0; i < splitStr.length; i += 1) {
|
|
118
|
-
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].slice(1);
|
|
119
|
-
}
|
|
120
|
-
return splitStr.join(' ');
|
|
121
|
-
}
|
|
122
|
-
export function getRealmString() {
|
|
123
|
-
const realm = state.getRealm();
|
|
124
|
-
return realm.split('/').reduce((result, item) => `${result}${titleCase(item)}`, '');
|
|
125
|
-
}
|
|
126
56
|
//# sourceMappingURL=ExportImportUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportImportUtils.js","names":["frodo","
|
|
1
|
+
{"version":3,"file":"ExportImportUtils.js","names":["frodo","fs","lstat","readdir","readFile","join","printMessage","readFiles","baseDirectory","childDirectory","targetDirectory","directoryItems","childPaths","map","item","filePathsNested","Promise","all","childPath","path","isDirectory","content","flat","getMetadata","getTypedFilename","saveJsonToFile","saveToFile","titleCase","getRealmString","utils","saveTextToFile","data","filename","writeFileSync","error"],"sources":["../../src/utils/ExportImportUtils.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport { lstat, readdir, readFile } from 'fs/promises';\nimport { join } from 'path';\n\nimport { printMessage } from './Console';\n\n/**\n * find all (nested) files in a directory\n *\n * @param baseDirectory directory to search\n * @param childDirectory subdirectory to search\n * @returns list of files\n */\nexport async function readFiles(\n baseDirectory: string,\n childDirectory = ''\n): Promise<\n {\n path: string;\n content: string;\n }[]\n> {\n const targetDirectory = join(baseDirectory, childDirectory);\n const directoryItems = await readdir(targetDirectory);\n const childPaths = directoryItems.map((item) => join(childDirectory, item));\n\n const filePathsNested = await Promise.all(\n childPaths.map(async (childPath) => {\n const path = join(baseDirectory, childPath);\n const isDirectory = (await lstat(path)).isDirectory();\n\n if (isDirectory) {\n return readFiles(baseDirectory, childPath);\n }\n\n return {\n path: childPath,\n content: await readFile(path, 'utf8'),\n };\n })\n );\n\n return filePathsNested.flat();\n}\n\nconst {\n getMetadata,\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n titleCase,\n getRealmString,\n} = frodo.utils;\n\nexport {\n getMetadata,\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n titleCase,\n};\n\n/**\n * Save text data to file\n * @param data text data\n * @param filename file name\n * @return true if successful, false otherwise\n */\nexport function saveTextToFile(data: string, filename: string): boolean {\n try {\n fs.writeFileSync(filename, data);\n return true;\n } catch (error) {\n printMessage(`ERROR - can't save ${filename}`, 'error');\n return false;\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC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Y,EAAEC,QAAgB,EAAW;EACtE,IAAI;IACF/B,EAAE,CAACgC,aAAa,CAACD,QAAQ,EAAED,IAAI,CAAC;IAChC,OAAO,IAAI;EACb,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd5B,YAAY,CAAE,sBAAqB0B,QAAS,EAAC,EAAE,OAAO,CAAC;IACvD,OAAO,KAAK;EACd;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rockcarver/frodo-cli",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A command line interface to manage ForgeRock Identity Cloud tenants, ForgeOps deployments, and classic deployments.",
|
|
6
6
|
"keywords": [
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
]
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@rockcarver/frodo-lib": "2.0.0-
|
|
107
|
+
"@rockcarver/frodo-lib": "2.0.0-34",
|
|
108
108
|
"chokidar": "^3.5.3",
|
|
109
109
|
"cli-progress": "^3.11.2",
|
|
110
110
|
"cli-table3": "^0.6.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme-list.e2e.test_.js","names":["spawn","spawnSync","ansiEscapeCodes","beforeAll","deleteThemesCmd","status","console","error","stderr","toString","log","stdout","importBaselineThemesCmd","cwd","describe","it","done","themeList","expected","join","chunks","on","chunk","push","output","Buffer","concat","replace","expect","toBe","expectedLong"],"sources":["../../../src/cli/theme/theme-list.e2e.test_.ts"],"sourcesContent":["/* eslint-disable no-console */\n// import { jest } from '@jest/globals';\nimport { spawn, spawnSync } from 'child_process';\n\nconst ansiEscapeCodes =\n // eslint-disable-next-line no-control-regex\n /[\\u001b\\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;\n\n/**\n * delete all themes and import baseline and additional test themes\n */\nbeforeAll(async () => {\n // delete all themes\n const deleteThemesCmd = spawnSync('frodo', [\n 'theme',\n 'delete',\n '--all',\n 'frodo-dev',\n ]);\n if (deleteThemesCmd.status && deleteThemesCmd.status > 0) {\n console.error(deleteThemesCmd.stderr.toString());\n console.log(deleteThemesCmd.stdout.toString());\n }\n\n // import baseline themes\n const importBaselineThemesCmd = spawnSync(\n 'frodo',\n ['theme', 'import', '--all-separate', 'frodo-dev'],\n {\n cwd: `test/e2e/theme/baseline`,\n }\n );\n if (importBaselineThemesCmd.status && importBaselineThemesCmd.status > 0) {\n console.error(importBaselineThemesCmd.stderr.toString());\n console.log(importBaselineThemesCmd.stdout.toString());\n }\n});\n\ndescribe('frodo theme list', () => {\n it('\"frodo theme list\": should list the names of the default themes', (done) => {\n const themeList = spawn('frodo', ['theme', 'list', 'frodo-dev']);\n const expected = [\n 'Contrast',\n 'Highlander',\n 'Robroy',\n 'Starter Theme',\n 'Zardoz',\n '',\n ].join('\\n');\n\n const chunks: Uint8Array[] = [];\n themeList.stdout.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n themeList.stdout.on('end', () => {\n const output = Buffer.concat(chunks)\n .toString()\n .replace(ansiEscapeCodes, '');\n try {\n expect(output).toBe(expected);\n done();\n } catch (error) {\n done(error);\n }\n });\n });\n\n const expectedLong = [\n 'Name │Id │Default',\n 'Contrast │cd6c93e2-52e2-4340-9770-66a588343841│ ',\n 'Highlander │00203891-dde0-4114-b27a-219ae0b43a61│ ',\n 'Robroy │b82755e8-fe9a-4d27-b66b-45e37ae12345│ ',\n 'Starter Theme│86ce2f64-586d-44fe-8593-b12a85aac68d│Yes ',\n 'Zardoz │4ded6d91-ceea-400a-ae3f-42209f1b0e06│ ',\n '',\n ].join('\\n');\n\n it('\"frodo theme list -l\": should list the names, ids, and default flag of the baseline themes', (done) => {\n const themeList = spawn('frodo', ['theme', 'list', '-l', 'frodo-dev']);\n\n const chunks: Uint8Array[] = [];\n themeList.stdout.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n themeList.stdout.on('end', () => {\n const output = Buffer.concat(chunks)\n .toString()\n .replace(ansiEscapeCodes, '');\n try {\n expect(output).toBe(expectedLong);\n done();\n } catch (error) {\n done(error);\n }\n });\n });\n\n it('\"frodo theme list --long\": should list the names, status, and default flag of the baseline themes', (done) => {\n const themeList = spawn('frodo', ['theme', 'list', '--long', 'frodo-dev']);\n\n const chunks: Uint8Array[] = [];\n themeList.stdout.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n themeList.stdout.on('end', () => {\n const output = Buffer.concat(chunks)\n .toString()\n .replace(ansiEscapeCodes, '');\n try {\n expect(output).toBe(expectedLong);\n done();\n } catch (error) {\n done(error);\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA,SAASA,KAAK,EAAEC,SAAS,QAAQ,eAAe;AAEhD,MAAMC,eAAe;AACnB;AACA,6EAA6E;;AAE/E;AACA;AACA;AACAC,SAAS,CAAC,YAAY;EACpB;EACA,MAAMC,eAAe,GAAGH,SAAS,CAAC,OAAO,EAAE,CACzC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,CACZ,CAAC;EACF,IAAIG,eAAe,CAACC,MAAM,IAAID,eAAe,CAACC,MAAM,GAAG,CAAC,EAAE;IACxDC,OAAO,CAACC,KAAK,CAACH,eAAe,CAACI,MAAM,CAACC,QAAQ,CAAC,CAAC,CAAC;IAChDH,OAAO,CAACI,GAAG,CAACN,eAAe,CAACO,MAAM,CAACF,QAAQ,CAAC,CAAC,CAAC;EAChD;;EAEA;EACA,MAAMG,uBAAuB,GAAGX,SAAS,CACvC,OAAO,EACP,CAAC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAClD;IACEY,GAAG,EAAG;EACR,CACF,CAAC;EACD,IAAID,uBAAuB,CAACP,MAAM,IAAIO,uBAAuB,CAACP,MAAM,GAAG,CAAC,EAAE;IACxEC,OAAO,CAACC,KAAK,CAACK,uBAAuB,CAACJ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