Skip to content

Commit db4e5c3

Browse files
authored
python: Sort imports with isort (#2275)
Enables isort for import sorting https://pycqa.github.io/isort/
1 parent 1055a27 commit db4e5c3

File tree

82 files changed

+270
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+270
-212
lines changed

.ci/scripts/get_versions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
- main:
1818
Retrieves available versions of Elastic Agent and performs operations on them.
1919
"""
20-
import os
21-
import json
2220
import argparse
21+
import json
22+
import os
23+
2324
import requests
2425

2526

.ci/scripts/prepare_slack_data.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
It reads environment variables set by the GitHub Actions runtime, validates them, and
55
constructs a Slack payload based on the workflow status.
66
"""
7-
import os
87
import json
9-
8+
import os
109

1110
color_by_job_status = {
1211
"success": "#36a64f",

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ repos:
5252
# TODO: Apply pylint in security-policies
5353
exclude: security-policies.*
5454

55+
- repo: https://github.com/pycqa/isort
56+
rev: 5.13.2
57+
hooks:
58+
- id: isort
59+
name: isort (python)
60+
5561
- repo: https://github.com/psf/black
5662
rev: 24.4.2
5763
hooks:

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[tool.black]
22
line-length = 120
3+
4+
[tool.isort]
5+
profile = "black"

security-policies/dev/generate_rule_metadata.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import argparse
22
import os
33
import uuid
4-
5-
import pandas as pd
4+
from dataclasses import asdict, dataclass
65

76
import common
8-
from dataclasses import dataclass, asdict
9-
7+
import pandas as pd
108
from ruamel.yaml import YAML
119

1210
yml = YAML()

security-policies/dev/generate_rule_templates.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import argparse
2-
import os
3-
import yaml
42
import json
5-
import common
3+
import os
64
from pathlib import Path
75

6+
import common
7+
import yaml
8+
89
INTEGRATION_RULE_TEMPLATE_DIR = "../../../integrations/packages/cloud_security_posture/kibana/csp_rule_template/"
910

1011

tests/commonlib/agents_map.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Generate agent parameterization for pytest.
33
"""
44

5+
from configuration import agent, elasticsearch
6+
from fleet_api.agent_policy_api import get_agents
57
from loguru import logger
68
from munch import Munch
7-
from configuration import elasticsearch, agent
8-
from fleet_api.agent_policy_api import get_agents
9-
109

1110
CIS_AWS_COMPONENT = "cloudbeat/cis_aws"
1211
CIS_GCP_COMPONENT = "cloudbeat/cis_gcp"

tests/commonlib/framework/reporting.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"""
44

55
from __future__ import annotations
6+
67
from dataclasses import dataclass
8+
9+
import allure
710
import pytest
811
from allure_commons.types import LinkType
9-
import allure
1012

1113

1214
@dataclass

tests/commonlib/io_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import os
88
import shutil
99
import subprocess
10-
1110
from datetime import datetime
1211
from pathlib import Path
1312

1413
import yaml
15-
from munch import Munch, munchify
1614
from loguru import logger
15+
from munch import Munch, munchify
1716

1817

1918
def get_events_from_index(

tests/commonlib/kubernetes.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
This module provides kubernetes functionality based on original kubernetes python library.
33
"""
44

5+
from pathlib import Path
56
from subprocess import CalledProcessError
67
from typing import Union
7-
from pathlib import Path
88

9+
from commonlib.io_utils import get_k8s_yaml_objects
910
from kubernetes import client, config, utils
1011
from kubernetes.client import ApiException
11-
from kubernetes.watch import watch
1212
from kubernetes.stream import stream
13-
14-
from commonlib.io_utils import get_k8s_yaml_objects
13+
from kubernetes.watch import watch
1514
from loguru import logger
1615

1716
RESOURCE_POD = "Pod"

tests/commonlib/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import datetime
33
import json
44
import time
5-
from typing import Union
65
from functools import reduce
6+
from typing import Union
7+
78
import allure
8-
from commonlib.io_utils import get_logs_from_stream, get_events_from_index
9+
from commonlib.io_utils import get_events_from_index, get_logs_from_stream
910
from loguru import logger
1011

1112
FINDINGS_BACKOFF_SECONDS = 5

tests/configuration.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"""
66

77
import os
8-
from munch import Munch
8+
99
from loguru import logger
10+
from munch import Munch
1011

1112
FINDINGS_INDEX_PATTERN = "*cloud_security_posture.findings*"
1213
VULNERABILITIES_INDEX_PATTERN = "*cloud_security_posture.vulnerabilities*"

tests/conftest.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
Global pytest file for fixtures and test configs
33
"""
44

5+
import functools
56
import logging
67
import sys
7-
import functools
88
import time
99

10-
import pytest
1110
import configuration
12-
from commonlib.agents_map import AgentExpectedMapping, AgentComponentMapping
13-
from commonlib.kubernetes import KubernetesHelper
14-
from commonlib.elastic_wrapper import ElasticWrapper
11+
import pytest
12+
from _pytest.logging import LogCaptureFixture
13+
from commonlib.agents_map import AgentComponentMapping, AgentExpectedMapping
1514
from commonlib.docker_wrapper import DockerWrapper
15+
from commonlib.elastic_wrapper import ElasticWrapper
1616
from commonlib.io_utils import FsClient
17-
from _pytest.logging import LogCaptureFixture
17+
from commonlib.kubernetes import KubernetesHelper
1818
from loguru import logger
1919

2020

tests/fleet_api/agent_policy_api.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"""
44

55
from typing import Optional
6-
from munch import Munch, munchify
7-
from loguru import logger
6+
87
from fleet_api.base_call_api import APICallException, perform_api_call
8+
from loguru import logger
9+
from munch import Munch, munchify
910

1011

1112
def create_agent_policy(cfg: Munch, json_policy: dict) -> str:

tests/fleet_api/common_api.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
This module contains API calls related to Fleet settings
33
"""
44

5-
import time
6-
import json
75
import codecs
8-
from typing import Dict, Any, List
9-
from munch import Munch, munchify
10-
from loguru import logger
6+
import json
7+
import time
8+
from typing import Any, Dict, List
9+
1110
from fleet_api.base_call_api import APICallException, perform_api_call
12-
from fleet_api.utils import (
13-
replace_image_field,
14-
add_capabilities,
15-
add_tags,
16-
)
11+
from fleet_api.utils import add_capabilities, add_tags, replace_image_field
12+
from loguru import logger
13+
from munch import Munch, munchify
1714

1815
AGENT_ARTIFACT_SUFFIX = "/downloads/beats/elastic-agent"
1916
AGENT_ARTIFACT_SUFFIX_SHORT = "/downloads/"

tests/fleet_api/package_policy_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
This module contains API calls related to the package policy API.
33
"""
44

5-
from munch import Munch, munchify
6-
from loguru import logger
75
from fleet_api.base_call_api import APICallException, perform_api_call
8-
from fleet_api.utils import update_key, delete_key
6+
from fleet_api.utils import delete_key, update_key
7+
from loguru import logger
8+
from munch import Munch, munchify
99

1010

1111
def create_kspm_unmanaged_integration(cfg: Munch, pkg_policy: dict, agent_policy_id: str) -> str:

tests/integration/tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Integration tests setup configurations and fixtures
33
"""
44

5-
from pathlib import Path
65
import time
6+
from pathlib import Path
7+
78
import pytest
89
from commonlib.io_utils import get_k8s_yaml_objects
910
from commonlib.kubernetes import ApiException

tests/integration/tests/test_cloudbeat_integration.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
Cloudbeat -> ElasticSearch
66
"""
77

8-
import pytest
98
import configuration
10-
11-
from commonlib.utils import wait_for_cycle_completion, get_findings
9+
import pytest
10+
from commonlib.utils import get_findings, wait_for_cycle_completion
1211
from loguru import logger
1312

1413
CONFIG_TIMEOUT = 45

tests/integration/tests/test_sanity_checks.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
"""
99

1010
import time
11+
1112
import pytest
12-
from loguru import logger
13-
from configuration import elasticsearch
13+
from commonlib.agents_map import (
14+
CIS_AWS_COMPONENT,
15+
CIS_AZURE_COMPONENT,
16+
AgentComponentMapping,
17+
AgentExpectedMapping,
18+
)
1419
from commonlib.utils import get_findings
15-
from commonlib.agents_map import CIS_AWS_COMPONENT, CIS_AZURE_COMPONENT, AgentExpectedMapping, AgentComponentMapping
20+
from configuration import elasticsearch
21+
from loguru import logger
1622

1723
CONFIG_TIMEOUT = 120
1824
GCP_CONFIG_TIMEOUT = 600

tests/integration/tests/test_standalone_agent_integration.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"""
77

88
import pytest
9-
10-
from commonlib.utils import get_findings
119
from commonlib.io_utils import FsClient
10+
from commonlib.utils import get_findings
1211
from loguru import logger
1312

1413
testdata = ["file", "process", "k8s_object"]

tests/integrations_setup/agents_enrolled.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
If the expected number of agents is not enrolled within the timeout, the test will fail
44
"""
55

6+
import re
67
import sys
78
import time
8-
import re
99
from dataclasses import dataclass
10-
from fleet_api.agent_policy_api import get_agents
10+
1111
import configuration_fleet as cnfg
12-
from state_file_manager import state_manager
12+
from fleet_api.agent_policy_api import get_agents
1313
from loguru import logger
14+
from state_file_manager import state_manager
1415

1516
TIMEOUT = 600
1617

tests/integrations_setup/configuration_fleet.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""
1818

1919
import os
20+
2021
from munch import Munch
2122

2223
# CNVM_TAGS format: "Key=<key1>,Value=<value1> Key=<key2>,Value=<value2> ..."

tests/integrations_setup/install_agentless_integrations.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"""
99

1010
import json
11+
1112
import configuration_fleet as cnfg
12-
from loguru import logger
1313
from fleet_api.package_policy_api import create_cspm_integration
14+
from loguru import logger
1415
from package_policy import (
1516
generate_package_policy,
1617
generate_policy_template,

tests/integrations_setup/install_cnvm_integration.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,32 @@
77
2. Create a CNVM AWS integration.
88
3. Create a deploy/cloudformation/config.json file to be used by the just deploy-cloudformation command.
99
"""
10-
import sys
1110
import json
11+
import sys
1212
from pathlib import Path
13-
from munch import Munch
13+
1414
import configuration_fleet as cnfg
1515
from fleet_api.agent_policy_api import create_agent_policy
16-
from fleet_api.package_policy_api import create_cnvm_integration
17-
from fleet_api.utils import rename_file_by_suffix
1816
from fleet_api.common_api import (
17+
get_artifact_server,
18+
get_cnvm_template,
1919
get_enrollment_token,
2020
get_fleet_server_host,
21-
get_artifact_server,
2221
get_package_version,
23-
get_cnvm_template,
2422
)
23+
from fleet_api.package_policy_api import create_cnvm_integration
24+
from fleet_api.utils import rename_file_by_suffix
2525
from loguru import logger
26-
from state_file_manager import state_manager, PolicyState, HostType
26+
from munch import Munch
2727
from package_policy import (
28-
version_compatible,
2928
VERSION_MAP,
30-
load_data,
29+
extract_template_url,
3130
generate_random_name,
3231
get_package_default_url,
33-
extract_template_url,
32+
load_data,
33+
version_compatible,
3434
)
35+
from state_file_manager import HostType, PolicyState, state_manager
3536

3637
CNVM_EXPECTED_AGENTS = 1
3738
CNVM_CLOUDFORMATION_CONFIG = "../../deploy/cloudformation/config.json"

0 commit comments

Comments
 (0)