Skip to content

Commit

Permalink
download with urn
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Aug 24, 2024
1 parent c646f4f commit 8ed119c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion fabrictestbed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.7.3b0"
__version__ = "1.7.3b1"
__VERSION__ = __version__
35 changes: 18 additions & 17 deletions fabrictestbed/fabric_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def upload_file_to_artifact(self, file_to_upload: str, artifact_id: str = None,
raise FabricManagerException(error_message)

def download_artifact(self, download_dir: str, artifact_id: str = None, artifact_title: str = None,
version: str = None):
version: str = None, version_urn: str = None):
"""
Download an artifact to a specified directory.
Expand All @@ -363,28 +363,29 @@ def download_artifact(self, download_dir: str, artifact_id: str = None, artifact
:param artifact_id: The unique identifier of the artifact to download.
:param artifact_title: The title of the artifact to download.
:param version: The specific version of the artifact to download (optional).
:param version_urn: Version urn for the artifact.
:return: The path to the downloaded artifact.
:raises ValueError: If neither `artifact_id` nor `artifact_title` is provided.
:raises FabricManagerException: If an error occurs during the download process.
"""
if artifact_id is None and artifact_title is None:
raise ValueError("Either artifact_id or artifact_title must be specified!")
if artifact_id is None and artifact_title is None and version_urn:
raise ValueError("Either artifact_id, artifact_title or version_urn must be specified!")
try:
am_proxy = ArtifactManager(api_url=self.am_host, token=self.ensure_valid_token())
artifact = self.get_artifact(artifact_id=artifact_id, artifact_title=artifact_title)
artifact_urn = None
for v in artifact.get("versions"):
if not version:
version = v.get("version")
artifact_urn = v.get("urn")
break
if version in v:
artifact_urn = v.get("urn")
break
if not artifact_urn:
raise ValueError(f"Requested version: {version} not found for the artifact: "
f"{artifact_id}/{artifact_title}!")
return am_proxy.download_artifact(urn=artifact_urn, download_dir=download_dir, version=version)
if not version_urn:
artifact = self.get_artifact(artifact_id=artifact_id, artifact_title=artifact_title)
for v in artifact.get("versions"):
if not version:
version = v.get("version")
version_urn = v.get("urn")
break
if version in v:
version_urn = v.get("urn")
break
if not version_urn:
raise ValueError(f"Requested artifact: {artifact_id}/{artifact_title} with {version}/{version_urn} "
f"can not be found!")
return am_proxy.download_artifact(urn=version_urn, download_dir=download_dir, version=version)
except Exception as e:
error_message = Utils.extract_error_message(exception=e)
raise FabricManagerException(error_message)

0 comments on commit 8ed119c

Please sign in to comment.