Skip to content

Commit 97f4bb3

Browse files
🧹 chore: Updated files to comply with pylint requirements
1 parent 153cf3c commit 97f4bb3

File tree

10 files changed

+54
-51
lines changed

10 files changed

+54
-51
lines changed

api/v1/alert.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Standard library imports
44
from datetime import datetime
5-
import sys
65
import time
76

87
# Third-party imports
@@ -14,7 +13,6 @@
1413
from user_agents import parse
1514

1615
# Local imports
17-
from utils.custom_limiter import custom_rate_limiter
1816
from models.responses import (
1917
AlertResponse,
2018
UnsubscribeResponse,
@@ -23,6 +21,7 @@
2321
from services.analytics import get_breaches_analytics
2422
from services.breach import get_breaches, get_exposure, get_sensitive_exposure
2523
from services.send_email import send_alert_confirmation, send_unsub_email
24+
from utils.custom_limiter import custom_rate_limiter
2625
from utils.helpers import fetch_location_by_ip, get_preferred_ip_address
2726
from utils.token import confirm_token, generate_confirmation_token
2827
from utils.validation import validate_email_with_tld, validate_url, validate_variables

api/v1/analytics.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,41 @@
55
import html
66
import logging
77
from collections import defaultdict
8-
from typing import Optional, Union, Dict, Any, List
8+
from typing import Any, Dict, Optional, Union
99

1010
# Third-party imports
11-
from fastapi import APIRouter, HTTPException, Request, Query
11+
from fastapi import APIRouter, HTTPException, Query, Request
1212
from fastapi.responses import HTMLResponse, JSONResponse
1313
from fastapi.templating import Jinja2Templates
1414
from google.cloud import datastore
1515
from google.api_core import exceptions as google_exceptions
1616

1717
# Local imports
18-
from utils.custom_limiter import custom_rate_limiter
1918
from models.responses import (
19+
BreachDetails,
20+
BreachHierarchyResponse,
21+
DetailedBreachInfo,
2022
DetailedMetricsResponse,
21-
PulseNewsResponse,
22-
DomainAlertResponse,
2323
DomainAlertErrorResponse,
24-
DomainBreachesResponse,
24+
DomainAlertResponse,
2525
DomainBreachesErrorResponse,
26-
BreachDetails,
27-
DetailedBreachInfo,
28-
ShieldActivationResponse,
26+
DomainBreachesResponse,
27+
PulseNewsResponse,
2928
ShieldActivationErrorResponse,
30-
BreachHierarchyResponse,
31-
)
32-
from services.analytics import (
33-
get_detailed_metrics,
34-
get_pulse_news,
29+
ShieldActivationResponse,
3530
)
31+
from services.analytics import get_detailed_metrics, get_pulse_news
3632
from services.send_email import send_dashboard_email_confirmation, send_shield_email
33+
from utils.custom_limiter import custom_rate_limiter
34+
from utils.helpers import fetch_location_by_ip, get_preferred_ip_address
35+
from utils.request import get_client_ip, get_user_agent_info
36+
from utils.token import confirm_token, generate_confirmation_token
3737
from utils.validation import (
3838
validate_email_with_tld,
39+
validate_token,
3940
validate_url,
4041
validate_variables,
41-
validate_token,
4242
)
43-
from utils.token import generate_confirmation_token, confirm_token
44-
from utils.helpers import get_preferred_ip_address, fetch_location_by_ip
45-
from utils.request import get_client_ip, get_user_agent_info
4643

4744
router = APIRouter()
4845
templates = Jinja2Templates(directory="templates")

api/v1/api_keys.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import datetime
55
import logging
66
from typing import Optional
7+
78
from fastapi import APIRouter, Request
89
from google.cloud import datastore
910

10-
from utils.custom_limiter import custom_rate_limiter
1111
from models.base import BaseResponse
12-
from utils.validation import validate_variables, validate_url
12+
from utils.custom_limiter import custom_rate_limiter
13+
from utils.validation import validate_url, validate_variables
1314

1415
router = APIRouter()
1516

api/v1/breaches.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
# Standard library imports
44
import json
5-
import sys
65
from datetime import datetime
7-
from typing import Optional, Union, List, Dict
6+
from typing import Optional, Union
87

98
# Third-party imports
10-
from fastapi import APIRouter, HTTPException, Request, Header, Query, Path
9+
from fastapi import APIRouter, Header, HTTPException, Path, Query, Request
1110
from fastapi.responses import JSONResponse, Response
1211
from google.cloud import datastore
1312

1413
# Local imports
1514
from config.settings import MAX_EMAIL_LENGTH
16-
from utils.custom_limiter import custom_rate_limiter
1715
from models.responses import (
1816
BreachAnalyticsResponse,
1917
BreachAnalyticsV2Response,
@@ -28,13 +26,14 @@
2826
get_ai_summary,
2927
get_summary_and_metrics,
3028
)
31-
from services.breach import get_exposure, get_sensitive_exposure, get_breaches
29+
from services.breach import get_breaches, get_exposure, get_sensitive_exposure
30+
from utils.custom_limiter import custom_rate_limiter
3231
from utils.helpers import (
32+
get_client_ip,
3333
string_to_boolean,
3434
validate_domain,
3535
validate_email_with_tld,
3636
validate_url,
37-
get_client_ip,
3837
)
3938
from utils.validation import validate_variables
4039

api/v1/domain_breaches.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
from typing import Dict, List
66
from operator import itemgetter
77

8-
from fastapi import APIRouter, Request, HTTPException, Header, Depends
8+
from fastapi import APIRouter, Depends, Header, HTTPException, Request
99
from google.cloud import datastore
1010
from pydantic import BaseModel, Field
1111

12-
from utils.custom_limiter import custom_rate_limiter
13-
from models.responses import DomainBreachesResponse, DomainBreachesErrorResponse
14-
15-
# from services.analytics import get_domain_breach_analytics
16-
from utils.validation import validate_url # , validate_api_key
1712
from models.base import BaseResponse
13+
from models.responses import DomainBreachesResponse
14+
from utils.custom_limiter import custom_rate_limiter
15+
from utils.validation import validate_url
1816

1917
router = APIRouter()
2018

api/v1/domain_phishing.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
"""Domain phishing check router module."""
22

3-
import socket
43
import json
5-
import os
4+
import socket
65
from datetime import datetime, timedelta
7-
from typing import Dict, List, Optional, Any, Union
86
from pathlib import Path
7+
from typing import Any, Dict, List, Optional, Union
98

109
import dnstwist
11-
from fastapi import APIRouter, Depends, HTTPException, Request, Query, Header
12-
from pydantic import BaseModel, Field, validator, EmailStr
10+
from fastapi import APIRouter, HTTPException, Query, Request
11+
from google.cloud import datastore
12+
from pydantic import BaseModel, EmailStr, Field, validator
1313
from redis import Redis
1414

15-
from config.settings import REDIS_HOST, REDIS_PORT, REDIS_DB
15+
from config.settings import REDIS_DB, REDIS_HOST, REDIS_PORT
1616
from models.responses import BaseResponse
17-
from utils.validation import validate_email_with_tld, validate_variables
18-
from utils.token import confirm_token
19-
from google.cloud import datastore
2017
from utils.custom_limiter import custom_rate_limiter
18+
from utils.token import confirm_token
2119

2220
router = APIRouter()
2321

@@ -37,6 +35,7 @@
3735

3836

3937
def validate_file_content(file_path: Path, min_lines: int = 1) -> None:
38+
"""Validate the content of a file to ensure it has sufficient lines."""
4039
if not file_path.exists():
4140
raise FileNotFoundError(f"File not found: {file_path}")
4241
with open(file_path, "r") as f:
@@ -55,10 +54,13 @@ def validate_file_content(file_path: Path, min_lines: int = 1) -> None:
5554

5655

5756
class DomainPhishingRequest(BaseModel):
57+
"""Request model for domain phishing check."""
58+
5859
domain: str = Field(..., description="Domain to check for phishing variants")
5960

6061
@validator("domain")
6162
def validate_domain(cls, v: str) -> str:
63+
"""Validate the domain format and length."""
6264
if not v or not isinstance(v, str):
6365
raise ValueError("Domain must be a non-empty string")
6466
if len(v) > 255:
@@ -69,13 +71,17 @@ def validate_domain(cls, v: str) -> str:
6971

7072

7173
class DomainPhishingSummaryResponse(BaseResponse):
74+
"""Summary response model for domain phishing check."""
75+
7276
total_scanned: int
7377
total_live: int = 0
7478
unique_fuzzers: int = 0
7579
last_checked: Optional[str] = None
7680

7781

7882
class DomainPhishingResponse(BaseResponse):
83+
"""Detailed response model for domain phishing check."""
84+
7985
total_scanned: int
8086
total_live: int = 0
8187
unique_fuzzers: int = 0
@@ -85,6 +91,7 @@ class DomainPhishingResponse(BaseResponse):
8591

8692

8793
def is_domain_live(domain: str) -> bool:
94+
"""Check if a domain is live by resolving its IP address."""
8895
try:
8996
socket.gethostbyname(domain)
9097
return True
@@ -93,6 +100,7 @@ def is_domain_live(domain: str) -> bool:
93100

94101

95102
def get_cached_result(domain: str) -> Optional[Dict]:
103+
"""Retrieve cached phishing check results from Redis."""
96104
cache_key = f"phishing_check:{domain}"
97105
cached_data = redis_client.get(cache_key)
98106
if cached_data:
@@ -104,13 +112,15 @@ def get_cached_result(domain: str) -> Optional[Dict]:
104112

105113

106114
def cache_result(domain: str, result: Dict, expiry_hours: int = 24) -> None:
115+
"""Cache phishing check results in Redis."""
107116
cache_key = f"phishing_check:{domain}"
108117
if isinstance(result.get("last_checked"), datetime):
109118
result["last_checked"] = result["last_checked"].isoformat()
110119
redis_client.setex(cache_key, timedelta(hours=expiry_hours), json.dumps(result))
111120

112121

113122
async def verify_user_access(email: str, token: str) -> bool:
123+
"""Verify user access based on email and token."""
114124
if not email or not token:
115125
return False
116126
try:

api/v1/slack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from fastapi import APIRouter, HTTPException, Request
44

5-
from utils.custom_limiter import custom_rate_limiter
65
from models.requests import ChannelSetupRequest
76
from models.responses import ChannelConfigResponse, ChannelSetupResponse
87
from services.slack import (
9-
setup_slack_channel,
10-
verify_slack_channel,
118
delete_slack_channel,
129
get_slack_channel_config,
10+
setup_slack_channel,
11+
verify_slack_channel,
1312
)
13+
from utils.custom_limiter import custom_rate_limiter
1414
from utils.helpers import validate_url, validate_variables
1515

1616
router = APIRouter()

config/middleware.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Third-party imports
77
from fastapi import FastAPI, Request
88
from fastapi.middleware.cors import CORSMiddleware
9-
from slowapi.middleware import SlowAPIMiddleware
109

1110
# Local imports
1211
from services.globe import process_request_for_globe

services/globe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
retrieves geolocation information, and publishes the data to a PubSub topic.
66
"""
77

8+
import hashlib
89
import json
9-
import time
1010
import os
11-
import hashlib
11+
import time
12+
from typing import Any, Dict, Optional
13+
1214
import httpx
13-
from typing import Dict, Any, Optional
1415
from google.cloud import pubsub_v1
1516

1617
# Initialize PubSub constants

services/send_email.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
# Third-party imports
1313
import httpx
14-
import requests
1514
from fastapi import HTTPException
1615

1716
# Mailjet configuration

0 commit comments

Comments
 (0)