Skip to content

Commit 6dcb527

Browse files
committed
Fix: Curl manifest can be impacted by rate based WAF rules (DataBiosphere/azul-private#125, PR #5808)
2 parents 24d67f9 + 7f4caff commit 6dcb527

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

src/azul/service/manifest_service.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,12 @@ def command_lines(cls,
13971397
else ()
13981398
)
13991399
]
1400+
file_options = [
1401+
'--fail-early', # Exit curl with error on the first failure encountered
1402+
'--continue-at -', # Resume partially downloaded files
1403+
'--retry 2', # Retry a file download up to X times on transient error
1404+
'--retry-delay 10', # Sleep for X seconds between retries
1405+
]
14001406
return {
14011407
'cmd.exe': ' '.join([
14021408
'curl.exe',
@@ -1405,6 +1411,7 @@ def command_lines(cls,
14051411
'|',
14061412
'curl.exe',
14071413
*authentication_option,
1414+
*file_options,
14081415
'--config',
14091416
'-'
14101417
]),
@@ -1415,6 +1422,7 @@ def command_lines(cls,
14151422
'|',
14161423
'curl',
14171424
*authentication_option,
1425+
*file_options,
14181426
'--config',
14191427
'-'
14201428
])
@@ -1480,10 +1488,6 @@ def _write(file: JSON, is_related_file: bool = False):
14801488
'--location', # Follow redirects
14811489
'--globoff', # Prevent '#' in file names from being interpreted as output variables
14821490
'--fail', # Upon server error don't save the error message to the file
1483-
'--fail-early', # Exit curl with error on the first failure encountered
1484-
'--continue-at -', # Resume partially downloaded files
1485-
'--retry 2', # Retry a file download up to X times on transient error
1486-
'--retry-delay 10', # Sleep for X seconds between retries
14871491
'--write-out "Downloading to: %{filename_effective}\\n\\n"'
14881492
]
14891493
output.write('\n\n'.join(curl_options))

terraform/api_gateway.tf.json.template.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,17 @@ def for_domain(cls, domain):
223223
'priority': 1,
224224
'name': config.waf_rate_rule_name,
225225
'action': {
226-
'block': {}
226+
'block': {
227+
'custom_response': {
228+
'response_code': 429,
229+
'response_header': [
230+
{
231+
'name': 'Retry-After',
232+
'value': '10'
233+
}
234+
]
235+
}
236+
}
227237
},
228238
'statement': {
229239
'rate_based_statement': {

test/service/test_manifest.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,14 +1195,6 @@ def test_curl_manifest(self):
11951195
'',
11961196
'--fail',
11971197
'',
1198-
'--fail-early',
1199-
'',
1200-
'--continue-at -',
1201-
'',
1202-
'--retry 2',
1203-
'',
1204-
'--retry-delay 10',
1205-
'',
12061198
'--write-out "Downloading to: %{filename_effective}\\n\\n"',
12071199
'',
12081200
]
@@ -1496,10 +1488,13 @@ def test(*, format: ManifestFormat, fetch: bool, url: Optional[furl] = None):
14961488
expected_url = object_url
14971489
expected_url_for_bash = f"'{expected_url}'"
14981490
if format is ManifestFormat.curl:
1499-
options = "--location --fail"
1491+
manifest_options = '--location --fail'
1492+
file_options = '--fail-early --continue-at - --retry 2 --retry-delay 10'
15001493
expected = {
1501-
'cmd.exe': f'curl.exe {options} "{expected_url}" | curl.exe --config -',
1502-
'bash': f'curl {options} {expected_url_for_bash} | curl --config -'
1494+
'cmd.exe': f'curl.exe {manifest_options} "{expected_url}"'
1495+
f' | curl.exe {file_options} --config -',
1496+
'bash': f'curl {manifest_options} {expected_url_for_bash}'
1497+
f' | curl {file_options} --config -'
15031498
}
15041499
else:
15051500
if format is ManifestFormat.terra_bdbag:

0 commit comments

Comments
 (0)