package Ġorg . p mi ops . workbench . action audit Ċ Ċ import Ġcom . google . cloud . Mon itored Resource Ċ import Ġcom . google . cloud . logging . LogEntry Ċ import Ġcom . google . cloud . logging . Logging Ċ import Ġcom . google . cloud . logging . Payload . Json Payload Ċ import Ġcom . google . cloud . logging . Severity Ċ import Ġjava . util . HashMap Ċ import Ġjava . util . logging . Level Ċ import Ġjava . util . logging . Logger Ċ import Ġjavax . inject . Provider Ċ import Ġorg . p mi ops . workbench . config . Workbench Config Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . stereotype . Service Ċ Ċ @ Service Ċ class ĠAction Audit ServiceImpl Ġ@ Autowired Ċ constructor ( private Ġval Ġconfig Provider : ĠProvider < Workbench Config >, Ġprivate Ġval Ġcloud Logging : ĠLogging ) Ġ: ĠAction Audit Service Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġsend ( events : ĠCollection < Action Audit Event >) Ġ{ ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġlog Entries : ĠList < LogEntry > Ġ= Ġevents ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġthis . audit Event To LogEntry ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( log Entries . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcloud Logging . write ( log Entries ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠRuntimeException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservice Logger . log ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLevel . SEVERE , Ġe ) Ġ{ Ġ" Exception Ġencountered Ġwriting Ġlog Ġentries Ġto ĠCloud ĠLogging ." Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġaudit Event To LogEntry ( audit Event : ĠAction Audit Event ): ĠLog Entry Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaction Audit Config Ġ= Ġconfig Provider . get (). action Audit ĊĠĠĠĠĠĠĠ Ġreturn ĠLog Entry . newBuilder ( toJson Payload ( audit Event )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Severity ( Severity . INFO ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Log Name ( action Audit Config . log Name ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Resource ( mon itored Resource ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠtoJson Payload ( audit Event : ĠAction Audit Event ): ĠJson Payload Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġallow Ġnull Ġvalues Ġso Ġthat ĠJSON Ġcolumns Ġare Ġpopulated Ġand ĠB Q Ġschema ĊĠĠĠĠĠĠĠ Ġ// Ġdoesn 't Ġhave Ġg aps Ġthat Ġneed Ġto Ġbe Ġadded Ġlater Ġvia Ġdaily Ġmigration ĊĠĠĠĠĠĠĠ Ġval Ġjson Values By Column Ġ= ĠHashMap < String , ĠAny ?> () ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . TIMESTAMP . name ] Ġ= Ġaudit Event . timestamp ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . ACTION _ ID . name ] Ġ= Ġaudit Event . action Id ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . ACTION _ TYPE . name ] Ġ= Ġaudit Event . action Type ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . AGENT _ TYPE . name ] Ġ= Ġaudit Event . agent Type ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . AGENT _ ID . name ] Ġ= Ġaudit Event . agent Id Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . AGENT _ EMAIL . name ] Ġ= Ġaudit Event . agent Email Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . TARGET _ TYPE . name ] Ġ= Ġaudit Event . target Type ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . TARGET _ ID . name ] Ġ= Ġaudit Event . target Id Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . AGENT _ ID . name ] Ġ= Ġaudit Event . agent Id Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . TARGET _ PROPERTY . name ] Ġ= Ġaudit Event . target Property Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . PREV _ VALUE . name ] Ġ= Ġaudit Event . previous Value Maybe ĊĠĠĠĠĠĠĠ Ġjson Values By Column [ Audit Column . NEW _ VALUE . name ] Ġ= Ġaudit Event . newValue Maybe ĊĠĠĠĠĠĠĠ Ġreturn ĠJson Payload . of ( json Values By Column ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġlog RuntimeException ( logger : ĠLogger , Ġexception : ĠRuntimeException ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . log ( Level . WARNING , Ġ" Exception Ġencountered Ġduring Ġaudit .", Ġexception ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġservice Logger Ġ= ĠLogger . getLogger ( Action Audit ServiceImpl :: class . java . name ) ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠMON IT O RED _ RESOURCE _ TYPE Ġ= Ġ" global " ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġmon itored Resource : ĠMon itored Resource Ġ= ĠMon itored Resource . newBuilder ( MON IT O RED _ RESOURCE _ TYPE ). build () ĊĠĠĠ Ġ} Ċ } Ċ