Skip to content
Open
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: 21 additions & 5 deletions backend/secuscan/scanners/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Any, List, Optional
from datetime import datetime
import logging
import asyncio

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -34,17 +35,32 @@ async def _execute_command(self, command: List[str]) -> tuple:
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT
)
try:
stdout, _ = await process.communicate()
return stdout.decode('utf-8', errors='replace'), process.returncode
except asyncio.CancelledError:
try:
stdout, _ = await process.communicate()

logger.info(
"Command completed | scanner=%s | task_id=%s | return_code=%s",
self.name,
self.task_id,
process.returncode,
)

return stdout.decode('utf-8', errors='replace'), process.returncode

except asyncio.CancelledError:
logger.warning(
"Command cancelled | scanner=%s | task_id=%s",
self.name,
self.task_id,
)

try:
process.kill()
await process.wait()
except Exception:
pass
raise

@property
@abstractmethod
def name(self) -> str:
Expand Down
Loading