14
14
logger = logging .getLogger (__name__ )
15
15
16
16
17
- def build_collection_uri (collection : str , version : str ) -> str :
17
+ def build_collection_uri (collection_name : str , version : str ) -> str :
18
18
"""
19
19
Builds the full URI for a given collection and version.
20
20
21
21
Args:
22
- collection (str): The collection name.
22
+ collection_name (str): The collection name.
23
23
version (str): The version string.
24
24
25
25
Returns:
26
26
str: The full URI to the collection artifact.
27
27
"""
28
+ collection = collection_name .replace ("." , "-" )
28
29
path = "/api/galaxy/v3/plugin/ansible/content/published/collections/artifacts"
29
30
filename = f"{ collection } -{ version } .tar.gz"
30
31
31
- print ("Filename" , filename )
32
-
33
32
return urljoin (f"{ settings .AAP_URL } /" , f"{ path } /{ filename } " )
34
33
35
34
@@ -47,11 +46,10 @@ def download_collection(collection_name: str, version: str) -> Iterator[str]:
47
46
The path to the extracted collection files.
48
47
"""
49
48
response = None
50
- collection = collection_name .replace ("." , "-" )
51
49
temp_base_dir = tempfile .mkdtemp ()
52
- collection_path = os .path .join (temp_base_dir , f"{ collection } -{ version } " )
50
+ collection_path = os .path .join (temp_base_dir , f"{ collection_name } -{ version } " )
53
51
os .makedirs (collection_path , exist_ok = True )
54
- path = build_collection_uri (collection , version )
52
+ path = build_collection_uri (collection_name , version )
55
53
56
54
try :
57
55
response = get (path )
@@ -62,4 +60,6 @@ def download_collection(collection_name: str, version: str) -> Iterator[str]:
62
60
logger .info (f"Collection extracted to { collection_path } " )
63
61
yield collection_path # Yield the path to the caller
64
62
finally :
63
+ if response :
64
+ response .close () # Explicitly close the response object
65
65
shutil .rmtree (temp_base_dir )
0 commit comments