-
Notifications
You must be signed in to change notification settings - Fork 11
Feat: Support to accept the response of signing result from RADAS #294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e322b4e
Feat: Support to accept the response of signing result from RADAS
yma955 07e43f3
Format Code and fix typo
yma955 42dbb01
Rename radas_sign_timeout_retry_count and radas_sign_timeout_retry_in…
yma955 89be82f
Use oras registry_config and registry url parse to finalize login
yma955 d4eee68
Change sign_result_loc to cmd flag both for sign request and maven up…
yma955 d2e86c9
Update quay_radas_registry_config to default None since it's not nece…
yma955 75740e5
Use radas_config validate instead of is_radas_config_enable option
yma955 947f23c
Ignore the registry config if the provided config path is not valid t…
yma955 da803dd
Add is_radas_enabled unified method to check radas enablement
yma955 f784b16
Change on_message process method without using threads
yma955 83a92f9
Remove timeout retry handling for sign result fetch from maven upload
yma955 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| """ | ||
| Copyright (C) 2022 Red Hat, Inc. (https://github.com/Commonjava/charon) | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| import oras.client | ||
| import logging | ||
| from charon.config import get_config | ||
| from typing import List | ||
| from urllib.parse import urlparse | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class OrasClient: | ||
| """ | ||
| Wrapper for oras‑py’s OrasClient, deciding whether to login based on config. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| self.conf = get_config() | ||
| self.client = oras.client.OrasClient() | ||
|
|
||
| def login_if_needed(self, registry: str) -> None: | ||
| """ | ||
| If quay_radas_registry_config is provided, call login to authenticate. | ||
| """ | ||
| if not registry.startswith("http://") and not registry.startswith("https://"): | ||
| registry = "https://" + registry | ||
| registry = urlparse(registry).netloc | ||
|
|
||
| rconf = self.conf.get_radas_config() if self.conf else None | ||
| if rconf and rconf.quay_radas_registry_config(): | ||
| logger.info("Logging in to registry: %s", registry) | ||
| res = self.client.login( | ||
| hostname=registry, | ||
| config_path=rconf.quay_radas_registry_config(), | ||
| ) | ||
| logger.info(res) | ||
| else: | ||
| logger.info("Registry config is not provided, skip login.") | ||
|
|
||
| def pull(self, result_reference_url: str, sign_result_loc: str) -> List[str]: | ||
| """ | ||
| Call oras‑py’s pull method to pull the remote file to local. | ||
| Args: | ||
| result_reference_url (str): | ||
| Reference of the remote file (e.g. “quay.io/repository/signing/radas@hash”). | ||
| sign_result_loc (str): | ||
| Local save path (e.g. “/tmp/sign”). | ||
| """ | ||
| files = [] | ||
| try: | ||
| self.login_if_needed(registry=result_reference_url) | ||
| files = self.client.pull(target=result_reference_url, outdir=sign_result_loc) | ||
| logger.info("Pull file from %s to %s", result_reference_url, sign_result_loc) | ||
| except Exception as e: | ||
| logger.error( | ||
| "Failed to pull file from %s to %s: %s", result_reference_url, sign_result_loc, e | ||
| ) | ||
| return files |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should add a
__is_radas_enabledfield here for convenient, which set toself.__radas_config__ and self.__radas_config__.validate(). So then we can use this with a get methodis_radas_enabled()for unified way in other place to check if radas is usable.