Skip to content

Commit 8e4897d

Browse files
committed
code review, use ANVIL_HOSTS everywhere
1 parent 2d05029 commit 8e4897d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

python_anvil/api_resources/requests.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from python_anvil.http import HTTPClient
44

5+
from constants import VALID_HOSTS
6+
57

68
class AnvilRequest:
79
show_headers = False
@@ -166,18 +168,13 @@ def get_url(self):
166168
class FullyQualifiedRequest(BaseAnvilHttpRequest):
167169
"""A request class that validates URLs point to Anvil domains."""
168170

169-
VALID_HOSTS = [
170-
"https://app.useanvil.com",
171-
# Future Anvil specific URLs
172-
]
173-
174171
def get_url(self):
175172
return "" # Not used since we expect full URLs
176173

177174
def _validate_url(self, url):
178-
if not any(url.startswith(host) for host in self.VALID_HOSTS):
175+
if not any(url.startswith(host) for host in VALID_HOSTS):
179176
raise ValueError(
180-
f"URL must start with one of: {', '.join(self.VALID_HOSTS)}"
177+
f"URL must start with one of: {', '.join(VALID_HOSTS)}"
181178
)
182179

183180
def get(self, url, params=None, **kwargs):

python_anvil/constants.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"""Basic constants used in the library."""
22

33
GRAPHQL_ENDPOINT: str = "https://graphql.useanvil.com"
4-
REST_ENDPOINT = "https://app.useanvil.com/api/v1/"
4+
REST_ENDPOINT = "https://app.useanvil.com/api/v1"
5+
ANVIL_HOST = "https://app.useanvil.com"
6+
7+
VALID_HOSTS = [
8+
ANVIL_HOST,
9+
REST_ENDPOINT,
10+
GRAPHQL_ENDPOINT,
11+
]
512

613
RETRIES_LIMIT = 5
714
REQUESTS_LIMIT = {

python_anvil/tests/test_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ..api_resources.payload import FillPDFPayload
1414
from . import payloads
15+
from constants import VALID_HOSTS
1516

1617

1718
DEV_KEY = "MY-SECRET-KEY"
@@ -403,7 +404,7 @@ def describe_rest_request_absolute_url_behavior():
403404
[
404405
("some/relative/path", True),
405406
("https://external.example.com/full/path/file.pdf", True),
406-
("https://app.useanvil.com/api/v1/some-endpoint", False),
407+
*[(host + "/some-endpoint", False) for host in VALID_HOSTS],
407408
],
408409
)
409410
@mock.patch("python_anvil.api_resources.requests.AnvilRequest._request")
@@ -431,7 +432,7 @@ def test_get_behavior(mock_request, anvil, url, should_raise):
431432
[
432433
("some/relative/path", True),
433434
("https://external.example.com/full/path/file.pdf", True),
434-
("https://app.useanvil.com/api/v1/some-endpoint", False),
435+
*[(host + "/some-endpoint", False) for host in VALID_HOSTS],
435436
],
436437
)
437438
@mock.patch("python_anvil.api_resources.requests.AnvilRequest._request")

0 commit comments

Comments
 (0)