From 07572f9d9f89825d95c7ebb000b1126dc85d4e3e Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Tue, 13 Jul 2021 14:19:39 -0400 Subject: [PATCH 1/2] make invalid AZCOPY environment variables more clear --- src/cli/onefuzz/azcopy.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cli/onefuzz/azcopy.py b/src/cli/onefuzz/azcopy.py index aa46858e87..8a4a3801a8 100644 --- a/src/cli/onefuzz/azcopy.py +++ b/src/cli/onefuzz/azcopy.py @@ -2,15 +2,26 @@ import shutil import subprocess # nosec +def find_azcopy() -> str: + azcopy = os.environ.get("AZCOPY") -def azcopy_sync(src: str, dst: str) -> None: - """Expose azcopy for uploading/downloading files""" + 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 From 54d376d99a802b79ec22af3455703fd8835b6a9f Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Tue, 13 Jul 2021 14:28:24 -0400 Subject: [PATCH 2/2] format --- src/cli/onefuzz/azcopy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/onefuzz/azcopy.py b/src/cli/onefuzz/azcopy.py index 8a4a3801a8..ac2b706d23 100644 --- a/src/cli/onefuzz/azcopy.py +++ b/src/cli/onefuzz/azcopy.py @@ -2,6 +2,7 @@ import shutil import subprocess # nosec + def find_azcopy() -> str: azcopy = os.environ.get("AZCOPY") @@ -18,6 +19,7 @@ def find_azcopy() -> str: return azcopy + def azcopy_sync(src: str, dst: str) -> None: """Expose azcopy for uploading/downloading files"""