Skip to content

Commit 43ce771

Browse files
committed
fixup! Different rate limits depending on HTTP method (#5555)
1 parent 4a2678e commit 43ce771

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

terraform/api_gateway.tf.json.template.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
dataclass,
33
)
44
import importlib
5+
import ipaddress
56
import json
67
import logging
78

9+
from furl import (
10+
furl,
11+
)
812
from more_itertools import (
913
one,
1014
)
@@ -124,11 +128,15 @@ def public_ip() -> str:
124128
"""
125129
Return the public IPv4 address of the machine running this code.
126130
"""
127-
url = 'https://checkip.amazonaws.com'
131+
url = furl('https://checkip.amazonaws.com')
128132
http = http_client(log)
129-
response = http.request('GET', url)
133+
response = http.request('GET', str(url))
130134
assert response.status == 200, R('Unexpected response', response)
131-
ip_address = response.data.decode().strip()
135+
ip_address = response.data.decode().strip() + '.0'
136+
try:
137+
ipaddress.IPv4Address(ip_address)
138+
except ipaddress.AddressValueError as e:
139+
raise ValueError('Not a valid IPv4 address', ip_address) from e
132140
return ip_address
133141

134142

0 commit comments

Comments
 (0)