Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/jest-resolve-29.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron authored Jul 17, 2023
2 parents 55dbd54 + 8a67c9e commit b77fc50
Show file tree
Hide file tree
Showing 23 changed files with 1,085 additions and 66 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- run: npm test
- name: upload coverage
if: success()
run: curl -s https://codecov.io/bash | bash
env:
CODECOV_NAME: ${{ runner.os }} node.js ${{ matrix.node-version }}
shell: bash
uses: codecov/codecov-action@v3.1.1
with:
name: ${{ runner.os }} node.js ${{ matrix.node-version }}
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ DESCRIPTION
Manage your Adobe I/O Events
```

_See code: [src/commands/event/index.ts](https://github.com/adobe/aio-cli-plugin-events/blob/v3.0.1/src/commands/event/index.ts)_
_See code: [src/commands/event/index.ts](https://github.com/adobe/aio-cli-plugin-events/blob/v3.2.0/src/commands/event/index.ts)_

## `aio event eventmetadata`

Expand Down Expand Up @@ -326,14 +326,19 @@ Get list of all Providers for the Organization

```
USAGE
$ aio event provider list [--help] [-v] [--version] [-j | -y]
$ aio event provider list [--help] [-v] [--version] [--fetchEventMetadata] [--providerMetadataId <value> | -p <value>]
[--instanceId <value>] [-j | -y]
FLAGS
-j, --json Output json
-v, --verbose Verbose output
-y, --yml Output yml
--help Show help
--version Show version
-j, --json Output json
-p, --providerMetadataIds=<value>... Filter providers for org by list of provider metadata ids
-v, --verbose Verbose output
-y, --yml Output yml
--fetchEventMetadata Fetch event metadata with provider
--help Show help
--instanceId=<value> Filter providers for org by provider metadata id (and instance id if applicable)
--providerMetadataId=<value> Filter providers for org by provider metadata id (and instance id if applicable)
--version Show version
DESCRIPTION
Get list of all Providers for the Organization
Expand All @@ -348,14 +353,19 @@ Get list of all Providers for the Organization

