-
Notifications
You must be signed in to change notification settings - Fork 31
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 for multiple actions using the require-adobe-auth annotation in the same package #137
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const fs = require('fs') | |
const yaml = require('js-yaml') | ||
const debug = require('debug')('aio-cli-plugin-runtime/deploy') | ||
const sha1 = require('sha1') | ||
const cloneDeep = require('lodash.clonedeep') | ||
|
||
// for lines starting with date-time-string followed by stdout|stderr a ':' and a log-line, return only the logline | ||
const dtsRegex = /\d{4}-[01]{1}\d{1}-[0-3]{1}\d{1}T[0-2]{1}\d{1}:[0-6]{1}\d{1}:[0-6]{1}\d{1}.\d+Z( *(stdout|stderr):)?\s(.*)/ | ||
|
@@ -423,74 +424,61 @@ function rewriteActionsWithAdobeAuthAnnotation (packages, deploymentPackages) { | |
const REWRITE_ACTION_PREFIX = '__secured_' | ||
|
||
// avoid side effects, do not modify input packages | ||
const newPackages = { ...packages } | ||
const newDeploymentPackages = { ...deploymentPackages } | ||
const newPackages = cloneDeep(packages) | ||
const newDeploymentPackages = cloneDeep(deploymentPackages) | ||
|
||
// traverse all actions in all packages | ||
Object.keys(packages).forEach((key) => { | ||
if (packages[key]['actions']) { | ||
Object.keys(packages[key]['actions']).forEach((actionName) => { | ||
const thisAction = packages[key]['actions'][actionName] | ||
Object.keys(newPackages).forEach((key) => { | ||
if (newPackages[key]['actions']) { | ||
Object.keys(newPackages[key]['actions']).forEach((actionName) => { | ||
const thisAction = newPackages[key]['actions'][actionName] | ||
|
||
const isWeb = checkWebFlags(thisAction['web-export'])['web-export'] || checkWebFlags(thisAction['web'])['web-export'] | ||
|
||
// check if the annotation is defined AND the action is a web action | ||
if (isWeb && thisAction.annotations && thisAction.annotations[ADOBE_AUTH_ANNOTATION]) { | ||
debug(`found annotation '${ADOBE_AUTH_ANNOTATION}' in action '${key}/${actionName}'`) | ||
|
||
// 0. second level copy | ||
newPackages[key] = { ...packages[key] } | ||
newDeploymentPackages[key] = { ...deploymentPackages[key] } | ||
|
||
// 1. rename the action | ||
const renamedAction = REWRITE_ACTION_PREFIX + actionName | ||
/* istanbul ignore if */ | ||
if (packages[key]['actions'][renamedAction] !== undefined) { | ||
if (newPackages[key]['actions'][renamedAction] !== undefined) { | ||
// unlikely | ||
throw new Error(`Failed to rename the action '${key}/${actionName}' to '${key}/${renamedAction}': an action with the same name exists already.`) | ||
} | ||
|
||
// copy actions to the new package and move the action content to the new key | ||
newPackages[key]['actions'] = { | ||
...packages[key]['actions'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here was the problem as we were overriding any previous action rewrites |
||
[renamedAction]: { ...thisAction } | ||
} | ||
// set the action to the new key | ||
newPackages[key]['actions'][renamedAction] = thisAction | ||
// delete the old key | ||
delete newPackages[key]['actions'][actionName] | ||
|
||
// make sure any content in the deployment package is linked to the new action name | ||
if (deploymentPackages[key] && deploymentPackages[key]['actions'] && deploymentPackages[key]['actions'][actionName]) { | ||
newDeploymentPackages[key]['actions'] = { | ||
...deploymentPackages[key]['actions'], | ||
[renamedAction]: deploymentPackages[key]['actions'][actionName] | ||
} | ||
if (newDeploymentPackages[key] && newDeploymentPackages[key]['actions'] && newDeploymentPackages[key]['actions'][actionName]) { | ||
newDeploymentPackages[key]['actions'][renamedAction] = newDeploymentPackages[key]['actions'][actionName] | ||
delete newDeploymentPackages[key]['actions'][actionName] | ||
} | ||
|
||
// 2. delete the adobe-auth annotation and secure the renamed action | ||
newPackages[key]['actions'][renamedAction]['annotations'] = { | ||
...packages[key]['actions'][actionName]['annotations'], | ||
'require-whisk-auth': true | ||
} | ||
newPackages[key]['actions'][renamedAction]['annotations']['require-whisk-auth'] = true | ||
delete newPackages[key]['actions'][renamedAction]['annotations'][ADOBE_AUTH_ANNOTATION] | ||
|
||
debug(`renamed action '${key}/${actionName}' to '${key}/${renamedAction}'`) | ||
|
||
// 3. create the sequence | ||
if (packages[key]['sequences'] === undefined) { | ||
if (newPackages[key]['sequences'] === undefined) { | ||
newPackages[key]['sequences'] = {} | ||
} /* istanbul ignore next */ else if (packages[key]['sequences'][actionName] !== undefined) { | ||
} | ||
/* istanbul ignore if */ | ||
if (newPackages[key]['sequences'][actionName] !== undefined) { | ||
// unlikely | ||
throw new Error(`The name '${key}/${actionName}' is defined both for an action and a sequence, it should be unique`) | ||
} | ||
// set the sequence content | ||
newPackages[key]['sequences'] = { | ||
...packages[key]['sequences'], | ||
[actionName]: { | ||
actions: `${ADOBE_AUTH_ACTION},${key}/${renamedAction}`, | ||
web: 'yes' | ||
} | ||
newPackages[key]['sequences'][actionName] = { | ||
actions: `${ADOBE_AUTH_ACTION},${key}/${renamedAction}`, | ||
web: 'yes' | ||
} | ||
|
||
debug(`defined new sequence '${key}/${actionName}': '${ADOBE_AUTH_ACTION},${key}/${renamedAction}'`) | ||
} | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going with clone deep adds a (small) dependency but makes the implementation clearer and less error prone