Skip to content

Commit

Permalink
chore: replace reorder-python-imports by isort
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy authored and jdobes committed Sep 25, 2024
1 parent e97ad01 commit c285066
Show file tree
Hide file tree
Showing 89 changed files with 343 additions and 253 deletions.
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ repos:
hooks:
- id: flake8
files: "common|database|grouper|listener|evaluator|notificator|manager|vmaas_sync|taskomatic|scripts|exploit_sync|common|cluster|tests"
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.13.0
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: reorder-python-imports
- id: isort
name: isort
args: [--force-single-line, --profile=black]
1 change: 1 addition & 0 deletions cluster/cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Cluster job
"""

import os
import subprocess
from typing import List
Expand Down
1 change: 1 addition & 0 deletions common/bounded_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
ThreadPoolExecutor wrapper to limit number of submited items.
"""

from concurrent.futures import ThreadPoolExecutor
from threading import BoundedSemaphore

Expand Down
1 change: 1 addition & 0 deletions common/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Use Clowder config or env vars config.
"""

import os
import tempfile

Expand Down
2 changes: 1 addition & 1 deletion common/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Common constants declaration module.
"""

from enum import Enum
from enum import StrEnum

from common.config import Config


CFG = Config()

APP_VERSION = "2.40.8"
Expand Down
1 change: 1 addition & 0 deletions common/database_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module containing database handler class.
"""

import asyncio
import os
import ssl
Expand Down
4 changes: 3 additions & 1 deletion common/feature_flags.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
Common feature flags with Unleash to be used for multiple apps
"""

from os import path
from pathlib import Path
from uuid import uuid4

from UnleashClient import UnleashClient
from UnleashClient.cache import FileCache

from .config import Config
from common.logging import get_logger

from .config import Config

CFG = Config()
APP_NAME = "vulnerability-engine"
LOGGER = get_logger(__name__)
Expand Down
1 change: 1 addition & 0 deletions common/identity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
3scale authentication functions.
"""

import base64
import json

Expand Down
1 change: 1 addition & 0 deletions common/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Common logging functionality to be used for multiple apps
"""

import json
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions common/mqueue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module with classes for work with Kafka Message queue."""

import asyncio
import hashlib
import json
Expand Down
1 change: 1 addition & 0 deletions common/peewee_conditions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module defines common conditions for queries in manager or other parts.
"""

# pylint: disable=singleton-comparison,superfluous-parens
from peewee import Expression
from peewee import fn
Expand Down
1 change: 1 addition & 0 deletions common/peewee_database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Postgresql settings for peewee mappings.
"""

from playhouse.postgres_ext import PostgresqlExtDatabase

from common.config import Config
Expand Down
4 changes: 3 additions & 1 deletion common/peewee_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Database to peewee mappings
"""

# pylint: disable=invalid-name
from datetime import datetime
from enum import Enum
Expand All @@ -17,9 +18,10 @@
from peewee import UUIDField
from playhouse.postgres_ext import BinaryJSONField

from common.config import Config

from .peewee_database import DB
from .peewee_database import DB_READ_REPLICA
from common.config import Config

CFG = Config()

Expand Down
1 change: 1 addition & 0 deletions common/status_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module represents health endpoint + prometheus metrics as one async server
called status.
"""

from aiohttp import web
from prometheus_client import generate_latest

Expand Down
1 change: 1 addition & 0 deletions common/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Various utility functions.
"""

import asyncio
import json
from datetime import datetime
Expand Down
1 change: 1 addition & 0 deletions common/vmaas_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Async VMaaS API client
"""

import asyncio
import ssl

Expand Down
2 changes: 1 addition & 1 deletion evaluator/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Vulnerability engine Evaluator component.
"""

import json
import re
from collections import namedtuple
Expand All @@ -14,7 +15,6 @@
from common.peewee_model import VulnerabilityState
from common.utils import get_available_remediation_type


CFG = Config()
PROMETHEUS_PORT = CFG.prometheus_port or str(CFG.evaluator_prometheus_port)
PACKAGE_RE = re.compile(r"(([0-9]+):)?(?P<pn>[^:]+)-.*[^-:]+-.*")
Expand Down
10 changes: 6 additions & 4 deletions evaluator/evaluator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Vulnerability engine evaluator component
"""

import asyncio
import json
import signal
Expand All @@ -9,10 +10,6 @@
from dateutil import parser
from psycopg_pool.pool_async import AsyncConnectionPool

from .common import CFG
from .common import MESSAGE_PARSE_ERROR
from .common import PROMETHEUS_PORT
from .processor import EvaluatorProcessor
from common.constants import EvaluatorMessageType
from common.database_handler import setup_async_db_pool
from common.feature_flags import initialize_unleash
Expand All @@ -25,6 +22,11 @@
from common.utils import a_ensure_minimal_schema_version
from common.utils import create_task_and_log

from .common import CFG
from .common import MESSAGE_PARSE_ERROR
from .common import PROMETHEUS_PORT
from .processor import EvaluatorProcessor

LOGGER = get_logger(__name__)


Expand Down
16 changes: 9 additions & 7 deletions evaluator/logic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Vulnerability engine evaluator logic component
"""

