Skip to content

Commit 96992be

Browse files
committed
chore: make aws optional
1 parent dd294cf commit 96992be

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

common/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ version.workspace = true
1616
# normal
1717
anyhow = { workspace = true }
1818
async-trait = { workspace = true }
19-
aws-config = { workspace = true }
20-
aws-sdk-s3 = { workspace = true }
2119
backon = { workspace = true }
2220
base64 = { workspace = true }
2321
bytes = { workspace = true }
@@ -49,6 +47,8 @@ url = { workspace = true }
4947
walkdir = { workspace = true }
5048

5149
# optional
50+
aws-config = { workspace = true, optional = true }
51+
aws-sdk-s3 = { workspace = true, optional = true }
5252
bzip2 = { workspace = true, optional = true }
5353
bzip2-rs = { workspace = true, optional = true, features = ["rustc_1_51"] }
5454
clap = { workspace = true, features = ["derive", "env"], optional = true }
@@ -60,6 +60,7 @@ sequoia-openpgp = { workspace = true, optional = true }
6060
[features]
6161
default = ["bzip2"]
6262
openpgp = ["sequoia-openpgp"]
63+
s3 = ["dep:aws-config", "dep:aws-sdk-s3"]
6364

6465
# deprecated
6566
cli = ["clap", "env_logger"]

common/src/scoop/source.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
use crate::USER_AGENT;
22
use anyhow::bail;
3-
use aws_config::{BehaviorVersion, Region, meta::region::RegionProviderChain};
4-
use aws_sdk_s3::{
5-
Client,
6-
config::{AppName, Credentials},
7-
};
83
use bytes::Bytes;
94
use std::{
105
borrow::Cow,
116
path::{Path, PathBuf},
127
};
138
use url::Url;
149

10+
#[cfg(feature = "s3")]
11+
use aws_config::{BehaviorVersion, Region, meta::region::RegionProviderChain};
12+
#[cfg(feature = "s3")]
13+
use aws_sdk_s3::{
14+
Client,
15+
config::{AppName, Credentials},
16+
};
17+
1518
#[derive(Clone, Debug, PartialEq, Eq)]
19+
#[non_exhaustive]
1620
pub enum Source {
1721
Path(PathBuf),
1822
Http(Url),
23+
#[cfg(feature = "s3")]
1924
S3(S3),
2025
}
2126

2227
impl TryFrom<&str> for Source {
2328
type Error = anyhow::Error;
2429

2530
fn try_from(value: &str) -> Result<Self, Self::Error> {
26-
Ok(
27-
if value.starts_with("http://") || value.starts_with("https://") {
28-
Self::Http(Url::parse(value)?)
29-
} else if value.starts_with("s3://") {
30-
Self::S3(S3::try_from(value)?)
31-
} else {
32-
Self::Path(value.into())
33-
},
34-
)
31+
if value.starts_with("http://") || value.starts_with("https://") {
32+
return Ok(Self::Http(Url::parse(value)?));
33+
}
34+
35+
#[cfg(feature = "s3")]
36+
if value.starts_with("s3://") {
37+
return Ok(Self::S3(S3::try_from(value)?));
38+
}
39+
40+
Ok(Self::Path(value.into()))
3541
}
3642
}
3743

@@ -42,6 +48,7 @@ impl Source {
4248
.into_iter()
4349
.map(Self::Path)
4450
.collect()),
51+
#[cfg(feature = "s3")]
4552
Self::S3(s3) if s3.key.is_none() => Ok(Self::discover_s3(s3)
4653
.await?
4754
.into_iter()
@@ -77,6 +84,7 @@ impl Source {
7784
}
7885
}
7986

87+
#[cfg(feature = "s3")]
8088
async fn discover_s3(s3: S3) -> anyhow::Result<Vec<S3>> {
8189
let client = s3.client().await?;
8290

@@ -110,6 +118,7 @@ impl Source {
110118
match self {
111119
Self::Path(path) => path.to_string_lossy(),
112120
Self::Http(url) => url.as_str().into(),
121+
#[cfg(feature = "s3")]
113122
Self::S3(s3) => format!(
114123
"s3://{}/{}/{}",
115124
s3.region,
@@ -131,6 +140,7 @@ impl Source {
131140
.bytes()
132141
.await?
133142
}
143+
#[cfg(feature = "s3")]
134144
Self::S3(s3) => {
135145
let client = s3.client();
136146
client
@@ -163,6 +173,7 @@ impl Source {
163173
.send()
164174
.await?;
165175
}
176+
#[cfg(feature = "s3")]
166177
Self::S3(s3) => {
167178
// delete the object from the bucket
168179
let client = s3.client();
@@ -194,6 +205,7 @@ impl Source {
194205
// no-op, but warn
195206
log::warn!("Unable to move HTTP source ({url}), skipping!");
196207
}
208+
#[cfg(feature = "s3")]
197209
Self::S3(s3) => {
198210
let client = s3.client();
199211
client
@@ -211,6 +223,7 @@ impl Source {
211223
}
212224
}
213225

226+
#[cfg(feature = "s3")]
214227
#[derive(Clone, Debug, PartialEq, Eq)]
215228
pub struct S3 {
216229
region: String,
@@ -219,6 +232,7 @@ pub struct S3 {
219232
key: Option<String>,
220233
}
221234

235+
#[cfg(feature = "s3")]
222236
impl TryFrom<&str> for S3 {
223237
type Error = anyhow::Error;
224238

@@ -257,6 +271,7 @@ impl TryFrom<&str> for S3 {
257271
}
258272
}
259273

274+
#[cfg(feature = "s3")]
260275
impl S3 {
261276
pub async fn client(&self) -> anyhow::Result<Client> {
262277
let region_provider = RegionProviderChain::first_try(Region::new(self.region.clone()));
@@ -280,6 +295,7 @@ impl S3 {
280295
mod tests {
281296
use super::*;
282297

298+
#[cfg(feature = "s3")]
283299
#[test]
284300
fn parse_s3() {
285301
assert_eq!(
@@ -311,6 +327,7 @@ mod tests {
311327
);
312328
}
313329

330+
#[cfg(feature = "s3")]
314331
#[test]
315332
fn parse_s3_custom_region() {
316333
assert_eq!(

csaf/csaf-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ openssl = { workspace = true, optional = true }
3434

3535
# internal
3636
csaf-walker = { workspace = true, features = ["csaf"] }
37-
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger"] }
37+
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger", "s3"] }
3838
walker-extras = { workspace = true }
3939

4040
[features]

sbom/sbom-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tokio = { workspace = true, features = ["full"] }
3131

3232
# internal
3333
sbom-walker = { workspace = true, features = ["serde-cyclonedx", "spdx-rs"] }
34-
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger"] }
34+
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger", "s3"] }
3535
walker-extras = { workspace = true }
3636

3737
# just there for the feature

0 commit comments

Comments
 (0)