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

IMS org id as input header instead of default parameter #44

Merged
merged 2 commits into from
May 11, 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
2 changes: 2 additions & 0 deletions generators/add-action/analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class AnalyticsGenerator extends ActionGenerator {
// eslint-disable-next-line quotes
requiredParams: `['apiKey', 'companyId']`,
// eslint-disable-next-line quotes
requiredHeaders: `['Authorization']`,
// eslint-disable-next-line quotes
importCode: `const { Analytics } = require('@adobe/aio-sdk')`,
responseCode: `// initialize the sdk
const analyticsClient = await Analytics.init(params.companyId, params.apiKey, token)
Expand Down
2 changes: 2 additions & 0 deletions generators/add-action/campaign-standard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CampaignStandardGenerator extends ActionGenerator {
// eslint-disable-next-line quotes
requiredParams: `['apiKey', 'tenant']`,
// eslint-disable-next-line quotes
requiredHeaders: `['Authorization']`,
// eslint-disable-next-line quotes
importCode: `const { CampaignStandard } = require('@adobe/aio-sdk')`,
responseCode: `// initialize the sdk
const campaignClient = await CampaignStandard.init(params.tenant, params.apiKey, token)
Expand Down
10 changes: 6 additions & 4 deletions generators/add-action/customer-profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class CustomerProfileGenerator extends ActionGenerator {
this.props = {
description: 'This is a sample action showcasing how to access an external Adobe Experience Platform: Realtime Customer Profile API',
// eslint-disable-next-line quotes
requiredParams: `['tenant', 'orgId', 'apiKey', 'entityId', 'entityIdNS']`,
requiredParams: `['tenant', 'apiKey', 'entityId', 'entityIdNS']`,
// eslint-disable-next-line quotes
requiredHeaders: `['Authorization', 'x-gw-ims-org-id']`,
// eslint-disable-next-line quotes
importCode: `const { CustomerProfile } = require('@adobe/aio-sdk')`,
responseCode: `// initialize sdk
const client = await CustomerProfile.init(params.tenant, params.orgId, params.apiKey, token)
const orgId = params.__ow_headers['x-gw-ims-org-id']
const client = await CustomerProfile.init(params.tenant, orgId, params.apiKey, token)
// call methods, eg getProfile
const profile = await client.getProfile({
entityId: params.entityId,
Expand Down Expand Up @@ -53,15 +56,14 @@ class CustomerProfileGenerator extends ActionGenerator {
label: 'please provide your Adobe Experience Platform: Realtime Customer Profile integration tenant, orgId and api key',
vars: [
'CUSTOMER_PROFILE_TENANT',
'CUSTOMER_PROFILE_ORG_ID',
'CUSTOMER_PROFILE_API_KEY'
]
},
dependencies: {
'@adobe/aio-sdk': commonDependencyVersions['@adobe/aio-sdk']
},
actionManifestConfig: {
inputs: { LOG_LEVEL: 'debug', tenant: '$CUSTOMER_PROFILE_TENANT', orgId: '$CUSTOMER_PROFILE_ORG_ID', apiKey: '$CUSTOMER_PROFILE_API_KEY' },
inputs: { LOG_LEVEL: 'debug', tenant: '$CUSTOMER_PROFILE_TENANT', apiKey: '$CUSTOMER_PROFILE_API_KEY' },
annotations: { final: true } // makes sure loglevel cannot be overwritten by request param
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ beforeEach(() => {
mockLoggerInstance.debug.mockReset()
mockLoggerInstance.error.mockReset()
})
const fakeRequestParams = { tenant: 'fakeId', orgId: 'fakeOrgId', apiKey: 'fakeKey', entityId: 'fakeEntityId', entityIdNS: 'fakeEntityIdNS', __ow_headers: { authorization: 'Bearer fakeToken' } }
const fakeRequestParams = { tenant: 'fakeId', apiKey: 'fakeKey', entityId: 'fakeEntityId', entityIdNS: 'fakeEntityIdNS', __ow_headers: { authorization: 'Bearer fakeToken', 'x-gw-ims-org-id': 'fakeOrgId' } }
describe('<%= actionName %>', () => {
test('main should be defined', () => {
expect(action.main).toBeInstanceOf(Function)
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('<%= actionName %>', () => {
expect(response).toEqual({
error: {
statusCode: 400,
body: { error: 'missing header(s) \'authorization\' and missing parameter(s) \'tenant,orgId,apiKey,entityId,entityIdNS\'' }
body: { error: 'missing header(s) \'authorization,x-gw-ims-org-id\' and missing parameter(s) \'tenant,apiKey,entityId,entityIdNS\'' }
}
})
})
Expand Down
2 changes: 2 additions & 0 deletions generators/add-action/generic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class GenericGenerator extends ActionGenerator {
// eslint-disable-next-line quotes
requiredParams: `[/* add required params */]`,
// eslint-disable-next-line quotes
requiredHeaders: `['Authorization']`,
// eslint-disable-next-line quotes
importCode: `const fetch = require('node-fetch')`,
responseCode: `// replace this with the api you want to access
const apiEndpoint = 'https://adobeioruntime.net/api/v1/api-docs'
Expand Down
2 changes: 2 additions & 0 deletions generators/add-action/target/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class TargetGenerator extends ActionGenerator {
// eslint-disable-next-line quotes
requiredParams: `['apiKey', 'tenant']`,
// eslint-disable-next-line quotes
requiredHeaders: `['Authorization']`,
// eslint-disable-next-line quotes
importCode: `const { Target } = require('@adobe/aio-sdk')`,
responseCode: `// initialize the sdk
const targetClient = await Target.init(params.tenant, params.apiKey, token)
Expand Down
5 changes: 3 additions & 2 deletions generators/add-action/templates/stub-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ async function main (params) {

// check for missing request input parameters and headers
const requiredParams = <%- requiredParams %>
const errorMessage = checkMissingRequestInputs(params, requiredParams, ['Authorization'])
const requiredHeaders = <%- requiredHeaders %>
const errorMessage = checkMissingRequestInputs(params, requiredParams, requiredHeaders)
if (errorMessage) {
// return and log client errors
return errorResponse(400, errorMessage, logger)
}

// extract the user Bearer token from the input request parameters
// extract the user Bearer token from the Authorization header
const token = getBearerToken(params)

<%- responseCode %>
Expand Down
4 changes: 4 additions & 0 deletions test/generators/add-action/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function assertActionCodeContent (actionName) {
theFile,
'const requiredParams = [\'apiKey\', \'companyId\']'
)
assert.fileContent(
theFile,
'const requiredHeaders = [\'Authorization\']'
)
assert.fileContent(
theFile,
'const analyticsClient = await Analytics.init(params.companyId, params.apiKey, token)'
Expand Down
4 changes: 4 additions & 0 deletions test/generators/add-action/campaign-standard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function assertActionCodeContent (actionName) {
theFile,
'const requiredParams = [\'apiKey\', \'tenant\']'
)
assert.fileContent(
theFile,
'const requiredHeaders = [\'Authorization\']'
)
assert.fileContent(
theFile,
'const campaignClient = await CampaignStandard.init(params.tenant, params.apiKey, token)'
Expand Down
10 changes: 6 additions & 4 deletions test/generators/add-action/customer-profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function assertManifestContent (actionName) {
inputs: {
LOG_LEVEL: 'debug',
tenant: '$CUSTOMER_PROFILE_TENANT',
orgId: '$CUSTOMER_PROFILE_ORG_ID',
apiKey: '$CUSTOMER_PROFILE_API_KEY'
},
annotations: {
Expand All @@ -73,7 +72,6 @@ function assertManifestContent (actionName) {
function assertEnvContent (prevContent) {
assert.fileContent('.env', `## please provide your Adobe Experience Platform: Realtime Customer Profile integration tenant, orgId and api key
#CUSTOMER_PROFILE_TENANT=
#CUSTOMER_PROFILE_ORG_ID=
#CUSTOMER_PROFILE_API_KEY=`)
assert.fileContent('.env', prevContent)
}
Expand All @@ -83,11 +81,15 @@ function assertActionCodeContent (actionName) {
// a few checks to make sure the action calls the sdk
assert.fileContent(
theFile,
'const requiredParams = [\'tenant\', \'orgId\', \'apiKey\', \'entityId\', \'entityIdNS\']'
'const requiredParams = [\'tenant\', \'apiKey\', \'entityId\', \'entityIdNS\']'
)
assert.fileContent(
theFile,
'const client = await CustomerProfile.init(params.tenant, params.orgId, params.apiKey, token)'
'const requiredHeaders = [\'Authorization\', \'x-gw-ims-org-id\']'
)
assert.fileContent(
theFile,
'const client = await CustomerProfile.init(params.tenant, orgId, params.apiKey, token)'
)
assert.fileContent(
theFile,
Expand Down
4 changes: 4 additions & 0 deletions test/generators/add-action/generic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function assertActionCodeContent (actionName) {
theFile,
'const res = await fetch(apiEndpoint)'
)
assert.fileContent(
theFile,
'const requiredHeaders = [\'Authorization\']'
)
}

function assertDependencies () {
Expand Down
4 changes: 4 additions & 0 deletions test/generators/add-action/target.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function assertActionCodeContent (actionName) {
theFile,
'const requiredParams = [\'apiKey\', \'tenant\']'
)
assert.fileContent(
theFile,
'const requiredHeaders = [\'Authorization\']'
)
assert.fileContent(
theFile,
'const targetClient = await Target.init(params.tenant, params.apiKey, token)'
Expand Down