Skip to content

Commit

Permalink
Fix difference between integration types and corresponding json keys (#…
Browse files Browse the repository at this point in the history
…62)

* Fix difference between integration types and corresponding json keys

- For integration_type: 'service', console stores the credential config corresponding to 'jwt' key
- For integration_type: 'oauth_server_to_server', console stores the credential config corresponding to 'oauth_server_to_server' key
- For integration_type: 'oauth_server_to_server_migrate', console has both 'jwt' and 'oauth_server_to_server` credentials but we fetch details from 'oauth_server_to_server' key

* Fix failing tests

---------

Co-authored-by: Shikhar Tanwar <stanwar.adobe.com>
  • Loading branch information
shikhartanwar authored Jun 15, 2023
1 parent 09b7566 commit 79fb96b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ const CONSOLE_CONFIG_KEY = 'console'
const CONSOLE_API_KEY = 'aio-cli-console-auth'
const EVENTS_CONFIG_KEY = 'events'
const JWT_INTEGRATION_TYPE = 'service'
const JWT_JSON_KEY = 'jwt'
const OAUTH_SERVER_TO_SERVER_INTEGRATION_TYPE = 'oauth_server_to_server'
const OAUTH_SERVER_TO_SERVER_MIGRATE_INTEGRATION_TYPE = 'oauth_server_to_server_migrate'
const INTEGRATION_TYPES_TO_JSON_KEYS_MAP = {
[OAUTH_SERVER_TO_SERVER_INTEGRATION_TYPE]: OAUTH_SERVER_TO_SERVER_INTEGRATION_TYPE,
[OAUTH_SERVER_TO_SERVER_MIGRATE_INTEGRATION_TYPE]: OAUTH_SERVER_TO_SERVER_INTEGRATION_TYPE,
[JWT_INTEGRATION_TYPE]: JWT_JSON_KEY
}

class BaseCommand extends Command {
async initSdk () {
Expand Down Expand Up @@ -95,10 +101,11 @@ class BaseCommand extends Command {
const consoleJSON = await consoleClient.downloadWorkspaceJson(org.id, project.id, workspace.id)
const workspaceIntegration = this.extractServiceIntegrationConfig(consoleJSON.body.project.workspace)
const integrationType = workspaceIntegration.integration_type
const credentialJsonKey = INTEGRATION_TYPES_TO_JSON_KEYS_MAP[integrationType]
integration = {
id: workspaceIntegration.id,
name: workspaceIntegration.name,
clientId: workspaceIntegration[integrationType].client_id
clientId: workspaceIntegration[credentialJsonKey].client_id
}

// cache the integration details for future use
Expand Down Expand Up @@ -128,9 +135,8 @@ class BaseCommand extends Command {
// note here we take the first that matches
const workspaceIntegration = workspaceConfig.details.credentials &&
workspaceConfig.details.credentials.find(c => {
return c.integration_type === OAUTH_SERVER_TO_SERVER_INTEGRATION_TYPE ||
c.integration_type === OAUTH_SERVER_TO_SERVER_MIGRATE_INTEGRATION_TYPE ||
c.integration_type === JWT_INTEGRATION_TYPE
return Object.keys(INTEGRATION_TYPES_TO_JSON_KEYS_MAP)
.includes(c.integration_type)
})
if (!workspaceIntegration) {
throw new Error(this.getErrorMessageForInvalidCredentials(workspaceConfig.name))
Expand Down
4 changes: 2 additions & 2 deletions test/BaseCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('initSDK', () => {
id: _validConfig.integration.id,
name: _validConfig.integration.name,
integration_type: 'service',
service: { client_id: _validConfig.integration.clientId }
jwt: { client_id: _validConfig.integration.clientId }
}
]
}
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('initSDK', () => {
id: _validConfig.integration.id,
name: _validConfig.integration.name,
integration_type: 'service',
service: { client_id: _validConfig.integration.clientId }
jwt: { client_id: _validConfig.integration.clientId }
}
]
}
Expand Down

0 comments on commit 79fb96b

Please sign in to comment.