/* * dbMango * * Copyright 2025 Deutsche Bank AG * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using MongoDB.Bson; namespace Rms.Risk.Mango.Interfaces; /// /// Represents an audit record containing details about a database operation. /// /// The name of the database where the operation occurred. /// The timestamp of when the operation was performed. /// The email of the user who performed the operation. /// The ticket identifier associated with the operation. /// Indicates whether the operation was successful. /// The MongoDB command executed during the operation. /// Optional error message if the operation failed. public record AuditRecord( string DatabaseName, DateTime Timestamp, string Email, string Ticket, bool Success, BsonDocument Command, string? Error = null); /// /// Defines methods for auditing database operations. /// public interface IAuditService { /// /// Performs a pre-check on the provided MongoDB command. /// /// The MongoDB command to validate before execution. void PreCheck(BsonDocument command); /// /// Records an audit entry for a database operation. /// /// The audit record containing details of the operation. /// A cancellation token to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. Task Record(AuditRecord rec, CancellationToken token = default); /// /// Retrieves a list of audit records within a specified date range. /// /// The start date of the range to retrieve audit records. /// The end date of the range to retrieve audit records. /// A cancellation token to observe while waiting for the task to complete. /// A task that represents the asynchronous operation, containing a list of audit records. Task> Audit(DateTime startDate, DateTime endDate, CancellationToken token = default); }