Skip to content

Commit

Permalink
feat: keep a reference to the credentials in the config (#253)
Browse files Browse the repository at this point in the history
* keep a reference to the credentials in the config

* no need to lowercase
  • Loading branch information
moritzraho authored Jun 9, 2020
1 parent 348f3ea commit 21a3ed6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '_'), integration_type: c.integration_type }))
}

/**
* Import a downloadable config and write to the appropriate .env (credentials) and .aio (non-credentials) files.
*
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/__fixtures__/config.orgid.aio
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/__fixtures__/config.orgid.no.jwt.aio
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/__fixtures__/existing.merged.aio
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions test/__fixtures__/valid.config.aio
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 21a3ed6

Please sign in to comment.