-
Couldn't load subscription status.
- Fork 60
feat: Add blocking client #189
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
Open
dave-tucker
wants to merge
1
commit into
oras-project:main
Choose a base branch
from
dave-tucker:blocking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ on: | |
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| steps: | ||
| - uses: actions/[email protected] | ||
| - uses: engineerd/[email protected] | ||
|
|
||
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,100 @@ | ||
| use oci_client::{blocking::Client, secrets::RegistryAuth, Reference}; | ||
|
|
||
| use clap::Parser; | ||
| use docker_credential::{CredentialRetrievalError, DockerCredential}; | ||
| use tracing::{debug, warn}; | ||
| use tracing_subscriber::prelude::*; | ||
| use tracing_subscriber::{fmt, EnvFilter}; | ||
|
|
||
| /// Pull a WebAssembly module from a OCI container registry | ||
| #[derive(Parser, Debug)] | ||
| #[clap(author, version, about, long_about = None)] | ||
| pub(crate) struct Cli { | ||
| /// Enable verbose mode | ||
| #[clap(short, long)] | ||
| pub verbose: bool, | ||
|
|
||
| /// Perform anonymous operation, by default the tool tries to reuse the docker credentials read | ||
| /// from the default docker file | ||
| #[clap(short, long)] | ||
| pub anonymous: bool, | ||
|
|
||
| /// Pull image from registry using HTTP instead of HTTPS | ||
| #[clap(short, long)] | ||
| pub insecure: bool, | ||
|
|
||
| /// Enable json output | ||
| #[clap(long)] | ||
| pub json: bool, | ||
|
|
||
| /// Name of the image to pull | ||
| image: String, | ||
| } | ||
|
|
||
| fn build_auth(reference: &Reference, cli: &Cli) -> RegistryAuth { | ||
| let server = reference | ||
| .resolve_registry() | ||
| .strip_suffix('/') | ||
| .unwrap_or_else(|| reference.resolve_registry()); | ||
|
|
||
| if cli.anonymous { | ||
| return RegistryAuth::Anonymous; | ||
| } | ||
|
|
||
| match docker_credential::get_credential(server) { | ||
| Err(CredentialRetrievalError::ConfigNotFound) => RegistryAuth::Anonymous, | ||
| Err(CredentialRetrievalError::NoCredentialConfigured) => RegistryAuth::Anonymous, | ||
| Err(e) => panic!("Error handling docker configuration file: {}", e), | ||
| Ok(DockerCredential::UsernamePassword(username, password)) => { | ||
| debug!("Found docker credentials"); | ||
| RegistryAuth::Basic(username, password) | ||
| } | ||
| Ok(DockerCredential::IdentityToken(_)) => { | ||
| warn!("Cannot use contents of docker config, identity token not supported. Using anonymous auth"); | ||
| RegistryAuth::Anonymous | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn build_client_config(cli: &Cli) -> oci_client::blocking::ClientConfig { | ||
| let protocol = if cli.insecure { | ||
| oci_client::blocking::ClientProtocol::Http | ||
| } else { | ||
| oci_client::blocking::ClientProtocol::Https | ||
| }; | ||
|
|
||
| oci_client::blocking::ClientConfig { | ||
| protocol, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| pub fn main() { | ||
| let cli = Cli::parse(); | ||
|
|
||
| // setup logging | ||
| let level_filter = if cli.verbose { "debug" } else { "info" }; | ||
| let filter_layer = EnvFilter::new(level_filter); | ||
| tracing_subscriber::registry() | ||
| .with(filter_layer) | ||
| .with(fmt::layer().with_writer(std::io::stderr)) | ||
| .init(); | ||
|
|
||
| let reference: Reference = cli.image.parse().expect("Not a valid image reference"); | ||
| let auth = build_auth(&reference, &cli); | ||
|
|
||
| let client_config = build_client_config(&cli); | ||
| let mut client = Client::new(client_config); | ||
|
|
||
| let (manifest, _) = client | ||
| .pull_manifest(&reference, &auth) | ||
| .expect("Cannot pull manifest"); | ||
|
|
||
| if cli.json { | ||
| serde_json::to_writer_pretty(std::io::stdout(), &manifest) | ||
| .expect("Cannot serialize manifest to JSON"); | ||
| println!(); | ||
| } else { | ||
| println!("{}", manifest); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
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.
Any reason why this was removed? We had this on here so other tests could still run on the OS it didn't fail on
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.
Yes. strategy only applies to matrix jobs. From the docs