Files
splunk-security_content/bin/docker_detection_tester/modules/utils.py
T
pyth0n1c 5762b4e373 Updated the app baseline as well as
the python code for generating the
default config. Also updated the
print behavior for when files are
downloaded.
App baseline is now current, and
files are hosted on S3, as
of 06/21/2022.
2022-06-21 13:53:26 -07:00

23 lines
970 B
Python

import os
import requests
def download_file_from_http(url:str, destination_file:str, overwrite_file:bool=False, chunk_size:int=1024*1024, verbose_print:bool=False)->None:
if os.path.exists(destination_file) and overwrite_file is False:
print(f"[{destination_file}] already exists...using cached version")
return
if verbose_print:
print(f"downloading to [{destination_file}]...",end="")
try:
file_to_download = requests.get(url, stream=True)
if file_to_download.status_code != 200:
if verbose_print:
print("FAILED")
raise Exception(f"Error downloading the file {url}: Status Code {file_to_download.status_code}")
with open(destination_file, "wb") as output:
for piece in file_to_download.iter_content(chunk_size=chunk_size):
output.write(piece)
except Exception as e:
if verbose_print:
print("FAILED")
raise e