Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

make invalid AZCOPY environment variables more clear #1061

Merged
merged 4 commits into from
Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/cli/onefuzz/azcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
import subprocess # nosec


def azcopy_sync(src: str, dst: str) -> None:
"""Expose azcopy for uploading/downloading files"""
def find_azcopy() -> str:
azcopy = os.environ.get("AZCOPY")

if azcopy:
if not os.path.exists(azcopy):
raise Exception(f"AZCOPY environment variable is invalid: {azcopy}")
else:
azcopy = shutil.which("azcopy")

azcopy = os.environ.get("AZCOPY") or shutil.which("azcopy")
if not azcopy:
raise Exception(
"unable to find 'azcopy' in path or AZCOPY environment variable"
)

return azcopy


def azcopy_sync(src: str, dst: str) -> None:
"""Expose azcopy for uploading/downloading files"""

azcopy = find_azcopy()

# security note: callers need to understand the src/dst for this.
subprocess.check_output([azcopy, "sync", src, dst, "--recursive=true"]) # nosec