Skip to content

Commit a675568

Browse files
committed
fixup! Different rate limits depending on HTTP method (#5555)
1 parent 296a02e commit a675568

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

terraform/api_gateway.tf.json.template.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
dataclass,
33
)
44
import importlib
5-
from itertools import (
6-
chain,
7-
)
85
import json
96
import logging
107

@@ -119,19 +116,17 @@ def check_waf_rules(rules: JSONs) -> JSONs:
119116
return rules
120117

121118

122-
def user_ip() -> str:
119+
def public_ip() -> str:
123120
"""
124-
Return the user's public IP address in CIDR notation.
121+
Return the public IPv4 address of the machine running this code.
125122
"""
126123
url = 'https://checkip.amazonaws.com'
127124
http = http_client(log)
128125
response = http.request('GET', url)
129-
if response.status != 200:
130-
raise RuntimeError('Unexpected response %s' % url, response.status)
131-
else:
132-
ip_address = response.data.decode().strip()
133-
log.info('Determined IP address: %s', ip_address)
134-
return ip_address + '/32'
126+
assert response.status == 200, R('Unexpected response', response)
127+
ip_address = response.data.decode().strip()
128+
log.info('Determined IP address: %s', ip_address)
129+
return ip_address
135130

136131

137132
zones_by_domain = {
@@ -263,15 +258,13 @@ def user_ip() -> str:
263258
'name': config.qualified_resource_name('it_v4_ips'),
264259
'scope': 'REGIONAL',
265260
'ip_address_version': 'IPV4',
266-
'addresses': list(chain(
267-
[
261+
'addresses': [
262+
public_ip() + '/32',
263+
*[
268264
f'${{data.aws_nat_gateway.gitlab_{zone}.public_ip}}/32'
269265
for zone in range(vpc.num_zones)
270-
],
271-
[
272-
user_ip(),
273266
]
274-
))
267+
]
275268
}
276269
},
277270
'aws_wafv2_web_acl': {

0 commit comments

Comments
 (0)