File tree 1 file changed +10
-17
lines changed
1 file changed +10
-17
lines changed Original file line number Diff line number Diff line change 2
2
dataclass ,
3
3
)
4
4
import importlib
5
- from itertools import (
6
- chain ,
7
- )
8
5
import json
9
6
import logging
10
7
@@ -119,19 +116,17 @@ def check_waf_rules(rules: JSONs) -> JSONs:
119
116
return rules
120
117
121
118
122
- def user_ip () -> str :
119
+ def public_ip () -> str :
123
120
"""
124
- Return the user's public IP address in CIDR notation .
121
+ Return the public IPv4 address of the machine running this code .
125
122
"""
126
123
url = 'https://checkip.amazonaws.com'
127
124
http = http_client (log )
128
125
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
135
130
136
131
137
132
zones_by_domain = {
@@ -263,15 +258,13 @@ def user_ip() -> str:
263
258
'name' : config .qualified_resource_name ('it_v4_ips' ),
264
259
'scope' : 'REGIONAL' ,
265
260
'ip_address_version' : 'IPV4' ,
266
- 'addresses' : list (chain (
267
- [
261
+ 'addresses' : [
262
+ public_ip () + '/32' ,
263
+ * [
268
264
f'${{data.aws_nat_gateway.gitlab_{ zone } .public_ip}}/32'
269
265
for zone in range (vpc .num_zones )
270
- ],
271
- [
272
- user_ip (),
273
266
]
274
- ))
267
+ ]
275
268
}
276
269
},
277
270
'aws_wafv2_web_acl' : {
You can’t perform that action at this time.
0 commit comments