Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep a reference to the credentials in the config #253

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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