import json
from datetime import datetime
from typing import Dict
Expand All @@ -15,26 +16,27 @@
from psycopg.types.json import Jsonb
from psycopg_pool.pool_async import AsyncConnectionPool

from common.constants import format_vmaas_cve_endpoint
from common.logging import get_logger
from common.peewee_model import VulnerabilityState
from common.vmaas_client import vmaas_request

from .common import CFG
from .common import EVAL_PART_TIME
from .common import RULES_EVAL_TIME
from .common import VMAAS_EVAL_TIME
from .common import CpeCache
from .common import CveAdvisories
from .common import CveCache
from .common import CveImpactCache
from .common import CveUnpatched
from .common import EVAL_PART_TIME
from .common import ModuleCache
from .common import PackageNameCache
from .common import RuleCache
from .common import RULES_EVAL_TIME
from .common import SystemPlatform
from .common import SystemVulnerabilitiesRow
from .common import VMAAS_EVAL_TIME
from .common import VmaasErrorException
from .common import VulnerablePackageCache
from common.constants import format_vmaas_cve_endpoint
from common.logging import get_logger
from common.peewee_model import VulnerabilityState
from common.vmaas_client import vmaas_request

LOGGER = get_logger(__name__)

Expand Down
20 changes: 11 additions & 9 deletions evaluator/processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Processing logic of grouped evaluator message for single system
"""

import asyncio
import json
from datetime import datetime
Expand All @@ -17,31 +18,32 @@
from psycopg.rows import dict_row
from psycopg_pool.pool_async import AsyncConnectionPool

from common.logging import get_logger
from common.mqueue import MQWriter
from common.peewee_model import VulnerabilityState
from common.utils import executemany_fetchall
from common.utils import send_msg_to_payload_tracker
from common.utils import send_notifications
from common.utils import send_remediations_update

from .common import EMPTY_DATA_SKIP
from .common import EVAL_COUNT
from .common import EVAL_PART_TIME
from .common import EVAL_PERFORMED_COUNT
from .common import EVAL_TIME
from .common import EVALUATED_EARLIER_SKIP
from .common import EvaluatorException
from .common import INV_ID_NOT_FOUND
from .common import PACKAGE_RE
from .common import RECALC_EVENT_ERROR
from .common import RECALC_PACKAGES_UNCHANGED_SKIP
from .common import VMAAS_ERRORS_SKIP
from .common import EvaluatorException
from .common import RecalcEvent
from .common import SystemPlatform
from .common import SystemVulnerabilitiesRow
from .common import VMAAS_ERRORS_SKIP
from .common import VmaasErrorException
from .common import VulnerabilityDB
from .logic import EvaluatorLogic
from common.logging import get_logger
from common.mqueue import MQWriter
from common.peewee_model import VulnerabilityState
from common.utils import executemany_fetchall
from common.utils import send_msg_to_payload_tracker
from common.utils import send_notifications
from common.utils import send_remediations_update

LOGGER = get_logger(__name__)

Expand Down
1 change: 1 addition & 0 deletions exploit_sync/exploit_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Exploit sync job
"""

import base64
import json

Expand Down
1 change: 1 addition & 0 deletions grouper/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Common grouper tools.
"""

import asyncio
from dataclasses import dataclass
from enum import Enum
Expand Down
8 changes: 5 additions & 3 deletions grouper/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
Vulnerability grouper pod, groups the messages from listener (inventory/evaluator uploads),
and attempts to pair them.
"""

import asyncio
import json
import signal

from aiokafka.structs import ConsumerRecord

from .common import CFG
from .common import GrouperMessageType
from .queue import GrouperQueue
from common.logging import get_logger
from common.logging import init_logging
from common.mqueue import MQReader
from common.status_app import create_status_app
from common.status_app import create_status_runner
from common.utils import create_task_and_log

from .common import CFG
from .common import GrouperMessageType
from .queue import GrouperQueue

LOGGER = get_logger(__name__)


Expand Down
16 changes: 9 additions & 7 deletions grouper/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
Grouper Queue, groups advisor and inventory msgs, and sends the grouped
message to evaluator
"""

import asyncio
from datetime import datetime
from datetime import timezone
from typing import Dict

from common.constants import EvaluatorMessageType
from common.logging import get_logger
from common.mqueue import MQWriter
from common.utils import create_task_and_log
from common.utils import send_msg_to_payload_tracker

from .common import ADVISOR_QUEUE_SIZE
from .common import BoundedSemaphorePrometheus
from .common import CFG
from .common import CHANGED_SYSTEM
from .common import INVENTORY_QUEUE_SIZE
from .common import PAIR_HIT
from .common import PAIR_MISS
from .common import QUEUE_SIZE
from .common import QueueItem
from .common import UNCHANGED_SYSTEM
from common.constants import EvaluatorMessageType
from common.logging import get_logger
from common.mqueue import MQWriter
from common.utils import create_task_and_log
from common.utils import send_msg_to_payload_tracker
from .common import BoundedSemaphorePrometheus
from .common import QueueItem

LOGGER = get_logger(__name__)

Expand Down
Loading

0 comments on commit c285066

Please sign in to comment.