curl/curl_output: allow redacting secrets in the log

Add a new argument `secrets` to specify secret tokens, so we can redact them in the log.
This commit is contained in:
Cheng XU 2019-07-13 23:31:56 +08:00
parent 1d957c2029
commit 739c06229d
No known key found for this signature in database
GPG Key ID: B19F15830AB4E690

View File

@ -42,13 +42,14 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
args + extra_args args + extra_args
end end
def curl(*args) def curl(*args, secrets: [], **options)
# SSL_CERT_FILE can be incorrectly set by users or portable-ruby and screw # SSL_CERT_FILE can be incorrectly set by users or portable-ruby and screw
# with SSL downloads so unset it here. # with SSL downloads so unset it here.
system_command! curl_executable, system_command! curl_executable,
args: curl_args(*args), args: curl_args(*args, **options),
print_stdout: true, print_stdout: true,
env: { "SSL_CERT_FILE" => nil } env: { "SSL_CERT_FILE" => nil },
secrets: secrets
end end
def curl_download(*args, to: nil, **options) def curl_download(*args, to: nil, **options)
@ -77,10 +78,11 @@ def curl_download(*args, to: nil, **options)
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options) curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options)
end end
def curl_output(*args, **options) def curl_output(*args, secrets: [], **options)
system_command(curl_executable, system_command curl_executable,
args: curl_args(*args, show_output: true, **options), args: curl_args(*args, show_output: true, **options),
print_stderr: false) print_stderr: false,
secrets: secrets
end end
def curl_check_http_content(url, user_agents: [:default], check_content: false, strict: false) def curl_check_http_content(url, user_agents: [:default], check_content: false, strict: false)