From e0779347b2862e0d8f6c18da98f91142beaa6a81 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 23 Sep 2021 18:42:40 +0200 Subject: [PATCH] Island: Add all imports from encryption to __init__ Now the imports are shorter by one directory. Check the __init__ in encryption. --- .flake8 | 1 + .../field_encryptors/string_list_encryptor.py | 2 +- .../cc/resources/configuration_export.py | 4 +--- .../cc/resources/configuration_import.py | 2 +- monkey/monkey_island/cc/server_setup.py | 4 +--- .../cc/server_utils/encryption/__init__.py | 14 +++++++++++++- .../encryption/data_store_encryptor.py | 2 +- .../technique_reports/technique_report_tools.py | 2 +- monkey/monkey_island/cc/services/config.py | 2 +- .../cc/services/telemetry/processing/exploit.py | 2 +- .../services/telemetry/processing/system_info.py | 2 +- .../scoutsuite/scoutsuite_auth_service.py | 2 +- .../field_encryptors/test_string_list_encryptor.py | 2 +- .../cc/resources/test_configuration_import.py | 4 +--- .../encryption/test_data_store_encryptor.py | 5 +---- .../encryption/test_password_based_encryption.py | 5 +---- .../scoutsuite/test_scoutsuite_auth_service.py | 5 +---- pyproject.toml | 1 + 18 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.flake8 b/.flake8 index 97d903b8f..213c030a2 100644 --- a/.flake8 +++ b/.flake8 @@ -5,6 +5,7 @@ exclude = monkey/monkey_island/cc/ui,vulture_allowlist.py show-source = True max-complexity = 10 max-line-length = 100 +per-file-ignores = __init__.py:F401 ### ignore "whitespace before ':'", "line break before binary operator" for ### compatibility with black, and cyclomatic complexity (for now). diff --git a/monkey/monkey_island/cc/models/utils/field_encryptors/string_list_encryptor.py b/monkey/monkey_island/cc/models/utils/field_encryptors/string_list_encryptor.py index 8cde30af0..ab9b6a3e5 100644 --- a/monkey/monkey_island/cc/models/utils/field_encryptors/string_list_encryptor.py +++ b/monkey/monkey_island/cc/models/utils/field_encryptors/string_list_encryptor.py @@ -1,7 +1,7 @@ from typing import List from monkey_island.cc.models.utils.field_encryptors.i_field_encryptor import IFieldEncryptor -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor class StringListEncryptor(IFieldEncryptor): diff --git a/monkey/monkey_island/cc/resources/configuration_export.py b/monkey/monkey_island/cc/resources/configuration_export.py index 089e9c813..c550acc7d 100644 --- a/monkey/monkey_island/cc/resources/configuration_export.py +++ b/monkey/monkey_island/cc/resources/configuration_export.py @@ -4,9 +4,7 @@ import flask_restful from flask import request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.server_utils.encryption.password_based_encryption import ( - PasswordBasedEncryptor, -) +from monkey_island.cc.server_utils.encryption import PasswordBasedEncryptor from monkey_island.cc.services.config import ConfigService diff --git a/monkey/monkey_island/cc/resources/configuration_import.py b/monkey/monkey_island/cc/resources/configuration_import.py index c4b64a363..6c0575e94 100644 --- a/monkey/monkey_island/cc/resources/configuration_import.py +++ b/monkey/monkey_island/cc/resources/configuration_import.py @@ -8,7 +8,7 @@ from flask import request from common.utils.exceptions import InvalidConfigurationError from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.server_utils.encryption.password_based_encryption import ( +from monkey_island.cc.server_utils.encryption import ( InvalidCiphertextError, InvalidCredentialsError, PasswordBasedEncryptor, diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index e5d4dc47e..7d8bf2d9f 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -27,9 +27,7 @@ from monkey_island.cc.server_utils.consts import ( # noqa: E402 GEVENT_EXCEPTION_LOG, MONGO_CONNECTION_TIMEOUT, ) -from monkey_island.cc.server_utils.encryption.data_store_encryptor import ( # noqa: E402 - initialize_encryptor, -) +from monkey_island.cc.server_utils.encryption import initialize_encryptor # noqa: E402 from monkey_island.cc.server_utils.island_logger import reset_logger, setup_logging # noqa: E402 from monkey_island.cc.services.initialize import initialize_services # noqa: E402 from monkey_island.cc.services.reporting.exporter_init import populate_exporter_list # noqa: E402 diff --git a/monkey/monkey_island/cc/server_utils/encryption/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/__init__.py index d15968ca7..e245575eb 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/__init__.py +++ b/monkey/monkey_island/cc/server_utils/encryption/__init__.py @@ -1 +1,13 @@ -from monkey_island.cc.server_utils.encryption.i_encryptor import IEncryptor # noqa: F401 +from monkey_island.cc.server_utils.encryption.i_encryptor import IEncryptor +from monkey_island.cc.server_utils.encryption.key_based_encryptor import KeyBasedEncryptor +from monkey_island.cc.server_utils.encryption.password_based_encryption import ( + InvalidCiphertextError, + InvalidCredentialsError, + PasswordBasedEncryptor, + is_encrypted, +) +from monkey_island.cc.server_utils.encryption.data_store_encryptor import ( + DataStoreEncryptor, + get_encryptor, + initialize_encryptor, +) diff --git a/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py index f2b989816..f4125e1bf 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py @@ -4,7 +4,7 @@ import os # is maintained. from Crypto import Random # noqa: DUO133 # nosec: B413 -from monkey_island.cc.server_utils.encryption.key_based_encryptor import KeyBasedEncryptor +from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor from monkey_island.cc.server_utils.file_utils import open_new_securely_permissioned_file _encryptor = None diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/technique_report_tools.py b/monkey/monkey_island/cc/services/attack/technique_reports/technique_report_tools.py index 88243de5d..8e8938d93 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/technique_report_tools.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/technique_report_tools.py @@ -1,4 +1,4 @@ -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor def parse_creds(attempt): diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 7f69928c0..d5da366d6 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -19,7 +19,7 @@ from common.config_value_paths import ( USER_LIST_PATH, ) from monkey_island.cc.database import mongo -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor from monkey_island.cc.services.config_manipulator import update_config_per_mode from monkey_island.cc.services.config_schema.config_schema import SCHEMA from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode diff --git a/monkey/monkey_island/cc/services/telemetry/processing/exploit.py b/monkey/monkey_island/cc/services/telemetry/processing/exploit.py index 246176a8d..bd78e1fe8 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/exploit.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/exploit.py @@ -3,7 +3,7 @@ import copy import dateutil from monkey_island.cc.models import Monkey -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.edge.displayed_edge import EdgeService from monkey_island.cc.services.node import NodeService diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py index 3cc1dc560..4d54af4d8 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py @@ -1,6 +1,6 @@ import logging -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.node import NodeService from monkey_island.cc.services.telemetry.processing.system_info_collectors.system_info_telemetry_dispatcher import ( # noqa: E501 diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py index 3ac6a7861..ece015935 100644 --- a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py +++ b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py @@ -5,7 +5,7 @@ from ScoutSuite.providers.base.authentication_strategy import AuthenticationExce from common.cloud.scoutsuite_consts import CloudProviders from common.config_value_paths import AWS_KEYS_PATH from common.utils.exceptions import InvalidAWSKeys -from monkey_island.cc.server_utils.encryption.data_store_encryptor import get_encryptor +from monkey_island.cc.server_utils.encryption import get_encryptor from monkey_island.cc.services.config import ConfigService diff --git a/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py index 1428a0009..9af487e24 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py +++ b/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py @@ -1,7 +1,7 @@ import pytest from monkey_island.cc.models.utils.field_encryptors.string_list_encryptor import StringListEncryptor -from monkey_island.cc.server_utils.encryption.data_store_encryptor import initialize_encryptor +from monkey_island.cc.server_utils.encryption import initialize_encryptor MOCK_STRING_LIST = ["test_1", "test_2"] EMPTY_LIST = [] diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_configuration_import.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_configuration_import.py index ac72f01c2..fb397f234 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_configuration_import.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_configuration_import.py @@ -8,9 +8,7 @@ from tests.unit_tests.monkey_island.cc.services.utils.ciphertexts_for_encryption from common.utils.exceptions import InvalidConfigurationError from monkey_island.cc.resources.configuration_import import ConfigurationImport -from monkey_island.cc.server_utils.encryption.password_based_encryption import ( - PasswordBasedEncryptor, -) +from monkey_island.cc.server_utils.encryption import PasswordBasedEncryptor def test_is_config_encrypted__json(monkey_config_json): diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py index e3dbd8afa..fa135c345 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py @@ -1,9 +1,6 @@ import os -from monkey_island.cc.server_utils.encryption.data_store_encryptor import ( - get_encryptor, - initialize_encryptor, -) +from monkey_island.cc.server_utils.encryption import get_encryptor, initialize_encryptor PASSWORD_FILENAME = "mongo_key.bin" diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py index cb3756e40..d00609481 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py @@ -4,10 +4,7 @@ from tests.unit_tests.monkey_island.cc.services.utils.ciphertexts_for_encryption VALID_CIPHER_TEXT, ) -from monkey_island.cc.server_utils.encryption.password_based_encryption import ( - InvalidCredentialsError, - PasswordBasedEncryptor, -) +from monkey_island.cc.server_utils.encryption import InvalidCredentialsError, PasswordBasedEncryptor MONKEY_CONFIGS_DIR_PATH = "monkey_configs" STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME = "monkey_config_standard.json" diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py index 12809dfa8..3df67330c 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py @@ -5,10 +5,7 @@ import pytest from common.config_value_paths import AWS_KEYS_PATH from monkey_island.cc.database import mongo -from monkey_island.cc.server_utils.encryption.data_store_encryptor import ( - get_encryptor, - initialize_encryptor, -) +from monkey_island.cc.server_utils.encryption import get_encryptor, initialize_encryptor from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service import ( is_aws_keys_setup, diff --git a/pyproject.toml b/pyproject.toml index 05c8dfe81..88da84d42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true ensure_newline_before_comments = true +skip_glob="**/__init__.py" [tool.pytest.ini_options] minversion = "6.0"