diff --git a/supabase_functions/_async/functions_client.py b/supabase_functions/_async/functions_client.py index 4a037f9..aa66842 100644 --- a/supabase_functions/_async/functions_client.py +++ b/supabase_functions/_async/functions_client.py @@ -3,7 +3,7 @@ from httpx import HTTPError, Response from ..errors import FunctionsHttpError, FunctionsRelayError -from ..utils import AsyncClient +from ..utils import AsyncClient, is_http_url, is_valid_str_arg from ..version import __version__ @@ -16,6 +16,8 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): + if not is_http_url(url): + ValueError("url must be a valid HTTP URL string") self.url = url self.headers = { "User-Agent": f"supabase-py/functions-py v{__version__}", @@ -25,7 +27,7 @@ def __init__( base_url=self.url, headers=self.headers, verify=bool(verify), - timeout=timeout, + timeout=int(abs(timeout)), proxy=proxy, follow_redirects=True, http2=True, @@ -73,6 +75,8 @@ async def invoke( `body`: the body of the request `responseType`: how the response should be parsed. The default is `json` """ + if not is_valid_str_arg(function_name): + raise ValueError("function_name must a valid string value.") headers = self.headers body = None response_type = "text/plain" diff --git a/supabase_functions/_sync/functions_client.py b/supabase_functions/_sync/functions_client.py index 3550219..b407a5f 100644 --- a/supabase_functions/_sync/functions_client.py +++ b/supabase_functions/_sync/functions_client.py @@ -3,7 +3,7 @@ from httpx import HTTPError, Response from ..errors import FunctionsHttpError, FunctionsRelayError -from ..utils import SyncClient +from ..utils import SyncClient, is_http_url, is_valid_str_arg from ..version import __version__ @@ -16,6 +16,8 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): + if not is_http_url(url): + ValueError("url must be a valid HTTP URL string") self.url = url self.headers = { "User-Agent": f"supabase-py/functions-py v{__version__}", @@ -25,7 +27,7 @@ def __init__( base_url=self.url, headers=self.headers, verify=bool(verify), - timeout=timeout, + timeout=int(abs(timeout)), proxy=proxy, follow_redirects=True, http2=True, @@ -73,6 +75,8 @@ def invoke( `body`: the body of the request `responseType`: how the response should be parsed. The default is `json` """ + if not is_valid_str_arg(function_name): + raise ValueError("function_name must a valid string value.") headers = self.headers body = None response_type = "text/plain" diff --git a/supabase_functions/utils.py b/supabase_functions/utils.py index 46005dc..1f8b969 100644 --- a/supabase_functions/utils.py +++ b/supabase_functions/utils.py @@ -1,3 +1,5 @@ +from urllib.parse import urlparse + from httpx import AsyncClient as AsyncClient # noqa: F401 from httpx import Client as BaseClient @@ -7,3 +9,11 @@ class SyncClient(BaseClient): def aclose(self) -> None: self.close() + + +def is_valid_str_arg(target: str) -> bool: + return isinstance(target, str) and len(target.strip()) > 0 + + +def is_http_url(url: str) -> bool: + return urlparse(url).scheme in {"https", "http"}