Skip to content

Commit

Permalink
Merge pull request #386 from trivir/bugfix/fix-script-imports-and-exp…
Browse files Browse the repository at this point in the history
…orts

Fix --watch script imports and improve script exports
  • Loading branch information
vscheuber committed May 1, 2024
2 parents 8d18b66 + f66e43a commit 2381041
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 110 deletions.
5 changes: 3 additions & 2 deletions src/cli/script/script-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ program
.addOption(
new Option(
'-x, --extract',
'Extract the script from the exported file, and save it to a separate file. Ignored with -n or -a.'
'Extract the script from the exported file, and save it to a separate file. Ignored with -a.'
)
)
.addOption(
Expand All @@ -80,7 +80,8 @@ program
const outcome = await exportScriptByNameToFile(
options.scriptName || options.script,
options.file,
options.metadata
options.metadata,
options.extract
);
if (!outcome) process.exitCode = 1;
}
Expand Down
6 changes: 5 additions & 1 deletion src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
getFullExportConfig,
getFullExportConfigFromDirectory,
} from '../utils/Config';
import { cleanupProgressIndicators, printError, printMessage } from '../utils/Console';
import {
cleanupProgressIndicators,
printError,
printMessage,
} from '../utils/Console';
import { extractScriptToFile } from './ScriptOps';