```
USAGE
$ aio event provider ls [--help] [-v] [--version] [-j | -y]
$ aio event provider ls [--help] [-v] [--version] [--fetchEventMetadata] [--providerMetadataId <value> | -p <value>]
[--instanceId <value>] [-j | -y]
FLAGS
-j, --json Output json
-v, --verbose Verbose output
-y, --yml Output yml
--help Show help
--version Show version
-j, --json Output json
-p, --providerMetadataIds=<value>... Filter providers for org by list of provider metadata ids
-v, --verbose Verbose output
-y, --yml Output yml
--fetchEventMetadata Fetch event metadata with provider
--help Show help
--instanceId=<value> Filter providers for org by provider metadata id (and instance id if applicable)
--providerMetadataId=<value> Filter providers for org by provider metadata id (and instance id if applicable)
--version Show version
DESCRIPTION
Get list of all Providers for the Organization
Expand Down
30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"name": "@adobe/aio-cli-plugin-events",
"description": "Adobe I/O Events Plugin for the Adobe I/O CLI",
"version": "3.0.1",
"version": "3.2.0",
"main": "src/index.js",
"keywords": [
"oclif-plugin"
],
"license": "Apache-2.0",
"dependencies": {
"@adobe/aio-lib-console": "^4.0.0",
"@adobe/aio-lib-core-config": "^3.0.0",
"@adobe/aio-lib-core-logging": "^2.0.0",
"@adobe/aio-lib-events": "^3.0.0",
"@adobe/aio-lib-events": "^3.1.0",
"@adobe/aio-lib-ims": "^6.0.1",
"@oclif/core": "^1.5.2",
"js-yaml": "^3.13.1",
"inquirer": "^8.2.5"
"inquirer": "^8.2.5",
"js-yaml": "^3.13.1"
},
"repository": "adobe/aio-cli-plugin-events",
"devDependencies": {
Expand All @@ -21,7 +26,6 @@
"chalk": "^4.0.0",
"eol": "^0.9.1",
"eslint": "^8.38.0",
"execa": "^4.0.2",
"eslint-config-oclif": "^3.1.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
Expand All @@ -31,7 +35,8 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^27.5.1",
"execa": "^4.0.2",
"jest": "^29.5.0",
"jest-haste-map": "^27.5.1",
"jest-junit": "^10.0.0",
"jest-resolve": "^29.5.0",
Expand All @@ -46,19 +51,20 @@
"/oclif.manifest.json",
"/src"
],
"keywords": [
"oclif-plugin"
],
"license": "Apache-2.0",
"oclif": {
"commands": "./src/commands",
"bin": "aio",
"topicSeparator": " ",
"devPlugins": [
"@oclif/plugin-help"
]
],
"hooks": {
"pre-deploy-event-reg": "./src/hooks/pre-deploy-event-reg.js",
"post-deploy-event-reg": "./src/hooks/post-deploy-event-reg.js",
"pre-undeploy-event-reg": "./src/hooks/pre-deploy-event-reg.js",
"post-undeploy-event-reg": "./src/hooks/post-deploy-event-reg.js"
}
},
"main": "src/index.js",
"scripts": {
"posttest": "eslint src test e2e",
"test": "npm run unit-tests",
Expand Down
43 changes: 36 additions & 7 deletions src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ const Console = require('@adobe/aio-lib-console')
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 () {
// login
await context.setCli({ 'cli.bare-output': true }, false) // set this globally
aioLogger.debug('run login')
this.accessToken = await getToken(CLI) // user access token, would work with jwt too
this.accessToken = await getToken(CLI) // user access token, would work with JWT/OAuth Server-to-Server token too

// init console sdk
this.consoleClient = await Console.init(this.accessToken, CONSOLE_API_KEY)
Expand All @@ -42,8 +51,8 @@ class BaseCommand extends Command {
aioLogger.debug(`${JSON.stringify(this.conf)}`)

// init the event client
aioLogger.debug(`initializing aio-lib-events with org=${this.conf.org.code}, apiKey(jwtClientId)=${this.conf.integration.jwtClientId} and accessToken=<hidden>`)
this.eventClient = await Events.init(this.conf.org.code, this.conf.integration.jwtClientId, this.accessToken)
aioLogger.debug(`initializing aio-lib-events with org=${this.conf.org.code}, apiKey(clientId)=${this.conf.integration.clientId} and accessToken=<hidden>`)
this.eventClient = await Events.init(this.conf.org.code, this.conf.integration.clientId, this.accessToken)
}

// Note: loadConfig should be shared across plugins at the aio-lib-ims level
Expand All @@ -69,7 +78,7 @@ class BaseCommand extends Command {
org: { id: localProject.org.id, name: localProject.org.name, code: localProject.org.ims_org_id },
project: { id: localProject.id, name: localProject.name, title: localProject.title },
workspace: { id: localProject.workspace.id, name: localProject.workspace.name },
integration: { id: workspaceIntegration.id, name: workspaceIntegration.name, jwtClientId: integrationCredentials.client_id }
integration: { id: workspaceIntegration.id, name: workspaceIntegration.name, clientId: integrationCredentials.client_id }
}
}

Expand All @@ -91,7 +100,13 @@ class BaseCommand extends Command {
// fetch integration details
const consoleJSON = await consoleClient.downloadWorkspaceJson(org.id, project.id, workspace.id)
const workspaceIntegration = this.extractServiceIntegrationConfig(consoleJSON.body.project.workspace)
integration = { id: workspaceIntegration.id, name: workspaceIntegration.name, jwtClientId: workspaceIntegration.jwt.client_id }
const integrationType = workspaceIntegration.integration_type
const credentialJsonKey = INTEGRATION_TYPES_TO_JSON_KEYS_MAP[integrationType]
integration = {
id: workspaceIntegration.id,
name: workspaceIntegration.name,
clientId: workspaceIntegration[credentialJsonKey].client_id
}

// cache the integration details for future use
aioLogger.debug(`caching integration details with workspaceId=${workspace.id} to ${EVENTS_CONFIG_KEY}`)
Expand All @@ -118,9 +133,13 @@ class BaseCommand extends Command {
/** @private */
extractServiceIntegrationConfig (workspaceConfig) {
// note here we take the first that matches
const workspaceIntegration = workspaceConfig.details.credentials && workspaceConfig.details.credentials.find(c => c.integration_type === 'service')
const workspaceIntegration = workspaceConfig.details.credentials &&
workspaceConfig.details.credentials.find(c => {
return Object.keys(INTEGRATION_TYPES_TO_JSON_KEYS_MAP)
.includes(c.integration_type)
})
if (!workspaceIntegration) {
throw new Error(`Workspace ${workspaceConfig.name} has no JWT integration`)
throw new Error(this.getErrorMessageForInvalidCredentials(workspaceConfig.name))
}
return workspaceIntegration
}
Expand All @@ -144,6 +163,16 @@ class BaseCommand extends Command {
data = JSON.parse(JSON.stringify(data))
this.log(yaml.safeDump(data, { noCompatMode: true }))
}

/**
* Returns error message for invalid credential configuration in a workspace
*
* @param {string} workspaceName - name of the workspace
* @returns {string} error message in case the workspace has invalid credential configuration
*/
getErrorMessageForInvalidCredentials (workspaceName) {
return `Workspace ${workspaceName} has no oAuth Server-to-Server or JWT credential associated.`
}
}

BaseCommand.flags = {
Expand Down
28 changes: 27 additions & 1 deletion src/commands/event/provider/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class ProviderListCommand extends BaseCommand {
try {
await this.initSdk()
cli.action.start('Fetching all Event Providers')
const providers = await this.eventClient.getAllProviders(this.conf.org.id)
const options = {
fetchEventMetadata: flags.fetchEventMetadata,
filterBy: {
providerMetadataId: flags.providerMetadataId,
instanceId: flags.instanceId,
providerMetadataIds: flags.providerMetadataIds
}
}
const providers = await this.eventClient.getAllProviders(this.conf.org.id, options)
cli.action.stop()
if (flags.json) {
this.printJson(providers)
Expand Down Expand Up @@ -65,6 +73,24 @@ ProviderListCommand.aliases = [

ProviderListCommand.flags = {
...BaseCommand.flags,
fetchEventMetadata: Flags.boolean({
description: 'Fetch event metadata with provider'
}),
providerMetadataId: Flags.string({
multiple: false,
description: 'Filter providers for org by provider metadata id (and instance id if applicable)',
exclusive: ['providerMetadataIds']
}),
instanceId: Flags.string({
multiple: false,
description: 'Filter providers for org by provider metadata id (and instance id if applicable)'
}),
providerMetadataIds: Flags.string({
multiple: true,
char: 'p',
description: 'Filter providers for org by list of provider metadata ids',
exclusive: ['providerMetadataId']
}),
json: Flags.boolean({
description: 'Output json',
char: 'j',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/event/registration/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CreateCommand extends BaseCommand {
const body = this.parseJSONFile(args.bodyJSONFile)

if (!body.client_id) {
body.client_id = this.conf.integration.jwtClientId
body.client_id = this.conf.integration.clientId
}
// other checks are performed by the server

Expand Down
17 changes: 17 additions & 0 deletions src/hooks/post-deploy-event-reg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const {
WEBHOOK, deployRegistration
} = require('./utils/hook-utils')

module.exports = async function ({ appConfig, force }) {
await deployRegistration({ appConfig }, WEBHOOK, 'post-deploy-event-reg', force)
}
14 changes: 14 additions & 0 deletions src/hooks/post-undeploy-event-reg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = async function ({ appConfig }) {
console.log('post-undeploy-event-reg ', appConfig.events)
}
29 changes: 29 additions & 0 deletions src/hooks/pre-deploy-event-reg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const {
JOURNAL, getDeliveryType
} = require('./utils/hook-utils')

module.exports = async function ({ appConfig }) {
if (appConfig && appConfig.events) {
const registrations = appConfig.events.registrations
for (const registrationName in registrations) {
const deliveryType = getDeliveryType(registrations[registrationName])
if (deliveryType === JOURNAL) {
console.log('Journal registrations are not currently supported.')
return
}
}
} else {
console.log('No events to register. Skipping pre-deploy-event-reg hook')
}
}
14 changes: 14 additions & 0 deletions src/hooks/pre-undeploy-event-reg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = async function ({ appConfig }) {
console.log('pre-undeploy-event-reg ', appConfig.events)
}
Loading

0 comments on commit b77fc50

Please sign in to comment.