Skip to content

Commit f51e783

Browse files
committed
Prepare for production deployment
1 parent 64c8a51 commit f51e783

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

functions/host-info/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
2-
# The following two lines are necessary to import utils
3-
import sys
4-
sys.path.append('../')
52
from utils import validate_host_id, format_error_response
63
from logging import Logger
74
from typing import Dict

functions/user-management/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
2-
# The following two lines are necessary to import utils
3-
import sys
4-
sys.path.append('../')
52
from utils import validate_email, format_error_response
63
from logging import Logger
74
from typing import Dict

functions/user-management/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
import json
3+
from typing import Dict, Any, Optional, Union, List
4+
from falconfoundry import FoundryAPIError
5+
6+
def validate_host_id(host_id: str) -> bool:
7+
"""Validate that a host ID is in the correct format."""
8+
if not host_id or not isinstance(host_id, str):
9+
return False
10+
return len(host_id) == 32 and all(c in '0123456789abcdef' for c in host_id.lower())
11+
12+
def validate_email(email: str) -> bool:
13+
"""Validate email format."""
14+
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
15+
return bool(re.match(pattern, email))
16+
17+
def format_error_response(message: str, code: int = 400) -> list[Any]:
18+
"""Create a standardized error response."""
19+
return [FoundryAPIError(code=code, message=message)]
20+
21+
def safe_json_parse(data: str) -> Optional[Dict[str, Any]]:
22+
"""Safely parse JSON data."""
23+
try:
24+
return json.loads(data)
25+
except (json.JSONDecodeError, TypeError):
26+
return None

0 commit comments

Comments
 (0)