Skip to content

Commit

Permalink
should display logs for secured actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
florind-ens committed Feb 21, 2022
1 parent 511a1b9 commit e7903d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/commands/app/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ const { wrapError } = require('../../lib/app-helper')
const rtLib = require('@adobe/aio-lib-runtime')
const LogForwarding = require('../../lib/log-forwarding')

const SECURED = 'require-adobe-auth'

class Logs extends BaseCommand {
_processEachAction (fullConfig, processFn) {
const isSecuredAction = (pkg, aName) => {
try {
return pkg.actions[aName].annotations[SECURED]
} catch (e) {
return false
}
}
Object.entries(fullConfig.all).forEach(([, config]) => {
Object.entries(config.manifest.full.packages).forEach(([packageName, pkg]) => {
// handle default package
packageName = packageName.replace(/__APP_PACKAGE__/g, config.ow.package)

Object.keys(pkg.actions).forEach((aName) => {
processFn(packageName, aName)
processFn(packageName, aName, isSecuredAction(pkg, aName))
})
})
})
Expand Down Expand Up @@ -80,7 +88,11 @@ class Logs extends BaseCommand {
}
})
} else {
this._processEachAction(fullConfig, (packageName, aName) => {
this._processEachAction(fullConfig, (packageName, aName, isSecured) => {
if (isSecured) {
const securedAName = '__secured_' + aName
filterActions.push(`${packageName}/${securedAName}`)
}
filterActions.push(`${packageName}/${aName}`)
})
}
Expand Down
8 changes: 4 additions & 4 deletions test/commands/app/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('run', () => {

await command.run()
const ow = owConfig()
const actionList = ['legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
const actionList = ['legacy-app-1.0.0/__secured_action', 'legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
expect(printActionLogs).toHaveBeenCalledWith({ ow }, command.log, 1, actionList, false, false)
expect(command.error).not.toHaveBeenCalled()
})
Expand All @@ -108,7 +108,7 @@ describe('run', () => {
await command.run()
expect(command.log).toHaveBeenCalledWith(expect.stringContaining('using --limit=1'))
const ow = owConfig()
const actionList = ['legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
const actionList = ['legacy-app-1.0.0/__secured_action', 'legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
expect(printActionLogs).toHaveBeenCalledWith({ ow }, command.log, 1, actionList, false, false)
expect(command.error).not.toHaveBeenCalled()
})
Expand All @@ -120,7 +120,7 @@ describe('run', () => {
await command.run()
expect(command.log).toHaveBeenCalledWith(expect.stringContaining('using --limit=50'))
const ow = owConfig()
const actionList = ['legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
const actionList = ['legacy-app-1.0.0/__secured_action', 'legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
expect(printActionLogs).toHaveBeenCalledWith({ ow }, command.log, 50, actionList, false, false)
expect(command.error).not.toHaveBeenCalled()
})
Expand All @@ -131,7 +131,7 @@ describe('run', () => {

await command.run()
const ow = owConfig()
const actionList = ['legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
const actionList = ['legacy-app-1.0.0/__secured_action', 'legacy-app-1.0.0/action', 'legacy-app-1.0.0/action-zip']
expect(printActionLogs).toHaveBeenCalledWith({ ow }, command.log, 32, actionList, false, false)
expect(command.error).not.toHaveBeenCalled()
})
Expand Down

0 comments on commit e7903d2

Please sign in to comment.