mirror of
https://github.com/splunk/security_content
synced 2026-06-08 17:32:49 +00:00
5762b4e373
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.
23 lines
970 B
Python
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 |