From 1a5c48d4e35c8c699869c9bd1816bd936eb9d1a4 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 22:24:11 -0300 Subject: [PATCH 1/8] feat: Check if url arg is an HTTP URL --- supabase_functions/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/supabase_functions/utils.py b/supabase_functions/utils.py index 46005dc..a69f089 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_https_url(url: str) -> bool: + return urlparse(url).scheme == "https" From 3fd4638b2d8079e1d4df021ee8a5d43dfa51ec3c Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 22:24:31 -0300 Subject: [PATCH 2/8] feat: Check if url arg is an HTTP URL --- supabase_functions/_sync/functions_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/supabase_functions/_sync/functions_client.py b/supabase_functions/_sync/functions_client.py index 3550219..260ea71 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_valid_str_arg, is_https_url from ..version import __version__ @@ -16,6 +16,8 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): + if not is_https_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" From bbb38489b27b674581cee83b90a1a2383258a5e0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 22:24:43 -0300 Subject: [PATCH 3/8] feat: Check if url arg is an HTTP URL --- supabase_functions/_async/functions_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/supabase_functions/_async/functions_client.py b/supabase_functions/_async/functions_client.py index 4a037f9..985b9ad 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_valid_str_arg, is_https_url from ..version import __version__ @@ -16,6 +16,8 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): + if not is_https_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" From 5e502e05d293a1b5a2a3591976254c93295116ed Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 22:34:41 -0300 Subject: [PATCH 4/8] fix: style --- supabase_functions/_async/functions_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase_functions/_async/functions_client.py b/supabase_functions/_async/functions_client.py index 985b9ad..c463de3 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, is_valid_str_arg, is_https_url +from ..utils import AsyncClient, is_https_url, is_valid_str_arg from ..version import __version__ From 65ed616e03324b4f2aa3d137211a0fe5d9de4b17 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 22:34:54 -0300 Subject: [PATCH 5/8] fix: style --- supabase_functions/_sync/functions_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase_functions/_sync/functions_client.py b/supabase_functions/_sync/functions_client.py index 260ea71..02deef4 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, is_valid_str_arg, is_https_url +from ..utils import SyncClient, is_https_url, is_valid_str_arg from ..version import __version__ From 86936f5d6e9ec26b9e3ec17cf0de55014234f5e2 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 23:12:20 -0300 Subject: [PATCH 6/8] feat: Check if url arg is an HTTP URL --- supabase_functions/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supabase_functions/utils.py b/supabase_functions/utils.py index a69f089..1f8b969 100644 --- a/supabase_functions/utils.py +++ b/supabase_functions/utils.py @@ -15,5 +15,5 @@ def is_valid_str_arg(target: str) -> bool: return isinstance(target, str) and len(target.strip()) > 0 -def is_https_url(url: str) -> bool: - return urlparse(url).scheme == "https" +def is_http_url(url: str) -> bool: + return urlparse(url).scheme in {"https", "http"} From 2dab27bb1a2fd7b5968e74316dd6fe09f77e9b1f Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 23:12:28 -0300 Subject: [PATCH 7/8] feat: Check if url arg is an HTTP URL --- supabase_functions/_sync/functions_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supabase_functions/_sync/functions_client.py b/supabase_functions/_sync/functions_client.py index 02deef4..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, is_https_url, is_valid_str_arg +from ..utils import SyncClient, is_http_url, is_valid_str_arg from ..version import __version__ @@ -16,7 +16,7 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): - if not is_https_url(url): + if not is_http_url(url): ValueError("url must be a valid HTTP URL string") self.url = url self.headers = { From 10d400288da4470c442599fd9a20af88bd6ada5b Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 28 Oct 2024 23:12:36 -0300 Subject: [PATCH 8/8] feat: Check if url arg is an HTTP URL --- supabase_functions/_async/functions_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supabase_functions/_async/functions_client.py b/supabase_functions/_async/functions_client.py index c463de3..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, is_https_url, is_valid_str_arg +from ..utils import AsyncClient, is_http_url, is_valid_str_arg from ..version import __version__ @@ -16,7 +16,7 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ): - if not is_https_url(url): + if not is_http_url(url): ValueError("url must be a valid HTTP URL string") self.url = url self.headers = {