@@ -18,19 +18,22 @@ func NewReconcileHandler(adapter reconciliation.Adapter, store reconciliation.St
1818 return func (c * gin.Context ) {
1919 callerID , exists := c .Get ("callerID" )
2020 if ! exists {
21+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "denied" , map [string ]string {"reason" : "missing_auth" })
2122 RespondWithAuthError (c , "Missing authentication credentials" )
2223 return
2324 }
2425
2526 tenantID , exists := c .Get ("tenantID" )
2627 if ! exists {
28+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "denied" , map [string ]string {"reason" : "missing_tenant" })
2729 RespondWithAuthError (c , "Missing tenant context" )
2830 return
2931 }
3032 tid := tenantID .(string )
3133
3234 roles := auth .ExtractRoles (c )
3335 if ! hasAnyPermission (roles , auth .PermManageReconciliation ) {
36+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "denied" , map [string ]string {"reason" : "insufficient_permissions" })
3437 RespondWithError (c , http .StatusForbidden , ErrorCodeForbidden , "Insufficient permissions for reconciliation" )
3538 return
3639 }
@@ -40,6 +43,7 @@ func NewReconcileHandler(adapter reconciliation.Adapter, store reconciliation.St
4043
4144 var backendSubs []reconciliation.BackendSubscription
4245 if err := c .ShouldBindJSON (& backendSubs ); err != nil {
46+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "denied" , map [string ]string {"reason" : "invalid_request" })
4347 RespondWithValidationError (c , "Invalid request body" , map [string ]interface {}{
4448 "reason" : err .Error (),
4549 })
@@ -50,6 +54,7 @@ func NewReconcileHandler(adapter reconciliation.Adapter, store reconciliation.St
5054 if ! isAdmin {
5155 for _ , b := range backendSubs {
5256 if b .TenantID != "" && b .TenantID != tid {
57+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "denied" , map [string ]string {"reason" : "cross_tenant" })
5358 RespondWithError (c , http .StatusForbidden , ErrorCodeForbidden ,
5459 "Cannot reconcile subscriptions belonging to another tenant" )
5560 return
@@ -97,6 +102,12 @@ func NewReconcileHandler(adapter reconciliation.Adapter, store reconciliation.St
97102 }
98103 }
99104
105+ audit .LogAction (c , "reconciliation.execute" , "reconciliation" , "success" , map [string ]string {
106+ "total" : strconv .Itoa (len (reports )),
107+ "matched" : strconv .Itoa (matched ),
108+ "mismatched" : strconv .Itoa (len (reports ) - matched ),
109+ })
110+
100111 c .JSON (http .StatusOK , gin.H {
101112 "summary" : gin.H {"total" : len (reports ), "matched" : matched , "mismatched" : len (reports ) - matched },
102113 "reports" : reports ,
0 commit comments