shardline_protocol_adapters/lib.rs
1#![deny(unsafe_code)]
2#![cfg_attr(
3 test,
4 allow(
5 clippy::unwrap_used,
6 clippy::expect_used,
7 clippy::indexing_slicing,
8 clippy::shadow_unrelated,
9 clippy::let_underscore_must_use,
10 clippy::format_push_string
11 )
12)]
13
14//! Shared protocol adapters for Git LFS, Bazel HTTP cache, and related
15//! object-key mapping.
16//!
17//! This crate owns the small, self-contained functions that map protocol
18//! identifiers to validated [`shardline_storage::ObjectKey`] values. It
19//! avoids pulling in heavy server dependencies such as `axum` or `sqlx`.
20//!
21//! # Quick start
22//!
23//! Everything here is pure. The most common task is mapping an LFS object ID
24//! to a storage key:
25//!
26//! ```
27//! use shardline_protocol_adapters::{LfsOperation, TransferAdapter, lfs_object_key};
28//! use shardline_server_core::AuthorizedRepository;
29//!
30//! let oid = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
31//! let key = lfs_object_key(oid, &AuthorizedRepository::anonymous_full_access())?;
32//! assert!(key.as_str().starts_with("protocols/lfs/global/objects/"));
33//! assert!(key.as_str().ends_with(oid));
34//!
35//! // Malformed OIDs are rejected instead of being stored under a bad key.
36//! assert!(
37//! lfs_object_key("not-a-valid-sha256", &AuthorizedRepository::anonymous_full_access())
38//! .is_err()
39//! );
40//!
41//! // Batch operations and transfer adapters round-trip through their wire names.
42//! assert_eq!("download".parse(), Ok(LfsOperation::Download));
43//! assert_eq!(TransferAdapter::Xet.as_str(), "xet");
44//! # Ok::<(), Box<dyn std::error::Error>>(())
45//! ```
46//!
47//! See also [`bazel_cache_object_key`] for the Bazel HTTP cache mapping and
48//! [`scope_namespace`] for repository-scoped key prefixes.
49
50mod bazel;
51mod lfs;
52
53mod mapping;
54
55pub use bazel::{BazelCacheKind, bazel_cache_object_key};
56pub use lfs::{
57 LFS_CONTENT_TYPE, LfsBatchRequest, LfsBatchResponse, LfsObjectError, LfsObjectRequest,
58 LfsObjectResponse, LfsOperation, LfsValidationError, TransferAdapter, cas_headers,
59 lfs_object_key,
60};
61pub use mapping::{ProtocolError, object_key, scope_namespace, validate_content_hash};
62
63#[cfg(test)]
64mod tests;