Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions backend/app/audit_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger = logging.getLogger(__name__)


async def log_audit_event(
def log_audit_event(
db: Session,
action: str,
resource_type: str,
Expand Down Expand Up @@ -68,7 +68,7 @@ async def log_audit_event(
return False


async def log_login_event(
def log_login_event(
db: Session,
username: str,
user_id: Optional[int],
Expand All @@ -83,7 +83,7 @@ async def log_login_event(
if failure_reason and not success:
details += f" - Reason: {failure_reason}"

return await log_audit_event(
return log_audit_event(
db=db,
action=action,
resource_type="auth",
Expand All @@ -94,7 +94,7 @@ async def log_login_event(
)


async def log_scan_event(
def log_scan_event(
db: Session,
action: str,
scan_id: Optional[str],
Expand All @@ -108,7 +108,7 @@ async def log_scan_event(
if host_name:
scan_details += f" on host {host_name}"

return await log_audit_event(
return log_audit_event(
db=db,
action=f"SCAN_{action.upper()}",
resource_type="scan",
Expand All @@ -119,7 +119,7 @@ async def log_scan_event(
)


async def log_host_event(
def log_host_event(
db: Session,
action: str,
host_id: Optional[str],
Expand All @@ -131,7 +131,7 @@ async def log_host_event(
"""Log host-related events to database"""
host_details = details or f"{action.title()} host: {host_name}"

return await log_audit_event(
return log_audit_event(
db=db,
action=f"HOST_{action.upper()}",
resource_type="host",
Expand All @@ -142,7 +142,7 @@ async def log_host_event(
)


async def log_user_event(
def log_user_event(
db: Session,
action: str,
target_user_id: Optional[str],
Expand All @@ -154,7 +154,7 @@ async def log_user_event(
"""Log user management events to database"""
user_details = details or f"{action.title()} user: {target_username}"

return await log_audit_event(
return log_audit_event(
db=db,
action=f"USER_{action.upper()}",
resource_type="user",
Expand All @@ -165,15 +165,15 @@ async def log_user_event(
)


async def log_security_event(
def log_security_event(
db: Session,
event_type: str,
ip_address: str,
user_id: Optional[int] = None,
details: Optional[str] = None
) -> bool:
"""Log security-related events to database"""
return await log_audit_event(
return log_audit_event(
db=db,
action=f"SECURITY_{event_type.upper()}",
resource_type="security",
Expand All @@ -183,7 +183,7 @@ async def log_security_event(
)


async def log_admin_event(
def log_admin_event(
db: Session,
action: str,
user_id: int,
Expand All @@ -192,7 +192,7 @@ async def log_admin_event(
details: Optional[str] = None
) -> bool:
"""Log administrative actions to database"""
return await log_audit_event(
return log_audit_event(
db=db,
action=f"ADMIN_{action.upper()}",
resource_type=resource_type,
Expand Down
6 changes: 3 additions & 3 deletions backend/app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def log_security_event(self, event_type: str, details: str, ip_address: str):
f"SECURITY_{event_type} - Details: {details}, IP: {ip_address}"
)

async def log_api_key_action(self, user_id: str, action: str, api_key_id: str,
def log_api_key_action(self, user_id: str, action: str, api_key_id: str,
api_key_name: str, details: Optional[Dict] = None):
"""Log API key related actions"""
self.audit_logger.info(
Expand All @@ -286,7 +286,7 @@ async def log_api_key_action(self, user_id: str, action: str, api_key_id: str,
audit_logger = SecurityAuditLogger()


async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security)) -> Dict[str, Any]:
def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security)) -> Dict[str, Any]:
"""Get current authenticated user from JWT token or API key"""
from sqlalchemy.orm import Session
from .database import get_db, ApiKey
Expand Down Expand Up @@ -405,7 +405,7 @@ def decode_token(token: str) -> Optional[Dict[str, Any]]:
return None


async def require_admin(current_user: Dict[str, Any] = Depends(get_current_user)) -> Dict[str, Any]:
def require_admin(current_user: Dict[str, Any] = Depends(get_current_user)) -> Dict[str, Any]:
"""Require admin role for protected endpoints"""
if current_user.get("role") != UserRole.SUPER_ADMIN.value:
raise HTTPException(
Expand Down
2 changes: 1 addition & 1 deletion backend/app/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def revoke_task(self, task_id: str, terminate: bool = True) -> bool:
celery_manager = SecureCeleryManager()


async def check_redis_health() -> bool:
def check_redis_health() -> bool:
"""Check Redis connectivity for health checks"""
try:
# Parse Redis URL
Expand Down
4 changes: 2 additions & 2 deletions backend/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def get_db() -> Session:
db.close()


async def create_tables():
def create_tables():
"""Create database tables if they don't exist"""
try:
Base.metadata.create_all(bind=engine)
Expand All @@ -407,7 +407,7 @@ async def create_tables():
raise


async def check_database_health() -> bool:
def check_database_health() -> bool:
"""Check database connectivity for health checks"""
try:
from sqlalchemy import text
Expand Down
8 changes: 4 additions & 4 deletions backend/app/middleware/authorization_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _match_pattern(self, request_path: str, pattern: str) -> bool:

return True

async def _extract_current_user(self, request: Request) -> Optional[Dict[str, Any]]:
def _extract_current_user(self, request: Request) -> Optional[Dict[str, Any]]:
"""
Extract current user from request authentication
"""
Expand Down Expand Up @@ -353,7 +353,7 @@ async def _extract_host_id_from_body(self, request: Request) -> Optional[str]:

return None

async def _get_host_id_from_scan_id(self, scan_id: str) -> Optional[str]:
def _get_host_id_from_scan_id(self, scan_id: str) -> Optional[str]:
"""
Get host_id associated with a scan_id
"""
Expand All @@ -373,7 +373,7 @@ async def _get_host_id_from_scan_id(self, scan_id: str) -> Optional[str]:
logger.error(f"Error getting host_id from scan_id {scan_id}: {e}")
return None

async def _get_host_ids_from_group_id(self, group_id: str) -> List[str]:
def _get_host_ids_from_group_id(self, group_id: str) -> List[str]:
"""
Get all host_ids in a host group
"""
Expand Down Expand Up @@ -424,7 +424,7 @@ async def _extract_bulk_host_ids(

return []

async def _build_authorization_context(
def _build_authorization_context(
self,
request: Request,
current_user: Dict[str, Any]
Expand Down
4 changes: 2 additions & 2 deletions backend/app/middleware/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _normalize_endpoint(self, path: str) -> str:

return normalized_path

async def _record_application_metrics(self, request: Request, response: Response, duration: float):
def _record_application_metrics(self, request: Request, response: Response, duration: float):
"""Record application-specific metrics based on request/response"""
path = request.url.path

Expand Down Expand Up @@ -161,7 +161,7 @@ class DatabaseMetricsCollector:
def __init__(self):
self.metrics = get_metrics_instance()

async def record_query_metrics(self, operation: str, duration: float):
def record_query_metrics(self, operation: str, duration: float):
"""Record database query metrics"""
from ..services.prometheus_metrics import database_query_duration_seconds
database_query_duration_seconds.labels(operation=operation).observe(duration)
Expand Down
16 changes: 8 additions & 8 deletions backend/app/plugins/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def cleanup(self) -> bool:
"""Cleanup plugin resources. Return True if successful."""
pass

async def health_check(self) -> Dict:
def health_check(self) -> Dict:
"""Perform plugin health check"""
return {
"status": "healthy" if self.enabled else "disabled",
Expand Down Expand Up @@ -142,7 +142,7 @@ async def validate_content(self, content_path: str) -> bool:
"""Validate SCAP content compatibility with this scanner"""
pass

async def get_supported_profiles(self, content_path: str) -> List[Dict]:
def get_supported_profiles(self, content_path: str) -> List[Dict]:
"""Get profiles supported by this scanner"""
return []

Expand All @@ -161,7 +161,7 @@ def get_supported_formats(self) -> List[str]:
"""Get list of supported report formats"""
pass

async def get_report_template(self, format_type: str) -> Optional[str]:
def get_report_template(self, format_type: str) -> Optional[str]:
"""Get report template for the specified format"""
return None

Expand All @@ -186,7 +186,7 @@ async def get_remediation_plan(self, failed_rules: List[str],
"""Get remediation plan for multiple failed rules"""
pass

async def validate_remediation(self, rule_id: str, host_config: Dict) -> Dict:
def validate_remediation(self, rule_id: str, host_config: Dict) -> Dict:
"""Validate that remediation was successful"""
return {"status": "unknown", "validated": False}

Expand All @@ -205,7 +205,7 @@ async def import_content(self, source_config: Dict) -> Optional[str]:
"""Import SCAP content from external source"""
pass

async def sync_hosts(self, source_config: Dict) -> List[Dict]:
def sync_hosts(self, source_config: Dict) -> List[Dict]:
"""Synchronize host inventory from external system"""
return []

Expand All @@ -228,7 +228,7 @@ async def validate_content_integrity(self, content_path: str) -> bool:
"""Validate content integrity and authenticity"""
pass

async def get_content_metadata(self, content_id: str) -> Dict:
def get_content_metadata(self, content_id: str) -> Dict:
"""Get metadata for specific content"""
return {}

Expand All @@ -247,7 +247,7 @@ async def authorize_action(self, user_info: Dict, action: str,
"""Check if user is authorized for specific action on resource"""
pass

async def get_user_groups(self, user_info: Dict) -> List[str]:
def get_user_groups(self, user_info: Dict) -> List[str]:
"""Get list of groups for authenticated user"""
return []

Expand All @@ -266,7 +266,7 @@ def get_supported_types(self) -> List[str]:
"""Get supported notification types"""
pass

async def validate_recipients(self, recipients: List[str]) -> List[str]:
def validate_recipients(self, recipients: List[str]) -> List[str]:
"""Validate and return valid recipients"""
return recipients

Expand Down
10 changes: 5 additions & 5 deletions backend/app/plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def list_plugins(self) -> Dict[str, Dict]:
}
return plugin_list

async def enable_plugin(self, plugin_name: str) -> bool:
def enable_plugin(self, plugin_name: str) -> bool:
"""Enable a plugin"""
plugin = self.get_plugin(plugin_name)
if plugin:
Expand All @@ -193,7 +193,7 @@ async def enable_plugin(self, plugin_name: str) -> bool:
return True
return False

async def disable_plugin(self, plugin_name: str) -> bool:
def disable_plugin(self, plugin_name: str) -> bool:
"""Disable a plugin"""
plugin = self.get_plugin(plugin_name)
if plugin:
Expand Down Expand Up @@ -316,7 +316,7 @@ async def _discover_plugins(self):
if plugin_file.exists():
await self.load_plugin(str(plugin_file), plugin_dir.name)

async def _load_plugin_configs(self):
def _load_plugin_configs(self):
"""Load plugin configurations from config directory"""
for config_file in self.config_dir.glob("*.json"):
try:
Expand All @@ -338,7 +338,7 @@ def _find_plugin_class(self, module) -> Optional[Type[PluginInterface]]:
return attr
return None

async def _validate_plugin(self, plugin: PluginInterface) -> bool:
def _validate_plugin(self, plugin: PluginInterface) -> bool:
"""Validate a plugin meets requirements"""
try:
metadata = plugin.get_metadata()
Expand Down Expand Up @@ -378,7 +378,7 @@ async def _register_plugin_hooks(self):
if isinstance(plugin, HookablePlugin):
await self._register_plugin_hooks_for(plugin)

async def _register_plugin_hooks_for(self, plugin: HookablePlugin):
def _register_plugin_hooks_for(self, plugin: HookablePlugin):
"""Register hooks for a specific plugin"""
for hook_name in plugin.get_registered_hooks():
if hook_name not in self.hook_registry:
Expand Down
2 changes: 1 addition & 1 deletion backend/app/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def check_permission(user_role: str, resource_type: str, action: str):
)


async def check_permission_async(current_user: dict, required_permission: Permission, db: Any = None):
def check_permission_async(current_user: dict, required_permission: Permission, db: Any = None):
"""Async permission check for specific permissions"""
if not current_user:
raise HTTPException(
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routes/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async def create_audit_log(
raise HTTPException(status_code=500, detail="Failed to create audit log")

# Helper function to create audit logs from middleware
async def log_audit_event(
def log_audit_event(
db: Session,
user_id: Optional[int],
action: str,
Expand Down
Loading
Loading