Skip to content

Commit b1b27b4

Browse files
committed
feat: support include-ims-credentials annotation
1 parent ca5de28 commit b1b27b4

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/lib/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ module.exports = {
4040
STAGE_LAUNCH_PREFIX: 'https://experience-stage.adobe.com/?devMode=true#/custom-apps/?localDevUrl=',
4141
PRIVATE_KEY_PATH: `${DEV_KEYS_DIR}/private.key`,
4242
PUB_CERT_PATH: `${DEV_KEYS_DIR}/cert-pub.crt`,
43-
BUNDLE_OPTIONS
43+
BUNDLE_OPTIONS,
44+
IMS_OAUTH_S2S_ENV_KEY: 'IMS_OAUTH_S2S'
4445
}

src/lib/run-dev.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ const coreLogger = require('@adobe/aio-lib-core-logging')
2525
const { getReasonPhrase } = require('http-status-codes')
2626

2727
const utils = require('./app-helper')
28-
const { SERVER_HOST, SERVER_DEFAULT_PORT, BUNDLER_DEFAULT_PORT, DEV_API_PREFIX, DEV_API_WEB_PREFIX, BUNDLE_OPTIONS, CHANGED_ASSETS_PRINT_LIMIT } = require('./constants')
28+
const { SERVER_HOST, SERVER_DEFAULT_PORT, BUNDLER_DEFAULT_PORT, DEV_API_PREFIX, DEV_API_WEB_PREFIX, BUNDLE_OPTIONS, CHANGED_ASSETS_PRINT_LIMIT, IMS_OAUTH_S2S_ENV_KEY } = require('./constants')
2929
const RAW_CONTENT_TYPES = ['application/octet-stream', 'multipart/form-data']
3030

31+
// for the include-ims-credentials annotation
32+
let imsAuthObject = null
33+
3134
/* global Request, Response */
3235

3336
/**
@@ -86,6 +89,11 @@ async function runDev (runOptions, config, _inprocHookRunner) {
8689
// ex. console.log('AIO_DEV ', process.env.AIO_DEV ? 'dev' : 'prod')
8790
process.env.AIO_DEV = 'true'
8891

92+
// for the include-ims-credentials annotation
93+
try {
94+
imsAuthObject = JSON.parse(process.env[IMS_OAUTH_S2S_ENV_KEY])
95+
} catch (e) {}
96+
8997
const serverPortToUse = parseInt(process.env.PORT) || SERVER_DEFAULT_PORT
9098
const serverPort = await getPort({ port: serverPortToUse })
9199

@@ -346,6 +354,13 @@ async function invokeAction ({ actionRequestContext, logger }) {
346354
}
347355
}
348356

357+
// process the include-ims-credentials annotation
358+
const newInputs = rtLib.utils.getIncludeIMSCredentialsAnnotationInputs(action, imsAuthObject)
359+
if (newInputs) {
360+
Object.entries(newInputs).forEach(([k, v]) => { params[k] = v })
361+
logger.debug(`Added IMS credentials to action params for action '${actionName}'.`)
362+
}
363+
349364
// if we run an action, we will restore the process.env after the call
350365
// we must do this before we load the action because code can execute on require/import
351366
const preCallEnv = { ...process.env }

0 commit comments

Comments
 (0)