@rockcarver/frodo-cli 0.24.2 → 0.24.3
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 +14 -2
- package/esm/cli/conn/conn-save.js +2 -4
- package/esm/cli/conn/conn-save.js.map +1 -1
- package/esm/cli/logging/logs-fetch.js +1 -2
- package/esm/cli/logging/logs-fetch.js.map +1 -1
- package/esm/cli/logging/logs-list.js +1 -1
- package/esm/cli/logging/logs-list.js.map +1 -1
- package/esm/cli/logging/logs-tail.js +1 -2
- package/esm/cli/logging/logs-tail.js.map +1 -1
- package/esm/ops/LogOps.js +95 -0
- package/esm/ops/LogOps.js.map +1 -0
- package/esm/utils/Config.js +3 -3
- package/esm/utils/Config.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [0.24.
|
|
10
|
+
## [0.24.3] - 2023-05-25
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Update to frodo-lib 0.19.2
|
|
15
|
+
|
|
16
|
+
## [0.24.2] - 2023-05-22
|
|
11
17
|
|
|
12
18
|
### Added
|
|
13
19
|
|
|
@@ -67,6 +73,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
67
73
|
|
|
68
74
|
- \#214: Fixed a regression introduced in #186, which 'swallowed' `frodo` command exit codes and resulted in always exiting with 0 even if a `frodo` command returned with a different exit code.
|
|
69
75
|
|
|
76
|
+
## [0.24.1] - 2023-05-22 [YANKED]
|
|
77
|
+
|
|
78
|
+
## [0.24.1-0] - 2023-05-22 [YANKED]
|
|
79
|
+
|
|
70
80
|
## [0.24.0] - 2023-05-21 [YANKED]
|
|
71
81
|
|
|
72
82
|
## [0.23.1-8] - 2023-05-21
|
|
@@ -1172,7 +1182,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1172
1182
|
- Fixed problem with adding connection profiles
|
|
1173
1183
|
- Miscellaneous bug fixes
|
|
1174
1184
|
|
|
1175
|
-
[Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v0.24.
|
|
1185
|
+
[Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v0.24.3...HEAD
|
|
1186
|
+
|
|
1187
|
+
[0.24.3]: https://github.com/rockcarver/frodo-cli/compare/v0.24.1...v0.24.3
|
|
1176
1188
|
|
|
1177
1189
|
[0.24.1]: https://github.com/rockcarver/frodo-cli/compare/v0.24.1-0...v0.24.1
|
|
1178
1190
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { FrodoCommand } from '../FrodoCommand';
|
|
2
2
|
import { Option } from 'commander';
|
|
3
|
-
import { Authenticate, ConnectionProfile,
|
|
4
|
-
const {
|
|
5
|
-
provisionCreds
|
|
6
|
-
} = Log;
|
|
3
|
+
import { Authenticate, ConnectionProfile, ServiceAccount, state, constants } from '@rockcarver/frodo-lib';
|
|
7
4
|
import { verboseMessage, printMessage } from '../../utils/Console';
|
|
8
5
|
import { addExistingServiceAccount } from '../../ops/ConnectionProfileOps.js';
|
|
6
|
+
import { provisionCreds } from '../../ops/LogOps';
|
|
9
7
|
const {
|
|
10
8
|
getTokens
|
|
11
9
|
} = Authenticate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conn-save.js","names":["FrodoCommand","Option","Authenticate","ConnectionProfile","Log","ServiceAccount","state","constants","provisionCreds","verboseMessage","printMessage","addExistingServiceAccount","getTokens","saveConnectionProfile","addNewServiceAccount","isServiceAccountsFeatureAvailable","program","alias","description","addOption","action","host","user","password","options","command","handleDefaultArgsAndOpts","setLogApiKey","logApiKey","setLogApiSecret","logApiSecret","authenticationService","setAuthenticationService","authenticationHeaderOverrides","setAuthenticationHeaderOverrides","JSON","parse","forceLoginAsUser","sa","getLogApiKey","getLogApiSecret","validate","getHost","getDeploymentType","CLOUD_DEPLOYMENT_TYPE_KEY","saId","saJwkFile","getServiceAccountId","name","_id","error","_error$response","_error$response2","_error$response2$data","response","data","message","process","exitCode","logApi","creds","api_key_id","api_key_secret","_error$response3","_error$response4","_error$response4$data"],"sources":["cli/conn/conn-save.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n ServiceAccount,\n state,\n constants,\n} from '@rockcarver/frodo-lib';\nconst { provisionCreds } = Log;\nimport { verboseMessage, printMessage } from '../../utils/Console';\nimport { addExistingServiceAccount } from '../../ops/ConnectionProfileOps.js';\n\nconst { getTokens } = Authenticate;\nconst { saveConnectionProfile, addNewServiceAccount } = ConnectionProfile;\nconst { isServiceAccountsFeatureAvailable } = ServiceAccount;\n\nconst program = new FrodoCommand('frodo conn save', ['realm']);\n\nprogram\n .alias('add')\n .description('Save connection profiles.')\n .addOption(\n new Option(\n '--sa-id <uuid>',\n \"Service account's uuid. If specified, must also include --sa-jwk-file. Ignored with --no-sa.\"\n )\n )\n .addOption(\n new Option(\n '--sa-jwk-file <file>',\n \"File containing the service account's java web key (jwk). Jwk must contain private key! If specified, must also include --sa-id. Ignored with --no-sa.\"\n )\n )\n .addOption(new Option('--no-sa', 'Do not create and add service account.'))\n .addOption(\n new Option(\n '--log-api-key [key]',\n 'Log API key. If specified, must also include --log-api-secret. Ignored with --no-log-api.'\n )\n )\n .addOption(\n new Option(\n '--log-api-secret [secret]',\n 'Log API secret. If specified, must also include --log-api-key. Ignored with --no-log-api.'\n )\n )\n .addOption(\n new Option('--no-log-api', 'Do not create and add log API key and secret.')\n )\n .addOption(new Option('--no-validate', 'Do not validate connection.'))\n .addOption(\n new Option(\n '--authentication-service [service]',\n 'Name of the authentication service/tree to use.'\n )\n )\n .addOption(\n new Option(\n '--authentication-header-overrides [headers]',\n 'Map of headers: {\"host\":\"am.example.com:8081\"}.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(host, user, password, options, command);\n state.setLogApiKey(options.logApiKey);\n state.setLogApiSecret(options.logApiSecret);\n if (options.authenticationService) {\n state.setAuthenticationService(options.authenticationService);\n }\n if (options.authenticationHeaderOverrides) {\n state.setAuthenticationHeaderOverrides(\n JSON.parse(options.authenticationHeaderOverrides)\n );\n }\n const forceLoginAsUser =\n !options.sa ||\n (state.getLogApiKey() && state.getLogApiSecret() ? false : true);\n if (\n (options.validate && (await getTokens(forceLoginAsUser))) ||\n !options.validate\n ) {\n verboseMessage(\n `Saving connection profile for tenant ${state.getHost()}...`\n );\n // if cloud deployment add service account\n if (\n options.validate &&\n state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY &&\n options.sa &&\n (await isServiceAccountsFeatureAvailable())\n ) {\n // validate and add existing service account\n if (options.saId && options.saJwkFile) {\n verboseMessage(`Validating and adding service account...`);\n if (\n await addExistingServiceAccount(\n options.saId,\n options.saJwkFile,\n options.validate\n )\n ) {\n printMessage(\n `Validated and added service account with id ${options.saId} to profile.`\n );\n }\n }\n // add new service account if none already exists in the profile\n else if (!state.getServiceAccountId()) {\n try {\n verboseMessage(`Creating service account...`);\n const sa = await addNewServiceAccount();\n printMessage(\n `Created and added service account ${sa.name} with id ${sa._id} to profile.`\n );\n } catch (error) {\n printMessage(error.response?.data, 'error');\n printMessage(\n `Error creating service account: ${error.response?.data?.message}`,\n 'error'\n );\n process.exitCode = 1;\n }\n }\n }\n // add existing service account without validation\n else if (\n !options.validate &&\n options.saId &&\n options.saJwkFile &&\n options.sa\n ) {\n addExistingServiceAccount(\n options.saId,\n options.saJwkFile,\n options.validate\n );\n }\n // if cloud deployment add log api key and secret\n verboseMessage(options);\n verboseMessage(state);\n if (\n options.validate &&\n state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY &&\n options.logApi\n ) {\n // validate and add existing log api key and secret\n if (options.logApiKey && options.logApiSecret) {\n verboseMessage(`Validating and adding log api key and secret...`);\n if (\n await addExistingServiceAccount(\n options.logApiKey,\n options.logApiSecret,\n options.validate\n )\n ) {\n printMessage(\n `Added log API key ${options.logApiKey} to profile.`\n );\n }\n }\n // add new log api key and secret if none already exists in the profile\n else if (!state.getLogApiKey()) {\n try {\n const creds = await provisionCreds();\n state.setLogApiKey(creds.api_key_id);\n state.setLogApiSecret(creds.api_key_secret);\n printMessage(\n `Created log API key ${creds.api_key_id} and secret.`\n );\n } catch (error) {\n printMessage(error.response?.data, 'error');\n printMessage(\n `Error creating log API key and secret: ${error.response?.data?.message}`,\n 'error'\n );\n process.exitCode = 1;\n }\n }\n }\n // add existing log api key and secret without validation\n // storing log API key and secret in the connection profile is happening default, therefore no code required here\n if (await saveConnectionProfile(host)) {\n printMessage(`Saved connection profile ${state.getHost()}`);\n } else {\n process.exitCode = 1;\n }\n } else {\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,GAAG,EACHC,cAAc,EACdC,KAAK,EACLC,SAAS,QACJ,uBAAuB;AAC9B,MAAM;EAAEC;AAAe,CAAC,GAAGJ,GAAG;AAC9B,SAASK,cAAc,EAAEC,YAAY,QAAQ,qBAAqB;AAClE,SAASC,yBAAyB,QAAQ,mCAAmC;AAE7E,MAAM;EAAEC;AAAU,CAAC,GAAGV,YAAY;AAClC,MAAM;EAAEW,qBAAqB;EAAEC;AAAqB,CAAC,GAAGX,iBAAiB;AACzE,MAAM;EAAEY;AAAkC,CAAC,GAAGV,cAAc;AAE5D,MAAMW,OAAO,GAAG,IAAIhB,YAAY,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC,CAAC;AAE9DgB,OAAO,CACJC,KAAK,CAAC,KAAK,CAAC,CACZC,WAAW,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e,CAAC+B,KAAK,CAACE,cAAc,CAAC;UAC3CpD,YAAY,CACT,uBAAsBkD,KAAK,CAACC,UAAW,cAC1C,CAAC;QACH,CAAC,CAAC,OAAOX,KAAK,EAAE;UAAA,IAAAa,gBAAA,EAAAC,gBAAA,EAAAC,qBAAA;UACdvD,YAAY,EAAAqD,gBAAA,GAACb,KAAK,CAACI,QAAQ,cAAAS,gBAAA,uBAAdA,gBAAA,CAAgBR,IAAI,EAAE,OAAO,CAAC;UAC3C7C,YAAY,CACT,0CAAuC,CAAAsD,gBAAA,GAAEd,KAAK,CAACI,QAAQ,cAAAU,gBAAA,wBAAAC,qBAAA,GAAdD,gBAAA,CAAgBT,IAAI,cAAAU,qBAAA,uBAApBA,qBAAA,CAAsBT,OAAQ,EAAC,EACzE,OACF,CAAC;UACDC,OAAO,CAACC,QAAQ,GAAG,CAAC;QACtB;MACF;IACF;IACA;IACA;IACA,IAAI,MAAM7C,qBAAqB,CAACQ,IAAI,CAAC,EAAE;MACrCX,YAAY,CAAE,4BAA2BJ,KAAK,CAACoC,OAAO,CAAC,CAAE,EAAC,CAAC;IAC7D,CAAC,MAAM;MACLe,OAAO,CAACC,QAAQ,GAAG,CAAC;IACtB;EACF,CAAC,MAAM;IACLD,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AACF,CAAC;;AAEH1C,OAAO,CAACoB,KAAK,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"conn-save.js","names":["FrodoCommand","Option","Authenticate","ConnectionProfile","ServiceAccount","state","constants","verboseMessage","printMessage","addExistingServiceAccount","provisionCreds","getTokens","saveConnectionProfile","addNewServiceAccount","isServiceAccountsFeatureAvailable","program","alias","description","addOption","action","host","user","password","options","command","handleDefaultArgsAndOpts","setLogApiKey","logApiKey","setLogApiSecret","logApiSecret","authenticationService","setAuthenticationService","authenticationHeaderOverrides","setAuthenticationHeaderOverrides","JSON","parse","forceLoginAsUser","sa","getLogApiKey","getLogApiSecret","validate","getHost","getDeploymentType","CLOUD_DEPLOYMENT_TYPE_KEY","saId","saJwkFile","getServiceAccountId","name","_id","error","_error$response","_error$response2","_error$response2$data","response","data","message","process","exitCode","logApi","creds","api_key_id","api_key_secret","_error$response3","_error$response4","_error$response4$data"],"sources":["cli/conn/conn-save.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n ServiceAccount,\n state,\n constants,\n} from '@rockcarver/frodo-lib';\nimport { verboseMessage, printMessage } from '../../utils/Console';\nimport { addExistingServiceAccount } from '../../ops/ConnectionProfileOps.js';\nimport { provisionCreds } from '../../ops/LogOps';\n\nconst { getTokens } = Authenticate;\nconst { saveConnectionProfile, addNewServiceAccount } = ConnectionProfile;\nconst { isServiceAccountsFeatureAvailable } = ServiceAccount;\n\nconst program = new FrodoCommand('frodo conn save', ['realm']);\n\nprogram\n .alias('add')\n .description('Save connection profiles.')\n .addOption(\n new Option(\n '--sa-id <uuid>',\n \"Service account's uuid. If specified, must also include --sa-jwk-file. Ignored with --no-sa.\"\n )\n )\n .addOption(\n new Option(\n '--sa-jwk-file <file>',\n \"File containing the service account's java web key (jwk). Jwk must contain private key! If specified, must also include --sa-id. Ignored with --no-sa.\"\n )\n )\n .addOption(new Option('--no-sa', 'Do not create and add service account.'))\n .addOption(\n new Option(\n '--log-api-key [key]',\n 'Log API key. If specified, must also include --log-api-secret. Ignored with --no-log-api.'\n )\n )\n .addOption(\n new Option(\n '--log-api-secret [secret]',\n 'Log API secret. If specified, must also include --log-api-key. Ignored with --no-log-api.'\n )\n )\n .addOption(\n new Option('--no-log-api', 'Do not create and add log API key and secret.')\n )\n .addOption(new Option('--no-validate', 'Do not validate connection.'))\n .addOption(\n new Option(\n '--authentication-service [service]',\n 'Name of the authentication service/tree to use.'\n )\n )\n .addOption(\n new Option(\n '--authentication-header-overrides [headers]',\n 'Map of headers: {\"host\":\"am.example.com:8081\"}.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(host, user, password, options, command);\n state.setLogApiKey(options.logApiKey);\n state.setLogApiSecret(options.logApiSecret);\n if (options.authenticationService) {\n state.setAuthenticationService(options.authenticationService);\n }\n if (options.authenticationHeaderOverrides) {\n state.setAuthenticationHeaderOverrides(\n JSON.parse(options.authenticationHeaderOverrides)\n );\n }\n const forceLoginAsUser =\n !options.sa ||\n (state.getLogApiKey() && state.getLogApiSecret() ? false : true);\n if (\n (options.validate && (await getTokens(forceLoginAsUser))) ||\n !options.validate\n ) {\n verboseMessage(\n `Saving connection profile for tenant ${state.getHost()}...`\n );\n // if cloud deployment add service account\n if (\n options.validate &&\n state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY &&\n options.sa &&\n (await isServiceAccountsFeatureAvailable())\n ) {\n // validate and add existing service account\n if (options.saId && options.saJwkFile) {\n verboseMessage(`Validating and adding service account...`);\n if (\n await addExistingServiceAccount(\n options.saId,\n options.saJwkFile,\n options.validate\n )\n ) {\n printMessage(\n `Validated and added service account with id ${options.saId} to profile.`\n );\n }\n }\n // add new service account if none already exists in the profile\n else if (!state.getServiceAccountId()) {\n try {\n verboseMessage(`Creating service account...`);\n const sa = await addNewServiceAccount();\n printMessage(\n `Created and added service account ${sa.name} with id ${sa._id} to profile.`\n );\n } catch (error) {\n printMessage(error.response?.data, 'error');\n printMessage(\n `Error creating service account: ${error.response?.data?.message}`,\n 'error'\n );\n process.exitCode = 1;\n }\n }\n }\n // add existing service account without validation\n else if (\n !options.validate &&\n options.saId &&\n options.saJwkFile &&\n options.sa\n ) {\n addExistingServiceAccount(\n options.saId,\n options.saJwkFile,\n options.validate\n );\n }\n // if cloud deployment add log api key and secret\n verboseMessage(options);\n verboseMessage(state);\n if (\n options.validate &&\n state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY &&\n options.logApi\n ) {\n // validate and add existing log api key and secret\n if (options.logApiKey && options.logApiSecret) {\n verboseMessage(`Validating and adding log api key and secret...`);\n if (\n await addExistingServiceAccount(\n options.logApiKey,\n options.logApiSecret,\n options.validate\n )\n ) {\n printMessage(\n `Added log API key ${options.logApiKey} to profile.`\n );\n }\n }\n // add new log api key and secret if none already exists in the profile\n else if (!state.getLogApiKey()) {\n try {\n const creds = await provisionCreds();\n state.setLogApiKey(creds.api_key_id);\n state.setLogApiSecret(creds.api_key_secret);\n printMessage(\n `Created log API key ${creds.api_key_id} and secret.`\n );\n } catch (error) {\n printMessage(error.response?.data, 'error');\n printMessage(\n `Error creating log API key and secret: ${error.response?.data?.message}`,\n 'error'\n );\n process.exitCode = 1;\n }\n }\n }\n // add existing log api key and secret without validation\n // storing log API key and secret in the connection profile is happening default, therefore no code required here\n if (await saveConnectionProfile(host)) {\n printMessage(`Saved connection profile ${state.getHost()}`);\n } else {\n process.exitCode = 1;\n }\n } else {\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,cAAc,EACdC,KAAK,EACLC,SAAS,QACJ,uBAAuB;AAC9B,SAASC,cAAc,EAAEC,YAAY,QAAQ,qBAAqB;AAClE,SAASC,yBAAyB,QAAQ,mCAAmC;AAC7E,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,MAAM;EAAEC;AAAU,CAAC,GAAGT,YAAY;AAClC,MAAM;EAAEU,qBAAqB;EAAEC;AAAqB,CAAC,GAAGV,iBAAiB;AACzE,MAAM;EAAEW;AAAkC,CAAC,GAAGV,cAAc;AAE5D,MAAMW,OAAO,GAAG,IAAIf,YAAY,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC,CAAC;AAE9De,OAAO,CACJC,KAAK,CAAC,KAAK,CAAC,CACZC,WAAW,CAAC,2BAA2B,CAAC,CACxCC,SAAS,CACR,IAAIjB,MAAM,CACR,gBA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sBmD,KAAK,CAACC,UAAW,cAC1C,CAAC;QACH,CAAC,CAAC,OAAOX,KAAK,EAAE;UAAA,IAAAa,gBAAA,EAAAC,gBAAA,EAAAC,qBAAA;UACdxD,YAAY,EAAAsD,gBAAA,GAACb,KAAK,CAACI,QAAQ,cAAAS,gBAAA,uBAAdA,gBAAA,CAAgBR,IAAI,EAAE,OAAO,CAAC;UAC3C9C,YAAY,CACT,0CAAuC,CAAAuD,gBAAA,GAAEd,KAAK,CAACI,QAAQ,cAAAU,gBAAA,wBAAAC,qBAAA,GAAdD,gBAAA,CAAgBT,IAAI,cAAAU,qBAAA,uBAApBA,qBAAA,CAAsBT,OAAQ,EAAC,EACzE,OACF,CAAC;UACDC,OAAO,CAACC,QAAQ,GAAG,CAAC;QACtB;MACF;IACF;IACA;IACA;IACA,IAAI,MAAM7C,qBAAqB,CAACQ,IAAI,CAAC,EAAE;MACrCZ,YAAY,CAAE,4BAA2BH,KAAK,CAACoC,OAAO,CAAC,CAAE,EAAC,CAAC;IAC7D,CAAC,MAAM;MACLe,OAAO,CAACC,QAAQ,GAAG,CAAC;IACtB;EACF,CAAC,MAAM;IACLD,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AACF,CAAC;;AAEH1C,OAAO,CAACoB,KAAK,CAAC,CAAC"}
|
|
@@ -4,9 +4,8 @@ import { Option } from 'commander';
|
|
|
4
4
|
import { Authenticate, ConnectionProfile, Log, state } from '@rockcarver/frodo-lib';
|
|
5
5
|
import * as config from '../../utils/Config';
|
|
6
6
|
import { printMessage } from '../../utils/Console';
|
|
7
|
+
import { fetchLogs, provisionCreds } from '../../ops/LogOps';
|
|
7
8
|
const {
|
|
8
|
-
provisionCreds,
|
|
9
|
-
fetchLogs,
|
|
10
9
|
resolveLevel
|
|
11
10
|
} = Log;
|
|
12
11
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs-fetch.js","names":["FrodoCommand","sourcesOptionM","Option","Authenticate","ConnectionProfile","Log","state","config","printMessage","provisionCreds","fetchLogs","resolveLevel","getConnectionProfile","saveConnectionProfile","getTokens","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","conn","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":["cli/logging/logs-fetch.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './logs';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\n\nconst { provisionCreds, fetchLogs, resolveLevel } = Log;\nconst { getConnectionProfile, saveConnectionProfile } = ConnectionProfile;\nconst { getTokens } = Authenticate;\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 logs 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);\n state.setLogApiSecret(creds.api_key_secret);\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,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,QAAQ;AACvC,SAASC,MAAM,QAAQ,WAAW;AAClC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,GAAG,EACHC,KAAK,QACA,uBAAuB;AAC9B,OAA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qB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACC,OAChB,gBAAelD,YAAY,CAACkB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACE,KAAK,CAAE,QACjD9B,IAAI,CAACE,MACN,KACH,CAAC;IACD,IAAIH,mBAAmB,EAAE,MAAMlB,qBAAqB,CAACY,IAAI,CAAC,CAAC,CAAC;;IAE5D,IAAIsC,aAAa,GAAG7C,yBAAyB;IAC7C,IAAIwC,KAAK,GAAGF,OAAO,GAAG,EAAE,EAAE;MACxBO,aAAa,GAAGA,aAAa,GAAG,EAAE;IACpC;IACA,GAAG;MACDJ,iBAAiB,GAAGH,OAAO,GAAGO,aAAa;MAC3C,MAAMrD,SAAS,CACbmB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACC,OAAO,EACtB,IAAIb,IAAI,CAACQ,OAAO,GAAG,IAAI,CAAC,CAACN,WAAW,CAAC,CAAC,EACtC,IAAIF,IAAI,CAACW,iBAAiB,GAAG,IAAI,CAAC,CAACT,WAAW,CAAC,CAAC,EAChDvC,YAAY,CAACkB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACE,KAAK,CAAC,EAClCjC,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACI,aAAa,EAC5BnC,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACK,YAAY,EAC3B,IAAI,EACJ1D,MAAM,CAAC2D,eAAe,CAACtC,OAAO,CAACuC,QAAQ,CACzC,CAAC;MACDX,OAAO,GAAGG,iBAAiB;IAC7B,CAAC,QAAQA,iBAAiB,GAAGD,KAAK;EACpC;AACF,CAAC,CAAC;AAEJvC,OAAO,CAACsC,KAAK,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"logs-fetch.js","names":["FrodoCommand","sourcesOptionM","Option","Authenticate","ConnectionProfile","Log","state","config","printMessage","fetchLogs","provisionCreds","resolveLevel","getConnectionProfile","saveConnectionProfile","getTokens","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","conn","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":["cli/logging/logs-fetch.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './logs';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\nimport { fetchLogs, provisionCreds } from '../../ops/LogOps';\n\nconst { resolveLevel } = Log;\nconst { getConnectionProfile, saveConnectionProfile } = ConnectionProfile;\nconst { getTokens } = Authenticate;\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 logs 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);\n state.setLogApiSecret(creds.api_key_secret);\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,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,QAAQ;AACvC,SAASC,MAAM,QAAQ,WAAW;AAClC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,GAAG,EACHC,KAAK,QACA,uBAAuB;AAC9B,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAC5C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,SAAS,EAAEC,cAAc,QAA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CAAC+B,IAAI,CAAC,CAAC,CAACE,KAAK,CAAE,QACjD9B,IAAI,CAACE,MACN,KACH,CAAC;IACD,IAAIH,mBAAmB,EAAE,MAAMlB,qBAAqB,CAACY,IAAI,CAAC,CAAC,CAAC;;IAE5D,IAAIsC,aAAa,GAAG7C,yBAAyB;IAC7C,IAAIwC,KAAK,GAAGF,OAAO,GAAG,EAAE,EAAE;MACxBO,aAAa,GAAGA,aAAa,GAAG,EAAE;IACpC;IACA,GAAG;MACDJ,iBAAiB,GAAGH,OAAO,GAAGO,aAAa;MAC3C,MAAMtD,SAAS,CACboB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACC,OAAO,EACtB,IAAIb,IAAI,CAACQ,OAAO,GAAG,IAAI,CAAC,CAACN,WAAW,CAAC,CAAC,EACtC,IAAIF,IAAI,CAACW,iBAAiB,GAAG,IAAI,CAAC,CAACT,WAAW,CAAC,CAAC,EAChDvC,YAAY,CAACkB,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACE,KAAK,CAAC,EAClCjC,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACI,aAAa,EAC5BnC,OAAO,CAAC+B,IAAI,CAAC,CAAC,CAACK,YAAY,EAC3B,IAAI,EACJ1D,MAAM,CAAC2D,eAAe,CAACtC,OAAO,CAACuC,QAAQ,CACzC,CAAC;MACDX,OAAO,GAAGG,iBAAiB;IAC7B,CAAC,QAAQA,iBAAiB,GAAGD,KAAK;EACpC;AACF,CAAC,CAAC;AAEJvC,OAAO,CAACsC,KAAK,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FrodoCommand } from '../FrodoCommand';
|
|
2
2
|
import { Authenticate, ConnectionProfile, Log, state } from '@rockcarver/frodo-lib';
|
|
3
3
|
import { printMessage, verboseMessage } from '../../utils/Console';
|
|
4
|
+
import { provisionCreds } from '../../ops/LogOps';
|
|
4
5
|
const {
|
|
5
|
-
provisionCreds,
|
|
6
6
|
getLogSources
|
|
7
7
|
} = Log;
|
|
8
8
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs-list.js","names":["FrodoCommand","Authenticate","ConnectionProfile","Log","state","printMessage","verboseMessage","provisionCreds","getLogSources","getConnectionProfile","saveConnectionProfile","getTokens","program","description","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","creds","api_key_id","api_key_secret","sources","length","forEach","source","parse"],"sources":["cli/logging/logs-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\n\nconst {
|
|
1
|
+
{"version":3,"file":"logs-list.js","names":["FrodoCommand","Authenticate","ConnectionProfile","Log","state","printMessage","verboseMessage","provisionCreds","getLogSources","getConnectionProfile","saveConnectionProfile","getTokens","program","description","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","creds","api_key_id","api_key_secret","sources","length","forEach","source","parse"],"sources":["cli/logging/logs-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport { provisionCreds } from '../../ops/LogOps';\n\nconst { getLogSources } = Log;\nconst { getConnectionProfile, saveConnectionProfile } = ConnectionProfile;\nconst { getTokens } = Authenticate;\n\nconst program = new FrodoCommand('frodo logs list', ['realm', 'type']);\nprogram\n .description('List available ID Cloud log sources.')\n .action(async (host, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(host, user, password, options, command);\n let credsFromParameters = true;\n verboseMessage('Listing available ID Cloud log sources...');\n const conn = await 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);\n state.setLogApiSecret(creds.api_key_secret);\n }\n }\n\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 if (credsFromParameters) await saveConnectionProfile(host); // save new values if they were specified on CLI\n printMessage(`Log sources from ${conn.tenant}`);\n sources.forEach((source) => {\n printMessage(`${source}`, 'data');\n });\n printMessage(\n 'Use any combination of comma separated sources, example:',\n 'info'\n );\n printMessage(`$ frodo logs tail -c am-core,idm-core ${host}`, 'text');\n }\n }\n });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SACEC,YAAY,EACZC,iBAAiB,EACjBC,GAAG,EACHC,KAAK,QACA,uBAAuB;AAC9B,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,MAAM;EAAEC;AAAc,CAAC,GAAGL,GAAG;AAC7B,MAAM;EAAEM,oBAAoB;EAAEC;AAAsB,CAAC,GAAGR,iBAAiB;AACzE,MAAM;EAAES;AAAU,CAAC,GAAGV,YAAY;AAElC,MAAMW,OAAO,GAAG,IAAIZ,YAAY,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtEY,OAAO,CACJC,WAAW,CAAC,sCAAsC,CAAC,CACnDC,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CAACwB,eAAe,CAACM,KAAK,CAACE,cAAc,CAAC;MAC7C;IACF;IAEA,MAAMC,OAAO,GAAG,MAAM7B,aAAa,CAAC,CAAC;IACrC,IAAI6B,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MACxBjC,YAAY,CACV,6DAA6D,EAC7D,OACF,CAAC;IACH,CAAC,MAAM;MACL,IAAIgB,mBAAmB,EAAE,MAAMX,qBAAqB,CAACK,IAAI,CAAC,CAAC,CAAC;MAC5DV,YAAY,CAAE,oBAAmBiB,IAAI,CAACE,MAAO,EAAC,CAAC;MAC/Ca,OAAO,CAACE,OAAO,CAAEC,MAAM,IAAK;QAC1BnC,YAAY,CAAE,GAAEmC,MAAO,EAAC,EAAE,MAAM,CAAC;MACnC,CAAC,CAAC;MACFnC,YAAY,CACV,0DAA0D,EAC1D,MACF,CAAC;MACDA,YAAY,CAAE,yCAAwCU,IAAK,EAAC,EAAE,MAAM,CAAC;IACvE;EACF;AACF,CAAC,CAAC;AAEJH,OAAO,CAAC6B,KAAK,CAAC,CAAC"}
|
|
@@ -4,9 +4,8 @@ import { Option } from 'commander';
|
|
|
4
4
|
import { Authenticate, ConnectionProfile, Log, state } from '@rockcarver/frodo-lib';
|
|
5
5
|
import * as config from '../../utils/Config';
|
|
6
6
|
import { printMessage } from '../../utils/Console';
|
|
7
|
+
import { provisionCreds, tailLogs } from '../../ops/LogOps';
|
|
7
8
|
const {
|
|
8
|
-
provisionCreds,
|
|
9
|
-
tailLogs,
|
|
10
9
|
resolveLevel
|
|
11
10
|
} = Log;
|
|
12
11
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs-tail.js","names":["FrodoCommand","sourcesOptionM","Option","Authenticate","ConnectionProfile","Log","state","config","printMessage","provisionCreds","tailLogs","resolveLevel","getConnectionProfile","saveConnectionProfile","getTokens","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","creds","api_key_id","api_key_secret","opts","sources","level","transactionId","getNoiseFilters","defaults","parse"],"sources":["cli/logging/logs-tail.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './logs';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\
|
|
1
|
+
{"version":3,"file":"logs-tail.js","names":["FrodoCommand","sourcesOptionM","Option","Authenticate","ConnectionProfile","Log","state","config","printMessage","provisionCreds","tailLogs","resolveLevel","getConnectionProfile","saveConnectionProfile","getTokens","program","description","addOption","default","FRODO_LOG_NOISEFILTER_FILENAME","action","host","user","password","options","command","handleDefaultArgsAndOpts","credsFromParameters","conn","setHost","tenant","logApiKey","logApiSecret","setLogApiKey","setLogApiSecret","username","getUsername","getPassword","setUsername","setPassword","creds","api_key_id","api_key_secret","opts","sources","level","transactionId","getNoiseFilters","defaults","parse"],"sources":["cli/logging/logs-tail.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { sourcesOptionM } from './logs';\nimport { Option } from 'commander';\nimport {\n Authenticate,\n ConnectionProfile,\n Log,\n state,\n} from '@rockcarver/frodo-lib';\nimport * as config from '../../utils/Config';\nimport { printMessage } from '../../utils/Console';\nimport { provisionCreds, tailLogs } from '../../ops/LogOps';\n\nconst { resolveLevel } = Log;\nconst { getConnectionProfile, saveConnectionProfile } = ConnectionProfile;\nconst { getTokens } = Authenticate;\n\nconst program = new FrodoCommand('frodo logs 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 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);\n state.setLogApiSecret(creds.api_key_secret);\n }\n }\n printMessage(\n `Tailing 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 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 });\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,QAAQ;AACvC,SAASC,MAAM,QAAQ,WAAW;AAClC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,GAAG,EACHC,KAAK,QACA,uBAAuB;AAC9B,OAAO,KAA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C,EAClCpB,OAAO,CAACkB,IAAI,CAAC,CAAC,CAACG,aAAa,EAC5B,IAAI,EACJvC,MAAM,CAACwC,eAAe,CAACvB,OAAO,CAACwB,QAAQ,CACzC,CAAC;EACH;AACF,CAAC,CAAC;AAEJjC,OAAO,CAACkC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { printMessage, verboseMessage } from '../utils/Console';
|
|
2
|
+
import { Log, state } from '@rockcarver/frodo-lib';
|
|
3
|
+
const {
|
|
4
|
+
getDefaultNoiseFilter,
|
|
5
|
+
tail,
|
|
6
|
+
fetch,
|
|
7
|
+
getLogApiKeys,
|
|
8
|
+
resolvePayloadLevel,
|
|
9
|
+
createAPIKeyAndSecret
|
|
10
|
+
} = Log;
|
|
11
|
+
export async function tailLogs(source, levels, txid, cookie, nf) {
|
|
12
|
+
try {
|
|
13
|
+
const logsObject = await tail(source, cookie);
|
|
14
|
+
let filteredLogs = [];
|
|
15
|
+
const noiseFilter = nf == null ? getDefaultNoiseFilter() : nf;
|
|
16
|
+
if (Array.isArray(logsObject.result)) {
|
|
17
|
+
filteredLogs = logsObject.result.filter(el => {
|
|
18
|
+
var _transactionId;
|
|
19
|
+
return !noiseFilter.includes(el.payload.logger) && !noiseFilter.includes(el.type) && (levels[0] === 'ALL' || levels.includes(resolvePayloadLevel(el))) && (typeof txid === 'undefined' || txid === null || ((_transactionId = el.payload.transactionId) === null || _transactionId === void 0 ? void 0 : _transactionId.includes(txid)));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
filteredLogs.forEach(e => {
|
|
23
|
+
printMessage(JSON.stringify(e), 'data');
|
|
24
|
+
});
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
tailLogs(source, levels, txid, logsObject.pagedResultsCookie, nf);
|
|
27
|
+
}, 5000);
|
|
28
|
+
return null;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
printMessage(`tail ERROR: tail data error - ${e}`, 'error');
|
|
31
|
+
return `tail ERROR: tail data error - ${e}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function provisionCreds() {
|
|
35
|
+
try {
|
|
36
|
+
let keyName = `frodo-${state.getUsername()}`;
|
|
37
|
+
try {
|
|
38
|
+
const keys = await getLogApiKeys();
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
if (key.name === keyName) {
|
|
41
|
+
// append current timestamp to name if the named key already exists
|
|
42
|
+
keyName = `${keyName}-${new Date().toISOString()}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const resp = await createAPIKeyAndSecret(keyName);
|
|
47
|
+
if (resp.name !== keyName) {
|
|
48
|
+
printMessage(`create keys ERROR: could not create log API key ${keyName}`, 'error');
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
verboseMessage(`Created a new log API key [${keyName}] in ${state.getHost()}`);
|
|
52
|
+
return resp;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
printMessage(`create keys ERROR: create keys call returned ${error}`, 'error');
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
printMessage(`get keys ERROR: get keys call returned ${error}`, 'error');
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
printMessage(`create keys ERROR: create keys data error - ${e}`, 'error');
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function fetchLogs(source, startTs, endTs, levels, txid, ffString, cookie, nf) {
|
|
66
|
+
try {
|
|
67
|
+
const logsObject = await fetch(source, startTs, endTs, cookie);
|
|
68
|
+
let filteredLogs = [];
|
|
69
|
+
const noiseFilter = nf == null ? getDefaultNoiseFilter() : nf;
|
|
70
|
+
if (Array.isArray(logsObject.result)) {
|
|
71
|
+
filteredLogs = logsObject.result.filter(el => {
|
|
72
|
+
var _transactionId2;
|
|
73
|
+
return !noiseFilter.includes(el.payload.logger) && !noiseFilter.includes(el.type) && (levels[0] === 'ALL' || levels.includes(resolvePayloadLevel(el))) && (typeof txid === 'undefined' || txid === null || ((_transactionId2 = el.payload.transactionId) === null || _transactionId2 === void 0 ? void 0 : _transactionId2.includes(txid)));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
filteredLogs.forEach(e => {
|
|
77
|
+
const log = JSON.stringify(e, null, 2);
|
|
78
|
+
if (ffString) {
|
|
79
|
+
if (log.includes(ffString)) {
|
|
80
|
+
printMessage(log, 'data');
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
printMessage(log, 'data');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (logsObject.pagedResultsCookie != null) {
|
|
87
|
+
await fetchLogs(source, startTs, endTs, levels, txid, ffString, logsObject.pagedResultsCookie, nf);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
} catch (e) {
|
|
91
|
+
printMessage(`fetch ERROR: fetch data error - ${e}`, 'error');
|
|
92
|
+
return `fetch ERROR: fetch data error - ${e}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=LogOps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogOps.js","names":["printMessage","verboseMessage","Log","state","getDefaultNoiseFilter","tail","fetch","getLogApiKeys","resolvePayloadLevel","createAPIKeyAndSecret","tailLogs","source","levels","txid","cookie","nf","logsObject","filteredLogs","noiseFilter","Array","isArray","result","filter","el","_transactionId","includes","payload","logger","type","transactionId","forEach","e","JSON","stringify","setTimeout","pagedResultsCookie","provisionCreds","keyName","getUsername","keys","key","name","Date","toISOString","resp","getHost","error","fetchLogs","startTs","endTs","ffString","_transactionId2","log"],"sources":["ops/LogOps.ts"],"sourcesContent":["import { LogEventPayloadSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport { printMessage, verboseMessage } from '../utils/Console';\nimport { Log, state } from '@rockcarver/frodo-lib';\n\nconst {\n getDefaultNoiseFilter,\n tail,\n fetch,\n getLogApiKeys,\n resolvePayloadLevel,\n createAPIKeyAndSecret,\n} = Log;\n\nexport async function tailLogs(\n source: string,\n levels: string[],\n txid: string,\n cookie: string,\n nf: string[]\n) {\n try {\n const logsObject = await tail(source, cookie);\n let filteredLogs = [];\n const noiseFilter = nf == null ? getDefaultNoiseFilter() : nf;\n if (Array.isArray(logsObject.result)) {\n filteredLogs = logsObject.result.filter(\n (el) =>\n !noiseFilter.includes(\n (el.payload as LogEventPayloadSkeleton).logger\n ) &&\n !noiseFilter.includes(el.type) &&\n (levels[0] === 'ALL' || levels.includes(resolvePayloadLevel(el))) &&\n (typeof txid === 'undefined' ||\n txid === null ||\n (el.payload as LogEventPayloadSkeleton).transactionId?.includes(\n txid\n ))\n );\n }\n\n filteredLogs.forEach((e) => {\n printMessage(JSON.stringify(e), 'data');\n });\n\n setTimeout(() => {\n tailLogs(source, levels, txid, logsObject.pagedResultsCookie, nf);\n }, 5000);\n return null;\n } catch (e) {\n printMessage(`tail ERROR: tail data error - ${e}`, 'error');\n return `tail ERROR: tail data error - ${e}`;\n }\n}\n\nexport async function provisionCreds() {\n try {\n let keyName = `frodo-${state.getUsername()}`;\n try {\n const keys = await getLogApiKeys();\n for (const key of keys) {\n if (key.name === keyName) {\n // append current timestamp to name if the named key already exists\n keyName = `${keyName}-${new Date().toISOString()}`;\n }\n }\n try {\n const resp = await createAPIKeyAndSecret(keyName);\n if (resp.name !== keyName) {\n printMessage(\n `create keys ERROR: could not create log API key ${keyName}`,\n 'error'\n );\n return null;\n }\n verboseMessage(\n `Created a new log API key [${keyName}] in ${state.getHost()}`\n );\n return resp;\n } catch (error) {\n printMessage(\n `create keys ERROR: create keys call returned ${error}`,\n 'error'\n );\n return null;\n }\n } catch (error) {\n printMessage(`get keys ERROR: get keys call returned ${error}`, 'error');\n }\n } catch (e) {\n printMessage(`create keys ERROR: create keys data error - ${e}`, 'error');\n return null;\n }\n}\n\nexport async function fetchLogs(\n source: string,\n startTs: string,\n endTs: string,\n levels: string[],\n txid: string,\n ffString: string,\n cookie: string,\n nf: string[]\n) {\n try {\n const logsObject = await fetch(source, startTs, endTs, cookie);\n let filteredLogs = [];\n const noiseFilter = nf == null ? getDefaultNoiseFilter() : nf;\n if (Array.isArray(logsObject.result)) {\n filteredLogs = logsObject.result.filter(\n (el) =>\n !noiseFilter.includes(\n (el.payload as LogEventPayloadSkeleton).logger\n ) &&\n !noiseFilter.includes(el.type) &&\n (levels[0] === 'ALL' || levels.includes(resolvePayloadLevel(el))) &&\n (typeof txid === 'undefined' ||\n txid === null ||\n (el.payload as LogEventPayloadSkeleton).transactionId?.includes(\n txid\n ))\n );\n }\n\n filteredLogs.forEach((e) => {\n const log = JSON.stringify(e, null, 2);\n if (ffString) {\n if (log.includes(ffString)) {\n printMessage(log, 'data');\n }\n } else {\n printMessage(log, 'data');\n }\n });\n if (logsObject.pagedResultsCookie != null) {\n await fetchLogs(\n source,\n startTs,\n endTs,\n levels,\n txid,\n ffString,\n logsObject.pagedResultsCookie,\n nf\n );\n }\n return null;\n } catch (e) {\n printMessage(`fetch ERROR: fetch data error - ${e}`, 'error');\n return `fetch ERROR: fetch data error - ${e}`;\n }\n}\n"],"mappings":"AACA,SAASA,YAAY,EAAEC,cAAc,QAAQ,kBAAkB;AAC/D,SAASC,GAAG,EAAEC,KAAK,QAAQ,uBAAuB;AAElD,MAAM;EACJC,qBAAqB;EACrBC,IAAI;EACJC,KAAK;EACLC,aAAa;EACbC,mBAAmB;EACnBC;AACF,CAAC,GAAGP,GAAG;AAEP,OAAO,eAAeQ,QAAQA,CAC5BC,MAAc,EACdC,MAAgB,EAChBC,IAAY,EACZC,MAAc,EACdC,EAAY,EACZ;EACA,IAAI;IACF,MAAMC,UAAU,GAAG,MAAMX,IAAI,CAACM,MAAM,EAAEG,MAAM,CAAC;IAC7C,IAAIG,YAAY,GAAG,EAAE;IACrB,MAAMC,WAAW,GAAGH,EAAE,IAAI,IAAI,GAAGX,qBAAqB,CAAC,CAAC,GAAGW,EAA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I;EACb,CAAC,CAAC,OAAOgB,CAAC,EAAE;IACV/B,YAAY,CAAE,mCAAkC+B,CAAE,EAAC,EAAE,OAAO,CAAC;IAC7D,OAAQ,mCAAkCA,CAAE,EAAC;EAC/C;AACF"}
|
package/esm/utils/Config.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'os';
|
|
|
3
3
|
import { Log } from '@rockcarver/frodo-lib';
|
|
4
4
|
import { printMessage } from './Console';
|
|
5
5
|
const {
|
|
6
|
-
|
|
6
|
+
getDefaultNoiseFilter
|
|
7
7
|
} = Log;
|
|
8
8
|
export const FRODO_CONFIG_PATH_KEY = 'FRODO_CONFIG_PATH';
|
|
9
9
|
export const FRODO_LOG_NOISEFILTER_FILENAME = 'LoggingNoiseFilter.json';
|
|
@@ -25,12 +25,12 @@ export function getNoiseFilters(defaults) {
|
|
|
25
25
|
const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;
|
|
26
26
|
if (defaults) {
|
|
27
27
|
printMessage(`Using default logging noise filters.`, 'info');
|
|
28
|
-
return
|
|
28
|
+
return getDefaultNoiseFilter();
|
|
29
29
|
}
|
|
30
30
|
let noiseFilter = getCustomNoiseFilters();
|
|
31
31
|
if (noiseFilter.length == 0) {
|
|
32
32
|
printMessage(`No custom noise filters defined. Using defaults.`, 'info');
|
|
33
|
-
noiseFilter =
|
|
33
|
+
noiseFilter = getDefaultNoiseFilter();
|
|
34
34
|
try {
|
|
35
35
|
fs.writeFileSync(filename, JSON.stringify(noiseFilter, null, 2));
|
|
36
36
|
printMessage(`The default filters were saved in ${filename}. You can change the filters as needed.`, 'info');
|
package/esm/utils/Config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","names":["fs","os","Log","printMessage","
|
|
1
|
+
{"version":3,"file":"Config.js","names":["fs","os","Log","printMessage","getDefaultNoiseFilter","FRODO_CONFIG_PATH_KEY","FRODO_LOG_NOISEFILTER_FILENAME","getConfigPath","process","env","homedir","getCustomNoiseFilters","filename","noiseFilter","data","readFileSync","JSON","parse","e","message","getNoiseFilters","defaults","length","writeFileSync","stringify"],"sources":["utils/Config.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport { Log } from '@rockcarver/frodo-lib';\n\nimport { printMessage } from './Console';\n\nconst { getDefaultNoiseFilter } = Log;\n\nexport const FRODO_CONFIG_PATH_KEY = 'FRODO_CONFIG_PATH';\nexport const FRODO_LOG_NOISEFILTER_FILENAME = 'LoggingNoiseFilter.json';\n\nexport function getConfigPath(): string {\n return process.env[FRODO_CONFIG_PATH_KEY] || `${os.homedir()}/.frodo`;\n}\n\nfunction getCustomNoiseFilters(): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n let noiseFilter = [];\n try {\n const data = fs.readFileSync(filename, 'utf8');\n noiseFilter = JSON.parse(data);\n } catch (e) {\n printMessage(`Error reading ${filename} (${e.message})`, 'error');\n }\n return noiseFilter;\n}\n\nexport function getNoiseFilters(defaults: boolean): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n if (defaults) {\n printMessage(`Using default logging noise filters.`, 'info');\n return getDefaultNoiseFilter();\n }\n let noiseFilter = getCustomNoiseFilters();\n if (noiseFilter.length == 0) {\n printMessage(`No custom noise filters defined. Using defaults.`, 'info');\n noiseFilter = getDefaultNoiseFilter();\n try {\n fs.writeFileSync(filename, JSON.stringify(noiseFilter, null, 2));\n printMessage(\n `The default filters were saved in ${filename}. You can change the filters as needed.`,\n 'info'\n );\n } catch (e) {\n printMessage(\n `Error creating noise filter configuration with default values.`,\n 'error'\n );\n }\n }\n return noiseFilter;\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,GAAG,QAAQ,uBAAuB;AAE3C,SAASC,YAAY,QAAQ,WAAW;AAExC,MAAM;EAAEC;AAAsB,CAAC,GAAG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,CACT,qCAAoCS,QAAS,yCAAwC,EACtF,MACF,CAAC;IACH,CAAC,CAAC,OAAOM,CAAC,EAAE;MACVf,YAAY,CACT,gEAA+D,EAChE,OACF,CAAC;IACH;EACF;EACA,OAAOU,WAAW;AACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rockcarver/frodo-cli",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.3",
|
|
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": [
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
]
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
|
-
"@rockcarver/frodo-lib": "0.19.
|
|
102
|
+
"@rockcarver/frodo-lib": "0.19.2",
|
|
103
103
|
"chokidar": "^3.5.3",
|
|
104
104
|
"cli-progress": "^3.11.2",
|
|
105
105
|
"cli-table3": "^0.6.3",
|