forked from pulp/pulpcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 7818847: Adding the support for uploading deb source packages
This PR adds the initial support for deb source packages, only the support for uploading and listing the sources packages is added in this PR, A later PR will add the support for publishing source packages. This PR is based on the [upstream PR](pulp/pulp_deb#295), Creating a patch based on the changes, and adding the patch to our docker container image. Here's a few examples of how the ccli can be used to manipulate source packages: ``` - pmc package upload ../../hello_sources/hello_2.10-2ubuntu2.dsc --source-artifact ../../hello_sources/ - pmc package deb_src list - pmc package show --details content-deb-source_packages-f63f0696-919d-41e2-b023-fd7c9c995b19 ``` A later PR will update the documentation, once we have the other part of the changes merged. Related work items: #13082573
- Loading branch information
1 parent
4bbc45e
commit ccd3a24
Showing
17 changed files
with
1,886 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import re | ||
from concurrent.futures import ThreadPoolExecutor, as_completed | ||
from pathlib import Path | ||
from typing import Any, Dict, Iterable, List, Optional | ||
|
||
import httpx | ||
from click import BadParameter | ||
from pydantic import AnyHttpUrl, ValidationError, parse_obj_as | ||
|
||
from pmc.client import client, client_context, create_client | ||
from pmc.context import PMCContext | ||
from pmc.utils import PulpTaskFailure | ||
|
||
SHA256_REGEX = r"?P<sha256>[a-fA-F0-9]{64}" | ||
ARTIFACT_EXISTS_ERROR = rf"Artifact with sha256 checksum of '{SHA256_REGEX}' already exists." | ||
|
||
|
||
class ArtifactUploader: | ||
def __init__( | ||
self, | ||
context: PMCContext, | ||
path_or_url: str, | ||
): | ||
self.context = context | ||
|
||
try: | ||
self.url = parse_obj_as(AnyHttpUrl, path_or_url) | ||
except ValidationError: | ||
self.url = None | ||
self.path = Path(path_or_url) | ||
if not self.path.is_file() and not self.path.is_dir(): | ||
raise BadParameter( | ||
f"Invalid url or non-existent file/directory for artifact {self.path}." | ||
) | ||
|
||
def _build_data(self) -> Dict[str, Any]: | ||
"""Build data dict for uploading artifact(s).""" | ||
data: Dict[str, Any] = {} | ||
|
||
if self.url: | ||
data["url"] = self.url | ||
|
||
return data | ||
|
||
def _find_existing_artifact(self, error_resp: Any) -> Any: | ||
"""Attempt to find the existing artifact if it exists""" | ||
error = error_resp.get("detail") | ||
|
||
if match := re.search(ARTIFACT_EXISTS_ERROR, error["non_field_errors"]): | ||
resp = client.get("/artifacts/", params=match.groupdict()) | ||
results = resp.json()["results"] | ||
if len(results) == 1: | ||
return results[0] | ||
|
||
raise KeyError() | ||
|
||
def _upload_artifact(self, data: Dict[str, Any], path: Optional[Path] = None) -> Any: | ||
if path: | ||
files = {"file": open(path, "rb")} | ||
else: | ||
files = None | ||
|
||
# upload the artifact | ||
resp = client.post("/artifacts/", params=data, files=files) | ||
resp_json = resp.json() | ||
|
||
if not httpx.codes.is_success(resp.status_code): | ||
try: | ||
return self._find_existing_artifact(resp) | ||
except KeyError: | ||
# we're not dealing with a failure due to an existing artifact | ||
raise PulpTaskFailure( | ||
{ | ||
"error": { | ||
"traceback": resp_json["command_traceback"], | ||
"description": resp_json["message"], | ||
} | ||
} | ||
) | ||
|
||
return resp_json | ||
|
||
def _upload_artifacts( | ||
self, data: Dict[str, Any], paths: Iterable[Path] = [] | ||
) -> List[Dict[str, Any]]: | ||
def set_context(context: PMCContext) -> None: | ||
client_context.set(create_client(context)) | ||
|
||
artifacts = [] | ||
with ThreadPoolExecutor( | ||
max_workers=5, initializer=set_context, initargs=(self.context,) | ||
) as executor: | ||
futures = [executor.submit(self._upload_artifact, data, path) for path in paths] | ||
for future in as_completed(futures): | ||
artifacts.append(future.result()) | ||
|
||
return artifacts | ||
|
||
def upload(self) -> List[Dict[str, Any]]: | ||
"""Perform the upload.""" | ||
data = self._build_data() | ||
|
||
if self.url: | ||
return [self._upload_artifact(data)] | ||
elif self.path.is_dir(): | ||
return self._upload_artifacts(data, self.path.glob("*")) | ||
else: | ||
return [self._upload_artifact(data, self.path)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-----BEGIN PGP SIGNED MESSAGE----- | ||
Hash: SHA512 | ||
|
||
Format: 3.0 (quilt) | ||
Source: hello | ||
Binary: hello | ||
Architecture: any | ||
Version: 2.10-2ubuntu2 | ||
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
Homepage: http://www.gnu.org/software/hello/ | ||
Standards-Version: 4.3.0 | ||
Testsuite: autopkgtest | ||
Build-Depends: debhelper-compat (= 9) | ||
Package-List: | ||
hello deb devel optional arch=any | ||
Checksums-Sha1: | ||
f7bebf6f9c62a2295e889f66e05ce9bfaed9ace3 725946 hello_2.10.orig.tar.gz | ||
560b84044b18d69dda0ad03e8e3792d6c571b763 6560 hello_2.10-2ubuntu2.debian.tar.xz | ||
Checksums-Sha256: | ||
31e066137a962676e89f69d1b65382de95a7ef7d914b8cb956f41ea72e0f516b 725946 hello_2.10.orig.tar.gz | ||
2ae08bfe430c90986e74afbffdc7f98d1920527fd292963a567cb8c29d645b07 6560 hello_2.10-2ubuntu2.debian.tar.xz | ||
Files: | ||
6cd0ffea3884a4e79330338dcc2987d6 725946 hello_2.10.orig.tar.gz | ||
446c355fd690fbebb49bdd51eeec6f6f 6560 hello_2.10-2ubuntu2.debian.tar.xz | ||
Original-Maintainer: Santiago Vila <sanvila@debian.org> | ||
|
||
-----BEGIN PGP SIGNATURE----- | ||
|
||
iQJOBAEBCgA4FiEErEg/aN5yj0PyIC/KVo0w8yGyEz0FAlzmJ0caHHN0ZXZlLmxh | ||
bmdhc2VrQHVidW50dS5jb20ACgkQVo0w8yGyEz2rkxAAg+yJexJtgzKhXiAqYTHW | ||
9Us3VMVicCzxDJbeJN11J45Bx1d1L3m+pCHgDpyFnYGJDCuaABRE3HUURIOWbEVX | ||
Zd5Jns6Aj28wIXPj35ju9swb5K7rghYnHJ++QViwaRDcB+KrEJyRprevDTBA37b7 | ||
KwYfY/hE7ZD8sMYeWHq5Ao814umOpNh7ruw2Jpc4GOcHEpcpt23cFLPKGumWVtWQ | ||
PNvYg94yId8J8fcF2NTrp681i0QXmtCIT53d7HLpyBlXcA8IlrpSRBTpcwXnIUAv | ||
MGTwYFQSEWYUw57H4XGzhJU1jGti5YgtIk78tce3r9m14oshVKXVJ0WsT1YZBAiY | ||
ngFg7yb1jREMf+uNgCZZXFbXLMndyGoZls6UywvyoEQOiCMDCb7eeaXN2qrcRWpu | ||
tF3p+alC2HAxWsgvv9A2pvhB86YMqDiOGs6+V4KuUleQpWhIlGQEIsasNqtVPKi0 | ||
64r1DwEbPYGJ28KSQd4YQEBYy1tcaiqwymfsdkDKD/a2xXCpMAFmJp35guLuezcs | ||
RhiKEBkcW4i7nLLfW35N6zsMoL0kLC3GDmglQW4klFnMM+bqs909kXG3J41E9N9J | ||
d9k+0doufnui6P/SxYlAmMpf7tkaAZAk0nXaC6/Hem9fDSqa6dP+mcZjzUZ+D9Jg | ||
JMZ93pTsFDrozldams1rDKM= | ||
=xqJQ | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.