Skip to content

Commit

Permalink
Refactored architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenhortas committed Sep 11, 2024
1 parent 7b0fc6e commit 9a59b8b
Show file tree
Hide file tree
Showing 22 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/fail2bangeolocation/application/location.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from tqdm import tqdm

from src.fail2bangeolocation.application import fail2ban, fail2banlog
from src.fail2bangeolocation.application.country import Country
from src.fail2bangeolocation.application.reallyfreegeoip import get_location, REALLYFREEGEOIP_URL
from src.fail2bangeolocation.application.utils.url_utils import is_online
from src.fail2bangeolocation.domain import fail2ban, fail2banlog
from src.fail2bangeolocation.domain.country import Country
from src.fail2bangeolocation.infrastructure.reallyfreegeoip import get_location, REALLYFREEGEOIP_URL
from src.fail2bangeolocation.domain.utils.url_utils import is_online
from src.fail2bangeolocation.crosscutting.strings import UNKNOWN


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from src.fail2bangeolocation.application.utils.system_utils import execute_command
from src.fail2bangeolocation.domain.utils.system_utils import execute_command

_FAIL2BAN_CLIENT = 'fail2ban-client'
_BANNED = 'banned'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from src.fail2bangeolocation.application.handlers.exception_handler import handle_exception
from src.fail2bangeolocation.domain.handlers.exception_handler import handle_exception

_REGEX_BANNED_IPS = re.compile(r'^.*\s(Found|Ban)\s(?P<ip>(\d{1,3}.){3}\d{1,3}).*$')
_REGEX_UNBANNED_IPS = re.compile(r'^.*\sUnban\s(?P<ip>(\d{1,3}.){3}\d{1,3}).*$')
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

from src.fail2bangeolocation.application.handlers.error_handler import handle_error
from src.fail2bangeolocation.domain.handlers.error_handler import handle_error
from src.fail2bangeolocation.crosscutting import strings


Expand Down
4 changes: 2 additions & 2 deletions src/fail2bangeolocation/fail2bangeolocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import argparse
import signal

from src.fail2bangeolocation.application.handlers.signal_handler import handle_sigint
from src.fail2bangeolocation.application.location import get_ips, locate
from src.fail2bangeolocation.application.utils.python_utils import get_python_interpreter_version
from src.fail2bangeolocation.domain.handlers.signal_handler import handle_sigint
from src.fail2bangeolocation.domain.utils.python_utils import get_python_interpreter_version
from src.fail2bangeolocation.crosscutting import constants, strings
from src.fail2bangeolocation.crosscutting.condition_messages import print_error, print_info
from src.fail2bangeolocation.presentation.cli_print import print_locations, print_unlocated_ips
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/fail2bangeolocation/presentation/cli_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from colorama import Style, Fore

from src.fail2bangeolocation.application.country import Country
from src.fail2bangeolocation.domain.country import Country
from src.fail2bangeolocation.crosscutting import strings


Expand Down
2 changes: 1 addition & 1 deletion tests/cli_print_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from src.fail2bangeolocation.application.country import Country
from src.fail2bangeolocation.domain.country import Country
from src.fail2bangeolocation.presentation.cli_print import print_locations, print_unlocated_ips


Expand Down
8 changes: 4 additions & 4 deletions tests/fail2ban_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import patch

from src.fail2bangeolocation.application.fail2ban import get_banned_ips
from src.fail2bangeolocation.domain.fail2ban import get_banned_ips


# noinspection SpellCheckingInspection
Expand All @@ -20,17 +20,17 @@ def setUp(self):
`- Banned IP list: 5.181.86.251'''
self.fail2ban_status_sshd_expected_result = ['5.181.86.251']

@patch('src.fail2bangeolocation.application.fail2ban.execute_command')
@patch('src.fail2bangeolocation.domain.fail2ban.execute_command')
def test_server_none(self, mock_execute_command):
mock_execute_command.return_value = None
self.assertEqual([], get_banned_ips())

@patch('src.fail2bangeolocation.application.fail2ban.execute_command')
@patch('src.fail2bangeolocation.domain.fail2ban.execute_command')
def test_command_returns_none(self, mock_execute_command):
mock_execute_command.return_value = self.fail2ban_banned
self.assertEqual(self.fail2ban_banned_expected_result, get_banned_ips())

@patch('src.fail2bangeolocation.application.fail2ban.execute_command')
@patch('src.fail2bangeolocation.domain.fail2ban.execute_command')
def test_server_sshd(self, mock_execute_command):
mock_execute_command.return_value = self.fail2ban_status_sshd
self.assertEqual(self.fail2ban_status_sshd_expected_result, get_banned_ips('sshd'))
Expand Down
2 changes: 1 addition & 1 deletion tests/fail2banlog_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import unittest

from src.fail2bangeolocation.application.fail2banlog import get_banned_ips
from src.fail2bangeolocation.domain.fail2banlog import get_banned_ips


class Fail2banLogTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/location_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from src.fail2bangeolocation.application.country import Country
from src.fail2bangeolocation.domain.country import Country
# noinspection PyProtectedMember
from src.fail2bangeolocation.application.location import _group_locations, _sort_grouped_locations

Expand Down
2 changes: 1 addition & 1 deletion tests/reallyfreegeoip_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from src.fail2bangeolocation.application.reallyfreegeoip import get_location
from src.fail2bangeolocation.infrastructure.reallyfreegeoip import get_location


# noinspection SpellCheckingInspection
Expand Down

0 comments on commit 9a59b8b

Please sign in to comment.