Audit Module API Reference¶
This section documents the internals of the audit
module in Bijux CLI.
bijux_cli.services.audit ¶
Provides concrete audit service implementations.
This module defines concrete classes that implement the AuditProtocol
. It offers different strategies for handling command auditing and execution, allowing the application to switch between a simulation mode (DryRunAudit
) and a real execution mode (RealAudit
).
A factory function, get_audit_service
, is provided to select the appropriate implementation based on a dry_run
flag.
DryRunAudit ¶
DryRunAudit(
log: ObservabilityProtocol, tel: TelemetryProtocol
)
Bases: _BaseAudit
An audit service that records events and simulates command execution.
Initializes the DryRunAudit
service.
Parameters:
-
log
(ObservabilityProtocol
) –The service for structured logging.
-
tel
(TelemetryProtocol
) –The service for event tracking.
Source code in src/bijux_cli/services/audit.py
cli_audit ¶
log ¶
Logs and records a command without executing it.
Parameters:
-
cmd
(list[str]
) –The command and arguments to log.
-
executor
(str
) –The name of the entity executing the command.
Returns:
-
None
(None
) –
Source code in src/bijux_cli/services/audit.py
run ¶
Simulates the execution of a command.
This method logs the command and returns a successful result without actually running a subprocess.
Parameters:
-
cmd
(list[str]
) –The command to simulate.
-
executor
(str
) –The name of the entity executing the command.
Returns:
-
tuple[int, bytes, bytes]
–tuple[int, bytes, bytes]: A tuple of dummy values:
(0, b"", b"")
.
Source code in src/bijux_cli/services/audit.py
RealAudit ¶
RealAudit(
log: ObservabilityProtocol, tel: TelemetryProtocol
)
Bases: _BaseAudit
An audit service that validates, logs, and executes real commands.
Initializes the RealAudit
service.
Parameters:
-
log
(ObservabilityProtocol
) –The service for structured logging.
-
tel
(TelemetryProtocol
) –The service for event tracking.
Source code in src/bijux_cli/services/audit.py
cli_audit ¶
Logs a real CLI audit event.
log ¶
Logs a command with the intent to execute it.
Parameters:
-
cmd
(list[str]
) –The command and arguments to log.
-
executor
(str
) –The name of the entity executing the command.
Returns:
-
None
(None
) –
Source code in src/bijux_cli/services/audit.py
run ¶
Validates, logs, and executes a command in a subprocess.
Parameters:
-
cmd
(list[str]
) –The command and arguments to execute.
-
executor
(str
) –The name of the entity executing the command.
Returns:
-
tuple[int, bytes, bytes]
–tuple[int, bytes, bytes]: A tuple containing the command's return code, standard output, and standard error.
Raises:
-
BijuxError
–If command validation fails or an unexpected error occurs during execution.
Source code in src/bijux_cli/services/audit.py
get_audit_service ¶
get_audit_service(
observability: ObservabilityProtocol,
telemetry: TelemetryProtocol,
dry_run: bool = False,
) -> AuditProtocol
A factory function for creating an audit service instance.
Parameters:
-
observability
(ObservabilityProtocol
) –The service for logging.
-
telemetry
(TelemetryProtocol
) –The service for event tracking.
-
dry_run
(bool
, default:False
) –If True, returns a
DryRunAudit
instance; otherwise, returns aRealAudit
instance.
Returns:
-
AuditProtocol
(AuditProtocol
) –An instance of the appropriate audit service.