Skip to content

Commit a660f70

Browse files
committed
feat(casi): implement core IO and logging functionality
- Add IO utilities for content hashing and stream processing - Add logging system with progress tracking and verbosity control - Define error types for the library - Add constants for configuration parameters
1 parent e4fb9f4 commit a660f70

File tree

14 files changed

+2640
-15
lines changed

14 files changed

+2640
-15
lines changed

Cargo.lock

Lines changed: 501 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"tools/bottlerocket-variant",
88
"tools/buildsys",
99
"tools/buildsys-config",
10+
"tools/casi",
1011
"tools/include-env-compressed",
1112
"tools/include-env-compressed/include-env-compressed-macro",
1213
"tools/oci-cli-wrapper",
@@ -89,6 +90,8 @@ unplug = { version = "0.1", path = "tools/unplug", artifact = [ "bin:unplug" ] }
8990
update-metadata = { version = "0.1", path = "tools/update-metadata" }
9091

9192
anyhow = "1"
93+
astral-tokio-tar = "0.5"
94+
async-compression = "0.4"
9295
async-recursion = "1"
9396
async-stream = "0.3"
9497
async-trait = "0.1"
@@ -100,6 +103,7 @@ aws-sdk-ec2 = { version = "1", default-features = false, features = ["default-ht
100103
aws-sdk-kms = { version = "1", default-features = false, features = ["default-https-client", "rt-tokio"] }
101104
aws-sdk-ssm = { version = "1", default-features = false, features = ["default-https-client", "rt-tokio"] }
102105
aws-sdk-sts = { version = "1", default-features = false, features = ["default-https-client", "rt-tokio"] }
106+
aws-sdk-s3 = { version = "1", default-features = false, features = ["default-https-client", "rt-tokio"] }
103107
aws-smithy-types = "1"
104108
aws-types = "1"
105109
base64 = "0.22"
@@ -131,10 +135,13 @@ lzma-rs = "0.3"
131135
maplit = "1"
132136
nix = "0.29"
133137
nonzero_ext = "0.3"
134-
num_cpus = "1"
138+
num_cpus = "1.17"
135139
num-traits = "0.2"
140+
oci-spec = "0.8"
136141
once_cell = "1.21"
137142
olpc-cjson = "0.1"
143+
owo-colors = "4.2"
144+
parking_lot = "0.12"
138145
proc-macro2 = "1"
139146
quote = "1"
140147
rand = { version = "0.8", default-features = false }
@@ -166,6 +173,8 @@ tough = "0.21"
166173
tough-kms = "0.13"
167174
tough-ssm = "0.16"
168175
tracing = "0.1"
176+
tracing-indicatif = "=0.3.9"
177+
tracing-subscriber = "0.3"
169178
tuftool = { version = "0.14", artifact = [ "bin:tuftool" ] }
170179
uds = "0.4.1"
171180
unescape = "0.1"

deny.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ wildcards = "deny"
6262
skip = [
6363
# several dependencies are using multiple versions of base64
6464
{ name = "base64" },
65+
# owo-colors uses two versions of supports-color by itself
66+
{ name = "supports-color" }
6567
]
6668

6769
skip-tree = [

tools/casi/Cargo.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[package]
2+
name = "casi"
3+
version = "0.1.0"
4+
authors = ["Jarrett Tierney <[email protected]>"]
5+
license = "Apache-2.0 OR MIT"
6+
edition = "2021"
7+
publish = false
8+
9+
[dependencies]
10+
astral-tokio-tar.workspace = true
11+
async-compression = { workspace = true, features = ["tokio", "zstd"] }
12+
async-trait.workspace = true
13+
aws-config.workspace = true
14+
aws-sdk-s3.workspace = true
15+
aws-smithy-types.workspace = true
16+
aws-types.workspace = true
17+
bon.workspace = true
18+
chrono = { workspace = true, features = ["serde", "now"] }
19+
clap = { workspace = true, features = ["derive"] }
20+
futures.workspace = true
21+
hex.workspace = true
22+
indicatif.workspace = true
23+
oci-spec.workspace = true
24+
olpc-cjson.workspace = true
25+
owo-colors = { workspace = true, features = ["supports-colors"] }
26+
parking_lot = { workspace = true, features = ["send_guard", "arc_lock"] }
27+
rand.workspace = true
28+
semver = { workspace = true, features = ["serde"] }
29+
serde = { workspace = true, features = ["derive"] }
30+
serde_json.workspace = true
31+
sha2.workspace = true
32+
snafu.workspace = true
33+
tempfile.workspace = true
34+
tokio = { workspace = true, features = ["full"] }
35+
tracing.workspace = true
36+
tracing-indicatif.workspace = true
37+
tracing-subscriber = { workspace = true, features = [
38+
"env-filter",
39+
"fmt",
40+
"registry",
41+
] }
42+
url = { workspace = true, features = ["serde"] }
43+
uuid = { workspace = true, features = ["v4"] }
44+
walkdir.workspace = true
45+
zstd.workspace = true

tools/casi/src/constants.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! Constants used throughout the casi crate.
2+
//!
3+
//! This module centralizes magic numbers and commonly used values to improve
4+
//! code maintainability and reduce the likelihood of errors.
5+
6+
/// Default buffer size for I/O operations (64KB)
7+
pub const DEFAULT_BUFFER_SIZE: usize = 64 * 1024;
8+
9+
/// Buffer size for hashing operations (128MB)
10+
/// Uses 8KB chunks which align with standard memory page sizes for optimal
11+
/// performance when reading from files and network streams.
12+
pub const HASH_BUFFER_SIZE: usize = 128 * 1024 * 1024;
13+
14+
/// Maximum number of multipart upload parts for S3
15+
pub const MAX_MULTIPART_PARTS: usize = 10_000;
16+
17+
/// Minimum size for S3 multipart upload parts (5MB)
18+
pub const MIN_MULTIPART_PART_SIZE: usize = 5 * 1024 * 1024;
19+
20+
/// Default compression level for Zstd
21+
pub const DEFAULT_COMPRESSION_LEVEL: i32 = 3;
22+
23+
/// Maximum file name length for cross-platform compatibility
24+
pub const MAX_FILENAME_LENGTH: usize = 255;
25+
26+
/// Default timeout for network operations (30 seconds)
27+
pub const DEFAULT_NETWORK_TIMEOUT_SECS: u64 = 30;
28+
29+
/// Maximum retry attempts for transient failures
30+
pub const MAX_RETRY_ATTEMPTS: usize = 3;
31+
32+
/// Default page size for listing operations
33+
pub const DEFAULT_PAGE_SIZE: usize = 100;
34+
35+
/// Maximum artifacts to display in table format
36+
pub const MAX_TABLE_DISPLAY_ARTIFACTS: usize = 1000;
37+
38+
/// Hash truncation length for display purposes
39+
pub const HASH_DISPLAY_LENGTH: usize = 16;
40+
41+
/// Schema version for OCI manifests
42+
pub const OCI_MANIFEST_SCHEMA_VERSION: u32 = 2;
43+
44+
/// Default file permissions for created files (0o644)
45+
pub const DEFAULT_FILE_PERMISSIONS: u32 = 0o644;
46+
47+
/// Default directory permissions for created directories (0o755)
48+
pub const DEFAULT_DIR_PERMISSIONS: u32 = 0o755;

tools/casi/src/error.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use snafu::Snafu;
2+
3+
pub type Result<T> = std::result::Result<T, Error>;
4+
5+
#[derive(Debug, Snafu)]
6+
#[snafu(visibility(pub))]
7+
pub enum Error {
8+
#[snafu(display(
9+
"Failed to read data for hashing: {source} - check if the file exists and is readable"
10+
))]
11+
HashingReadError { source: std::io::Error },
12+
13+
#[snafu(display("Failed to initialize logging system: {source}"))]
14+
LogInit {
15+
source: Box<dyn std::error::Error + Send + Sync>,
16+
},
17+
18+
#[snafu(display("Failed to parse log directive: {directive}"))]
19+
LogDirectiveParse { directive: String },
20+
}

0 commit comments

Comments
 (0)