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

Fix difference between integration types and corresponding json keys #62

Merged
merged 2 commits into from
Jun 15, 2023
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
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