Skip to content

Commit b9cc431

Browse files
authored
Merge pull request #199 from aslheyrr/master
Pass the artifacts checksums in the headers of the deploy request
2 parents 320a00c + c6b705d commit b9cc431

4 files changed

Lines changed: 27 additions & 20 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This library enables you to manage Artifactory resources such as users, groups,
3333
+ [Get the information about a file or folder](#get-the-information-about-a-file-or-folder)
3434
+ [Deploy an artifact](#deploy-an-artifact)
3535
+ [Deploy an artifact with properties](#deploy-an-artifact-with-properties)
36-
+ [Deploy an artifact with checksums](#deploy-an-artifact-with-checksums)
36+
+ [Deploy an artifact by checksums](#deploy-an-artifact-by-checksums)
3737
+ [Download an artifact](#download-an-artifact)
3838
+ [Retrieve artifact list](#retrieve-artifact-list)
3939
+ [Retrieve artifact properties](#retrieve-artifact-properties)
@@ -424,7 +424,7 @@ artifact = art.artifacts.deploy("<LOCAL_FILE_LOCATION>", "<ARTIFACT_PATH_IN_ARTI
424424
# artifact = art.artifacts.deploy("Desktop/myNewFile.txt", "my-repository/my/new/artifact/directory/file.txt", {"retention": ["30"]})
425425
```
426426

427-
#### Deploy an artifact with checksums
427+
#### Deploy an artifact by checksums
428428

429429
```python
430430
artifact = art.artifacts.deploy("<LOCAL_FILE_LOCATION>", "<ARTIFACT_PATH_IN_ARTIFACTORY>", checksum_enabled=True)

pyartifactory/models/artifact.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class OriginalChecksums(BaseModel):
4040
"""Models original checksums."""
4141

4242
sha256: str
43+
sha1: str
44+
md5: str
4345

4446

4547
class Child(BaseModel):

pyartifactory/objects/artifact.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,22 @@ def deploy(
9898
for file in files:
9999
self.deploy(Path(f"{root}/{file}"), Path(f"{new_root}/{file}"), properties, checksum_enabled)
100100
else:
101+
properties_param_str = ""
102+
if properties is not None:
103+
properties_param_str = ";".join(f"{k}={value}" for k, values in properties.items() for value in values)
104+
route = ";".join(s for s in [artifact_folder.as_posix(), properties_param_str] if s)
105+
artifact_check_sums = Checksums.generate(local_file)
106+
headers = {
107+
"X-Checksum-Sha1": artifact_check_sums.sha1,
108+
"X-Checksum-Sha256": artifact_check_sums.sha256,
109+
"X-Checksum": artifact_check_sums.md5,
110+
}
101111
if checksum_enabled:
102-
artifact_check_sums = Checksums.generate(local_file)
112+
headers["X-Checksum-Deploy"] = "true"
103113
try:
104114
self._put(
105-
route=artifact_folder.as_posix(),
106-
headers={
107-
"X-Checksum-Deploy": "true",
108-
"X-Checksum-Sha1": artifact_check_sums.sha1,
109-
"X-Checksum-Sha256": artifact_check_sums.sha256,
110-
"X-Checksum": artifact_check_sums.md5,
111-
},
115+
route=route,
116+
headers=headers,
112117
)
113118
except requests.exceptions.HTTPError as error:
114119
if error.response.status_code == 404:
@@ -120,12 +125,9 @@ def deploy(
120125
raise ArtifactNotFoundError(message)
121126
raise ArtifactoryError from error
122127
else:
128+
headers["X-Checksum-Deploy"] = "false"
123129
with local_file.open("rb") as stream:
124-
properties_param_str = ""
125-
if properties is not None:
126-
properties_param_str = self._format_properties(properties)
127-
route = ";".join(s for s in [artifact_folder.as_posix(), properties_param_str] if s)
128-
self._put(route, data=stream)
130+
self._put(route=route, headers=headers, data=stream)
129131

130132
logger.debug("Artifact %s successfully deployed", local_file)
131133
return self.info(artifact_folder)

tests/test_artifacts.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
"md5": "4cf609e0fe1267df8815bc650f5851e9",
7777
"sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858",
7878
},
79-
"originalChecksums": {"sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858"},
79+
"originalChecksums": {
80+
"sha1": "962c287c760e03b03c17eb920f5358d05f44dd3b",
81+
"md5": "4cf609e0fe1267df8815bc650f5851e9",
82+
"sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858",
83+
},
8084
"uri": f"{URL}/api/storage/{ARTIFACT_PATH}",
8185
}
8286
FILE_INFO = ArtifactFileInfoResponse(**FILE_INFO_RESPONSE)
@@ -460,10 +464,9 @@ def test_deploy_artifact_with_properties_success():
460464

461465
@responses.activate
462466
def test_deploy_artifact_with_multiple_properties_success():
463-
properties_param_str = ""
464-
for k, v in ARTIFACT_MULTIPLE_PROPERTIES.properties.items():
465-
values_str = ",".join(list(map(urllib.parse.quote, v)))
466-
properties_param_str += f"{k}={values_str};"
467+
properties_param_str = ";".join(
468+
f"{k}={value}" for k, values in ARTIFACT_MULTIPLE_PROPERTIES.properties.items() for value in values
469+
)
467470
responses.add(
468471
responses.PUT,
469472
f"{URL}/{ARTIFACT_PATH};{properties_param_str.rstrip(';')}",

0 commit comments

Comments
 (0)