oras-project / rust-oci-client

A Rust crate to interact with OCI registries
Apache License 2.0
93 stars 49 forks source link

Implement Client::pull_manifest_raw #115

Closed MathiasPius closed 7 months ago

MathiasPius commented 8 months ago

Implements Client::pull_manifest_raw for fetching the plain text representation of a manifest without deserializing it into an OciManifest.

This way the manifest can be pushed elsewhere while maintaining the digest value of the manifest which is otherwise subject to change following re-serialization of the OciManifest object.

Asymmetry with push_raw_manifest

push_manifest_raw takes a Vec<u8>, while pull_manifest_raw returns the content as a String. I've chosen this route, since it allows us to still call validate_registry_response in Client::_pull_manifest_raw where the response status and manifest text is available for validation.

Providing accepted_media_types when pulling raw manifests

Since pull_manifest_raw is specifically intended for fetching individual manifests for mirroring, I expect the caller to be traversing the tree of manifests manually and pushing/storing them elsewhere, and in that case they will have a very good idea of what kind of manifest they're likely to get back at each individual step.

Deduplicating code

I've re-implemented Client::_pull_manifest in terms of Client::_pull_manifest_raw to reduce code duplication, so it now uses the raw function to get the text manifest, and then performs deserialization from there.

Closes #114

MathiasPius commented 7 months ago

Thanks for the quick reviews! I've implemented the changes as requested, please review the updated PR, and let me know if there's anything else :)

flavio commented 7 months ago

@MathiasPius can you please fix the small formatting issue that causes the windows test to fail?

Aside from that, the PR LGTM