const {
Expand Down
6 changes: 5 additions & 1 deletion src/ops/ScriptOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ export async function exportScriptToFile(
* @param {string} name script name
* @param {string} file file name
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
* @param {boolean} extract Extracts the scripts from the exports into separate files if true
* @returns {Promise<boolean>} true if successful, false otherwise
*/
export async function exportScriptByNameToFile(
name: string,
file: string,
includeMeta: boolean = true
includeMeta: boolean = true,
extract: boolean = false
): Promise<boolean> {
debugMessage(`Cli.ScriptOps.exportScriptByNameToFile: start`);
try {
Expand All @@ -217,6 +219,7 @@ export async function exportScriptByNameToFile(
const filePath = getFilePath(fileName, true);
spinSpinner(`Exporting script '${name}' to '${filePath}'...`);
const scriptExport = await exportScriptByName(name);
if (extract) extractScriptToFile(scriptExport);
saveJsonToFile(scriptExport, filePath, includeMeta);
succeedSpinner(`Exported script '${name}' to '${filePath}'.`);
debugMessage(`Cli.ScriptOps.exportScriptByNameToFile: end`);
Expand Down Expand Up @@ -455,6 +458,7 @@ export async function importScriptsFromFiles(
],
{
persistent: watch,
ignoreInitial: watch,
}
);

Expand Down
3 changes: 1 addition & 2 deletions test/client_cli/en/__snapshots__/script-export.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ Options:
specified, may or may not produce additional
output.
-x, --extract Extract the script from the exported file, and
save it to a separate file. Ignored with -n or
-a.
save it to a separate file. Ignored with -a.
Evironment Variables:
FRODO_HOST: Access Management base URL. Overrides 'host' argument.
Expand Down
42 changes: 22 additions & 20 deletions test/e2e/__snapshots__/script-export.e2e.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16144,9 +16144,28 @@ exports[`frodo script export "frodo script export -NaD scriptExportTestDir2": sh
}
`;

exports[`frodo script export "frodo script export -Nn 'GitHub Profile Normalization' -D scriptExportTestDir1": should export the script named "GitHub Profile Normalization" into the directory scriptExportTestDir1 1`] = `""`;
exports[`frodo script export "frodo script export -Nxn 'GitHub Profile Normalization' -D scriptExportTestDir1": should export the script named "GitHub Profile Normalization" into the directory scriptExportTestDir1 1`] = `""`;

exports[`frodo script export "frodo script export -Nn 'GitHub Profile Normalization' -D scriptExportTestDir1": should export the script named "GitHub Profile Normalization" into the directory scriptExportTestDir1: scriptExportTestDir1/GitHub-Profile-Normalization.script.json 1`] = `
exports[`frodo script export "frodo script export -Nxn 'GitHub Profile Normalization' -D scriptExportTestDir1": should export the script named "GitHub Profile Normalization" into the directory scriptExportTestDir1: scriptExportTestDir1/GitHub-Profile-Normalization.script.groovy 1`] = `
"/*
* Copyright 2022 ForgeRock AS. All Rights Reserved
*
* Use of this code requires a commercial software license with ForgeRock AS.
* or with one of its affiliates. All use shall be exclusively subject
* to such license between the licensee and ForgeRock AS.
*/

import static org.forgerock.json.JsonValue.field
import static org.forgerock.json.JsonValue.json
import static org.forgerock.json.JsonValue.object

return json(object(
field("id", rawProfile.id),
field("displayName", rawProfile.name),
field("username", rawProfile.login)))"
`;

exports[`frodo script export "frodo script export -Nxn 'GitHub Profile Normalization' -D scriptExportTestDir1": should export the script named "GitHub Profile Normalization" into the directory scriptExportTestDir1: scriptExportTestDir1/GitHub-Profile-Normalization.script.json 1`] = `
{
"script": {
"a7a78773-445b-4eca-bb93-409e86bced81": {
Expand All @@ -16161,24 +16180,7 @@ exports[`frodo script export "frodo script export -Nn 'GitHub Profile Normalizat
"lastModifiedBy": "null",
"lastModifiedDate": 0,
"name": "GitHub Profile Normalization",
"script": [
"/*",
" * Copyright 2022 ForgeRock AS. All Rights Reserved",
" *",
" * Use of this code requires a commercial software license with ForgeRock AS.",
" * or with one of its affiliates. All use shall be exclusively subject",
" * to such license between the licensee and ForgeRock AS.",
" */",
"",
"import static org.forgerock.json.JsonValue.field",
"import static org.forgerock.json.JsonValue.json",
"import static org.forgerock.json.JsonValue.object",
"",
"return json(object(",
" field("id", rawProfile.id),",
" field("displayName", rawProfile.name),",
" field("username", rawProfile.login)))",
],
"script": "file://scriptExportTestDir1/GitHub-Profile-Normalization.script.groovy",
},
},
}
Expand Down
26 changes: 13 additions & 13 deletions test/e2e/mocks/github_584874290/recording.har

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions test/e2e/mocks/npmjs_1455397529/recording.har

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"log": {
"_recordingName": "script/export/0_Nn_D/am",
"_recordingName": "script/export/0_Nxn_D/am",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
Expand All @@ -21,11 +21,11 @@
},
{
"name": "user-agent",
"value": "@rockcarver/frodo-lib/2.0.0-58"
"value": "@rockcarver/frodo-lib/2.0.0-77"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "content-type",
Expand All @@ -51,7 +51,7 @@
"content": {
"mimeType": "application/json;charset=UTF-8",
"size": 553,
"text": "{\"_id\":\"*\",\"_rev\":\"1874515102\",\"domains\":[],\"protectedUserAttributes\":[\"telephoneNumber\",\"mail\"],\"cookieName\":\"6ac6499e9da2071\",\"secureCookie\":true,\"forgotPassword\":\"false\",\"forgotUsername\":\"false\",\"kbaEnabled\":\"false\",\"selfRegistration\":\"false\",\"lang\":\"en-US\",\"successfulUserRegistrationDestination\":\"default\",\"socialImplementations\":[],\"referralsEnabled\":\"false\",\"zeroPageLogin\":{\"enabled\":false,\"refererWhitelist\":[],\"allowedWithoutReferer\":true},\"realm\":\"/\",\"xuiUserSessionValidationEnabled\":true,\"fileBasedConfiguration\":true,\"userIdAttributes\":[]}"
"text": "{\"_id\":\"*\",\"_rev\":\"1874515102\",\"domains\":[],\"protectedUserAttributes\":[\"telephoneNumber\",\"mail\"],\"cookieName\":\"6ac6499e9da2071\",\"secureCookie\":true,\"forgotPassword\":\"false\",\"forgotUsername\":\"false\",\"kbaEnabled\":\"false\",\"selfRegistration\":\"false\",\"lang\":\"en-US\",\"successfulUserRegistrationDestination\":\"default\",\"socialImplementations\":[],\"referralsEnabled\":\"false\",\"zeroPageLogin\":{\"enabled\":false,\"allowedWithoutReferer\":true,\"refererWhitelist\":[]},\"realm\":\"/\",\"xuiUserSessionValidationEnabled\":true,\"fileBasedConfiguration\":true,\"userIdAttributes\":[]}"
},
"cookies": [],
"headers": [
Expand Down Expand Up @@ -109,16 +109,20 @@
},
{
"name": "date",
"value": "Thu, 04 Jan 2024 16:10:10 GMT"
"value": "Mon, 29 Apr 2024 19:15:16 GMT"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "strict-transport-security",
"value": "max-age=31536000; includeSubDomains; preload;"
},
{
"name": "x-robots-tag",
"value": "none"
},
{
"name": "via",
"value": "1.1 google"
Expand All @@ -128,22 +132,22 @@
"value": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
}
],
"headersSize": 767,
"headersSize": 787,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-01-04T16:10:10.224Z",
"time": 111,
"startedDateTime": "2024-04-29T19:15:16.272Z",
"time": 572,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 111
"wait": 572
}
},
{
Expand All @@ -160,11 +164,11 @@
},
{
"name": "user-agent",
"value": "@rockcarver/frodo-lib/2.0.0-58"
"value": "@rockcarver/frodo-lib/2.0.0-77"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "content-type",
Expand All @@ -190,11 +194,11 @@
"url": "https://openam-frodo-dev.forgeblocks.com/am/json/serverinfo/version"
},
"response": {
"bodySize": 281,
"bodySize": 275,
"content": {
"mimeType": "application/json;charset=UTF-8",
"size": 281,
"text": "{\"_id\":\"version\",\"_rev\":\"-347675290\",\"version\":\"7.5.0-SNAPSHOT\",\"fullVersion\":\"ForgeRock Access Management 7.5.0-SNAPSHOT Build c27d160f2238f1869b36b4e3a66ff9baa06e89f7 (2023-November-16 17:31)\",\"revision\":\"c27d160f2238f1869b36b4e3a66ff9baa06e89f7\",\"date\":\"2023-November-16 17:31\"}"
"size": 275,
"text": "{\"_id\":\"version\",\"_rev\":\"2101502404\",\"version\":\"7.5.0-SNAPSHOT\",\"fullVersion\":\"ForgeRock Access Management 7.5.0-SNAPSHOT Build 6ad90593128399cf212a047d3ccd08218f270fcf (2024-March-26 08:49)\",\"revision\":\"6ad90593128399cf212a047d3ccd08218f270fcf\",\"date\":\"2024-March-26 08:49\"}"
},
"cookies": [],
"headers": [
Expand Down Expand Up @@ -232,7 +236,7 @@
},
{
"name": "etag",
"value": "\"-347675290\""
"value": "\"2101502404\""
},
{
"name": "expires",
Expand All @@ -248,20 +252,24 @@
},
{
"name": "content-length",
"value": "281"
"value": "275"
},
{
"name": "date",
"value": "Thu, 04 Jan 2024 16:10:10 GMT"
"value": "Mon, 29 Apr 2024 19:15:16 GMT"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "strict-transport-security",
"value": "max-age=31536000; includeSubDomains; preload;"
},
{
"name": "x-robots-tag",
"value": "none"
},
{
"name": "via",
"value": "1.1 google"
Expand All @@ -271,22 +279,22 @@
"value": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
}
],
"headersSize": 767,
"headersSize": 787,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-01-04T16:10:10.480Z",
"time": 76,
"startedDateTime": "2024-04-29T19:15:17.011Z",
"time": 80,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 76
"wait": 80
}
},
{
Expand All @@ -303,11 +311,11 @@
},
{
"name": "user-agent",
"value": "@rockcarver/frodo-lib/2.0.0-58"
"value": "@rockcarver/frodo-lib/2.0.0-77"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "content-type",
Expand Down Expand Up @@ -396,16 +404,20 @@
},
{
"name": "date",
"value": "Thu, 04 Jan 2024 16:10:10 GMT"
"value": "Mon, 29 Apr 2024 19:15:16 GMT"
},
{
"name": "x-forgerock-transactionid",
"value": "frodo-60abbd8f-ad11-4557-842a-da1aa300dc13"
"value": "frodo-5bbb8bea-40d3-48d5-9f7f-644236413fde"
},
{
"name": "strict-transport-security",
"value": "max-age=31536000; includeSubDomains; preload;"
},
{
"name": "x-robots-tag",
"value": "none"
},
{
"name": "via",
"value": "1.1 google"
Expand All @@ -415,22 +427,22 @@
"value": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
}
],
"headersSize": 774,
"headersSize": 794,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-01-04T16:10:10.652Z",
"time": 67,
"startedDateTime": "2024-04-29T19:15:17.226Z",
"time": 91,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 67
"wait": 91
}
}
],
Expand Down
Loading

0 comments on commit 2381041

Please sign in to comment.