From 3e861b07375fd5c8e13dff2f2b48fb54b1c69c05 Mon Sep 17 00:00:00 2001 From: Moritz Raho Date: Tue, 2 Jun 2020 18:38:30 +0200 Subject: [PATCH 1/2] keep a reference to the credentials in the config --- src/lib/import.js | 34 ++++++++++++++++++++++- test/__fixtures__/config.orgid.aio | 12 ++++++++ test/__fixtures__/config.orgid.no.jwt.aio | 7 +++++ test/__fixtures__/existing.merged.aio | 17 ++++++++++++ test/__fixtures__/valid.config.aio | 17 ++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/lib/import.js b/src/lib/import.js index 772211d5..5c0abf7f 100644 --- a/src/lib/import.js +++ b/src/lib/import.js @@ -521,6 +521,37 @@ function transformCredentials (credentials, imsOrgId) { }, {}) } +/** + * Trim the credentials array to only keep a reference to each integration credential. + * Replace spaces in the name with _ and lowercase the name + * + * @example + * from: + * [{ + * "id": "17561142", + * "name": "Project Foo", + * "integration_type": "oauthweb", + * "oauth2": { + * "client_id": "XYXYXYXYXYXYXYXYX", + * "client_secret": "XYXYXYXYZZZZZZ", + * "redirect_uri": "https://test123" + * } + * }] + * to: + * [{ + * "id": "17561142", + * "name": "project_foo", + * "integration_type": "oauthweb" + * }] + * + * @param {Array} credentials array from Downloadable File Format + * @returns {object} an array holding only the references to the credentials + * @private + */ +function credentialsReferences (credentials) { + return credentials.map(c => ({ id: c.id, name: c.name.replace(/ /gi, '_').toLowerCase(), integration_type: c.integration_type })) +} + /** * Import a downloadable config and write to the appropriate .env (credentials) and .aio (non-credentials) files. * @@ -549,7 +580,8 @@ async function importConfigJson (configFileLocation, destinationFolder = process // remove the credentials delete config.project.workspace.details.runtime - delete config.project.workspace.details.credentials + // keep only a reference to the credentials in the aio config (hiding secrets) + config.project.workspace.details.credentials = credentialsReferences(config.project.workspace.details.credentials) // write to the console config (for the `aio console` commands) await writeConsoleConfig(config) diff --git a/test/__fixtures__/config.orgid.aio b/test/__fixtures__/config.orgid.aio index bb68d980..6760e58d 100644 --- a/test/__fixtures__/config.orgid.aio +++ b/test/__fixtures__/config.orgid.aio @@ -17,6 +17,18 @@ "action_url": "https://ABCD-TestProject-TestWorkspace.adobeioruntime.net", "app_url": "https://ABCD-TestProject-TestWorkspace.adobestatic.net", "details": { + "credentials": [ + { + "id": "17606512", + "name": "projectb", + "integration_type": "service" + }, + { + "id": "17950", + "name": "newtestintegration8", + "integration_type": "oauthandroid" + } + ], "services": [] } } diff --git a/test/__fixtures__/config.orgid.no.jwt.aio b/test/__fixtures__/config.orgid.no.jwt.aio index bb68d980..89743979 100644 --- a/test/__fixtures__/config.orgid.no.jwt.aio +++ b/test/__fixtures__/config.orgid.no.jwt.aio @@ -17,6 +17,13 @@ "action_url": "https://ABCD-TestProject-TestWorkspace.adobeioruntime.net", "app_url": "https://ABCD-TestProject-TestWorkspace.adobestatic.net", "details": { + "credentials": [ + { + "id": "17950", + "name": "newtestintegration8", + "integration_type": "oauthandroid" + } + ], "services": [] } } diff --git a/test/__fixtures__/existing.merged.aio b/test/__fixtures__/existing.merged.aio index bf6c527b..8a366b6b 100644 --- a/test/__fixtures__/existing.merged.aio +++ b/test/__fixtures__/existing.merged.aio @@ -25,6 +25,23 @@ "action_url": "https://ABCD-TestProject-TestWorkspace.adobeioruntime.net", "app_url": "https://ABCD-TestProject-TestWorkspace.adobestatic.net", "details": { + "credentials": [ + { + "id": "17561142", + "name": "projéct_a", + "integration_type": "oauthweb" + }, + { + "id": "17606512", + "name": "pröjectb", + "integration_type": "service" + }, + { + "id": "17950", + "name": "new_test_intégration_8", + "integration_type": "oauthandroid" + } + ], "services": [ { "code": "AdobeIOManagementAPISDK", diff --git a/test/__fixtures__/valid.config.aio b/test/__fixtures__/valid.config.aio index b0bb27d5..93d24b94 100644 --- a/test/__fixtures__/valid.config.aio +++ b/test/__fixtures__/valid.config.aio @@ -17,6 +17,23 @@ "action_url": "https://ABCD-TestProject-TestWorkspace.adobeioruntime.net", "app_url": "https://ABCD-TestProject-TestWorkspace.adobestatic.net", "details": { + "credentials": [ + { + "id": "17561142", + "name": "projéct_a", + "integration_type": "oauthweb" + }, + { + "id": "17606512", + "name": "pröjectb", + "integration_type": "service" + }, + { + "id": "17950", + "name": "new_test_intégration_8", + "integration_type": "oauthandroid" + } + ], "services": [ { "code": "AdobeIOManagementAPISDK", From 60c745254ed5336a71b6e48244c66ea3bcf43d32 Mon Sep 17 00:00:00 2001 From: Moritz Raho Date: Tue, 2 Jun 2020 18:48:35 +0200 Subject: [PATCH 2/2] no need to lowercase --- src/lib/import.js | 2 +- test/__fixtures__/config.orgid.aio | 4 ++-- test/__fixtures__/config.orgid.no.jwt.aio | 2 +- test/__fixtures__/existing.merged.aio | 6 +++--- test/__fixtures__/valid.config.aio | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/import.js b/src/lib/import.js index 5c0abf7f..4c97d964 100644 --- a/src/lib/import.js +++ b/src/lib/import.js @@ -549,7 +549,7 @@ function transformCredentials (credentials, imsOrgId) { * @private */ function credentialsReferences (credentials) { - return credentials.map(c => ({ id: c.id, name: c.name.replace(/ /gi, '_').toLowerCase(), integration_type: c.integration_type })) + return credentials.map(c => ({ id: c.id, name: c.name.replace(/ /gi, '_'), integration_type: c.integration_type })) } /** diff --git a/test/__fixtures__/config.orgid.aio b/test/__fixtures__/config.orgid.aio index 6760e58d..88849a3e 100644 --- a/test/__fixtures__/config.orgid.aio +++ b/test/__fixtures__/config.orgid.aio @@ -20,12 +20,12 @@ "credentials": [ { "id": "17606512", - "name": "projectb", + "name": "ProjectB", "integration_type": "service" }, { "id": "17950", - "name": "newtestintegration8", + "name": "NewTestIntegration8", "integration_type": "oauthandroid" } ], diff --git a/test/__fixtures__/config.orgid.no.jwt.aio b/test/__fixtures__/config.orgid.no.jwt.aio index 89743979..3c883e29 100644 --- a/test/__fixtures__/config.orgid.no.jwt.aio +++ b/test/__fixtures__/config.orgid.no.jwt.aio @@ -20,7 +20,7 @@ "credentials": [ { "id": "17950", - "name": "newtestintegration8", + "name": "NewTestIntegration8", "integration_type": "oauthandroid" } ], diff --git a/test/__fixtures__/existing.merged.aio b/test/__fixtures__/existing.merged.aio index 8a366b6b..f212c534 100644 --- a/test/__fixtures__/existing.merged.aio +++ b/test/__fixtures__/existing.merged.aio @@ -28,17 +28,17 @@ "credentials": [ { "id": "17561142", - "name": "projéct_a", + "name": "Projéct_A", "integration_type": "oauthweb" }, { "id": "17606512", - "name": "pröjectb", + "name": "PröjectB", "integration_type": "service" }, { "id": "17950", - "name": "new_test_intégration_8", + "name": "New_Test_Intégration_8", "integration_type": "oauthandroid" } ], diff --git a/test/__fixtures__/valid.config.aio b/test/__fixtures__/valid.config.aio index 93d24b94..189e432f 100644 --- a/test/__fixtures__/valid.config.aio +++ b/test/__fixtures__/valid.config.aio @@ -20,17 +20,17 @@ "credentials": [ { "id": "17561142", - "name": "projéct_a", + "name": "Projéct_A", "integration_type": "oauthweb" }, { "id": "17606512", - "name": "pröjectb", + "name": "PröjectB", "integration_type": "service" }, { "id": "17950", - "name": "new_test_intégration_8", + "name": "New_Test_Intégration_8", "integration_type": "oauthandroid" } ],