-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve package signing plugin integration #19345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop2
Are you sure you want to change the base?
Changes from 23 commits
d5c13c4
eac6b76
05d46b5
861ddca
7ac7ba9
8b599ac
9c8ee75
fbff444
8fa65b1
ce0d59a
e539f0a
2f2037b
2b75511
faea045
97963b7
03d0da6
bb99d7b
f397ae5
0b1e43c
bdb8e25
d76b0df
4645b3d
6ab0545
1ffd6f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,9 @@ | |
| from conan.errors import ConanException | ||
| from conan.api.model import PkgReference | ||
| from conan.api.model import RecipeReference | ||
| from conan.internal.api.uploader import PackagePreparator | ||
| from conan.internal.conan_app import ConanApp | ||
| from conan.internal.rest.pkg_sign import PkgSignaturesPlugin | ||
| from conan.internal.util.dates import revision_timestamp_now | ||
| from conan.internal.util.files import rmdir, mkdir, remove, save | ||
|
|
||
|
|
@@ -77,6 +80,76 @@ def check_integrity(self, package_list): | |
| checker = IntegrityChecker(cache) | ||
| checker.check(package_list) | ||
|
|
||
| def sign(self, package_list): | ||
| """Sign packages with the package signing plugin""" | ||
| cache = PkgCache(self._conan_api.cache_folder, self._api_helpers.global_conf) | ||
| pkg_signer = PkgSignaturesPlugin(cache, self._conan_api.home_folder) | ||
| if not pkg_signer.is_sign_configured: | ||
| raise ConanException( | ||
| "The sign() function in the package sign plugin is not defined. For more " | ||
| "information on how to configure the plugin, please read the documentation at " | ||
| "https://docs.conan.io/2/reference/extensions/package_signing.html.") | ||
| if not package_list.has_items(): | ||
| raise ConanException("No packages to sign in the pkglist provided.") | ||
|
|
||
| app = ConanApp(self._conan_api) | ||
| preparator = PackagePreparator(app, self._api_helpers.global_conf) | ||
| # Some packages can have missing sources/exports_sources | ||
| enabled_remotes = self._conan_api.remotes.list() | ||
| preparator.prepare(package_list, enabled_remotes, force=True) | ||
|
|
||
| for rref, packages in package_list.items(): | ||
| recipe_bundle = package_list.recipe_dict(rref) | ||
| if recipe_bundle: | ||
| rref_folder = cache.recipe_layout(rref).download_export() | ||
| try: | ||
| pkg_signer.sign_pkg(rref, recipe_bundle.get("files", {}), rref_folder) | ||
| except Exception as e: | ||
| recipe_bundle["pkgsign_error"] = str(e) | ||
czoido marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for pref in packages: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both should be signed, as packages cannot be uploaded without their recipe, and the recipe is the proxy to packages, so it makes sense to have both signed |
||
| pkg_bundle = package_list.package_dict(pref) | ||
| if pkg_bundle: | ||
| pref_folder = cache.pkg_layout(pref).download_package() | ||
| try: | ||
| pkg_signer.sign_pkg(pref, pkg_bundle.get("files", {}), pref_folder) | ||
| except Exception as e: | ||
| pkg_bundle["pkgsign_error"] = str(e) | ||
| return package_list | ||
|
|
||
| def verify(self, package_list): | ||
| """Verify packages with the package signing plugin""" | ||
| cache = PkgCache(self._conan_api.cache_folder, self._api_helpers.global_conf) | ||
| pkg_signer = PkgSignaturesPlugin(cache, self._conan_api.home_folder) | ||
| if not pkg_signer.is_verify_configured: | ||
| raise ConanException( | ||
| "The verify() function in the package sign plugin is not defined. For more " | ||
| "information on how to configure the plugin, please read the documentation at " | ||
| "https://docs.conan.io/2/reference/extensions/package_signing.html.") | ||
| if not package_list.has_items(): | ||
| raise ConanException("No packages to verify in the pkglist provided.") | ||
|
|
||
| for rref, packages in package_list.items(): | ||
| recipe_bundle = package_list.recipe_dict(rref) | ||
| if recipe_bundle: | ||
danimtb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rref_folder = cache.recipe_layout(rref).download_export() | ||
| files = {file: os.path.join(rref_folder, file) for file in | ||
| os.listdir(rref_folder) if not file.startswith(METADATA)} | ||
| try: | ||
| pkg_signer.verify(rref, rref_folder, files) | ||
| except Exception as e: | ||
| recipe_bundle["pkgsign_error"] = str(e) | ||
| for pref in packages: | ||
| pkg_bundle = package_list.package_dict(pref) | ||
| if pkg_bundle: | ||
| pref_folder = cache.pkg_layout(pref).download_package() | ||
| files = {file: os.path.join(pref_folder, file) for file in | ||
| os.listdir(pref_folder) if not file.startswith(METADATA)} | ||
| try: | ||
| pkg_signer.verify(pref, pref_folder, files) | ||
| except Exception as e: | ||
| pkg_bundle["pkgsign_error"] = str(e) | ||
| return package_list | ||
|
|
||
| def clean(self, package_list, source=True, build=True, download=True, temp=True, | ||
| backup_sources=False): | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.