@@ -18,10 +18,10 @@ const BaseCommand = require('../../BaseCommand')
1818const BuildCommand = require ( './build' )
1919const webLib = require ( '@adobe/aio-lib-web' )
2020const { Flags } = require ( '@oclif/core' )
21- const { runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata, getCliInfo } = require ( '../../lib/app-helper' )
21+ const { runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata, getCliInfo, getFilesCountWithExtension } = require ( '../../lib/app-helper' )
2222const rtLib = require ( '@adobe/aio-lib-runtime' )
2323const LogForwarding = require ( '../../lib/log-forwarding' )
24- const { sendAuditLogs , getAuditLogEvent , getFilesCountWithExtension } = require ( '../../lib/audit-logger' )
24+ const { sendAppAssetsDeployedAuditLog , sendAppDeployAuditLog } = require ( '../../lib/audit-logger' )
2525const { setRuntimeApiHostAndAuthHandler } = require ( '../../lib/auth-helper' )
2626const logActions = require ( '../../lib/log-actions' )
2727
@@ -53,15 +53,43 @@ class Deploy extends BuildCommand {
5353 const spinner = ora ( )
5454
5555 try {
56- const aioConfig = ( await this . getFullConfig ( ) ) . aio
56+ const { aio : aioConfig , packagejson : packageJson } = await this . getFullConfig ( )
5757 const cliDetails = await getCliInfo ( flags . publish )
58+ const appInfo = {
59+ name : packageJson . name ,
60+ version : packageJson . version ,
61+ project : aioConfig ?. project ,
62+ runtimeNamespace : aioConfig ?. runtime ?. namespace
63+ }
64+
65+ if ( cliDetails ?. accessToken ) {
66+ try {
67+ // send audit log at start (don't wait for deployment to finish)
68+ await sendAppDeployAuditLog ( {
69+ accessToken : cliDetails ?. accessToken ,
70+ cliCommandFlags : flags ,
71+ appInfo,
72+ env : cliDetails . env
73+ } )
74+ } catch ( error ) {
75+ if ( flags . verbose ) {
76+ this . warn ( 'Error: Audit Log Service Error: Failed to send audit log event for deployment.' )
77+ this . warn ( error . message )
78+ }
79+ }
80+ }
5881
5982 // 1. update log forwarding configuration
6083 // note: it is possible that .aio file does not exist, which means there is no local lg config
6184 if ( aioConfig ?. project ?. workspace && flags [ 'log-forwarding-update' ] && flags . actions ) {
6285 spinner . start ( 'Updating log forwarding configuration' )
6386 try {
64- const lf = await LogForwarding . init ( aioConfig )
87+ let lfConfig = aioConfig
88+ if ( process . env . IS_DEPLOY_SERVICE_ENABLED === 'true' ) {
89+ lfConfig = setRuntimeApiHostAndAuthHandler ( aioConfig )
90+ }
91+
92+ const lf = await LogForwarding . init ( lfConfig )
6593 if ( lf . isLocalConfigChanged ( ) ) {
6694 const lfConfig = lf . getLocalConfigWithSecrets ( )
6795 if ( lfConfig . isDefined ( ) ) {
@@ -101,22 +129,24 @@ class Deploy extends BuildCommand {
101129 // - break into smaller pieces deploy, allowing to first deploy all actions then all web assets
102130 for ( let i = 0 ; i < keys . length ; ++ i ) {
103131 const k = keys [ i ]
104- const v = setRuntimeApiHostAndAuthHandler ( values [ i ] )
132+ const v = process . env . IS_DEPLOY_SERVICE_ENABLED === 'true' ? setRuntimeApiHostAndAuthHandler ( values [ i ] ) : values [ i ]
105133
106134 await this . deploySingleConfig ( k , v , flags , spinner )
107- if ( v . app . hasFrontend && flags [ 'web-assets' ] ) {
135+ if ( cliDetails ?. accessToken && v . app . hasFrontend && flags [ 'web-assets' ] ) {
108136 const opItems = getFilesCountWithExtension ( v . web . distProd )
109- const assetDeployedLogEvent = getAuditLogEvent ( flags , aioConfig . project , 'AB_APP_ASSETS_DEPLOYED' )
110- if ( assetDeployedLogEvent && cliDetails ?. accessToken ) {
111- assetDeployedLogEvent . data . opItems = opItems
112- try {
113- // only send logs in case of web-assets deployment
114- await sendAuditLogs ( cliDetails . accessToken , assetDeployedLogEvent , cliDetails . env )
115- } catch ( error ) {
116- if ( flags . verbose ) {
117- this . warn ( 'Error: Audit Log Service Error: Failed to send audit log event for deployment.' )
118- this . warn ( error . message )
119- }
137+ try {
138+ // only send logs in case of web-assets deployment
139+ await sendAppAssetsDeployedAuditLog ( {
140+ accessToken : cliDetails ?. accessToken ,
141+ cliCommandFlags : flags ,
142+ opItems,
143+ appInfo,
144+ env : cliDetails . env
145+ } )
146+ } catch ( error ) {
147+ if ( flags . verbose ) {
148+ this . warn ( 'Error: Audit Log Service Error: Failed to send audit log event for deployment.' )
149+ this . warn ( error . message )
120150 }
121151 }
122152 }
0 commit comments