Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
edition = "2024"
license = "Apache-2.0"
rust-version = "1.87.0"
version = "0.14.2"
version = "0.15.0"

[workspace.dependencies]
anyhow = "1"
Expand Down Expand Up @@ -73,10 +73,10 @@ walkdir = "2.4"

# internal dependencies

csaf-walker = { version = "0.14.2", path = "csaf", default-features = false }
sbom-walker = { version = "0.14.2", path = "sbom", default-features = false }
walker-common = { version = "0.14.2", path = "common" }
walker-extras = { version = "0.14.2", path = "extras" }
csaf-walker = { version = "0.15.0", path = "csaf", default-features = false }
sbom-walker = { version = "0.15.0", path = "sbom", default-features = false }
walker-common = { version = "0.15.0", path = "common" }
walker-extras = { version = "0.15.0", path = "extras" }

[workspace.metadata.release]
tag = false
Expand Down
5 changes: 3 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ version.workspace = true
# normal
anyhow = { workspace = true }
async-trait = { workspace = true }
aws-config = { workspace = true }
aws-sdk-s3 = { workspace = true }
backon = { workspace = true }
base64 = { workspace = true }
bytes = { workspace = true }
Expand Down Expand Up @@ -49,6 +47,8 @@ url = { workspace = true }
walkdir = { workspace = true }

# optional
aws-config = { workspace = true, optional = true }
aws-sdk-s3 = { workspace = true, optional = true }
bzip2 = { workspace = true, optional = true }
bzip2-rs = { workspace = true, optional = true, features = ["rustc_1_51"] }
clap = { workspace = true, features = ["derive", "env"], optional = true }
Expand All @@ -60,6 +60,7 @@ sequoia-openpgp = { workspace = true, optional = true }
[features]
default = ["bzip2"]
openpgp = ["sequoia-openpgp"]
s3 = ["dep:aws-config", "dep:aws-sdk-s3"]

# deprecated
cli = ["clap", "env_logger"]
Expand Down
49 changes: 35 additions & 14 deletions common/src/scoop/source.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
use crate::USER_AGENT;
use anyhow::bail;
use aws_config::{BehaviorVersion, Region, meta::region::RegionProviderChain};
use aws_sdk_s3::{
Client,
config::{AppName, Credentials},
};
use bytes::Bytes;
use std::{
borrow::Cow,
path::{Path, PathBuf},
};
use url::Url;

#[cfg(feature = "s3")]
use aws_config::{BehaviorVersion, Region, meta::region::RegionProviderChain};
#[cfg(feature = "s3")]
use aws_sdk_s3::{
Client,
config::{AppName, Credentials},
};

#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Source {
Path(PathBuf),
Http(Url),
#[cfg(feature = "s3")]
S3(S3),
}

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

fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(
if value.starts_with("http://") || value.starts_with("https://") {
Self::Http(Url::parse(value)?)
} else if value.starts_with("s3://") {
Self::S3(S3::try_from(value)?)
} else {
Self::Path(value.into())
},
)
if value.starts_with("http://") || value.starts_with("https://") {
return Ok(Self::Http(Url::parse(value)?));
}

#[cfg(feature = "s3")]
if value.starts_with("s3://") {
return Ok(Self::S3(S3::try_from(value)?));
}
#[cfg(not(feature = "s3"))]
if value.starts_with("s3://") {
bail!("S3 URLs are not supported");
}

Ok(Self::Path(value.into()))
}
}

Expand All @@ -42,6 +52,7 @@ impl Source {
.into_iter()
.map(Self::Path)
.collect()),
#[cfg(feature = "s3")]
Self::S3(s3) if s3.key.is_none() => Ok(Self::discover_s3(s3)
.await?
.into_iter()
Expand Down Expand Up @@ -77,6 +88,7 @@ impl Source {
}
}

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

Expand Down Expand Up @@ -110,6 +122,7 @@ impl Source {
match self {
Self::Path(path) => path.to_string_lossy(),
Self::Http(url) => url.as_str().into(),
#[cfg(feature = "s3")]
Self::S3(s3) => format!(
"s3://{}/{}/{}",
s3.region,
Expand All @@ -131,6 +144,7 @@ impl Source {
.bytes()
.await?
}
#[cfg(feature = "s3")]
Self::S3(s3) => {
let client = s3.client();
client
Expand Down Expand Up @@ -163,6 +177,7 @@ impl Source {
.send()
.await?;
}
#[cfg(feature = "s3")]
Self::S3(s3) => {
// delete the object from the bucket
let client = s3.client();
Expand Down Expand Up @@ -194,6 +209,7 @@ impl Source {
// no-op, but warn
log::warn!("Unable to move HTTP source ({url}), skipping!");
}
#[cfg(feature = "s3")]
Self::S3(s3) => {
let client = s3.client();
client
Expand All @@ -211,6 +227,7 @@ impl Source {
}
}

#[cfg(feature = "s3")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct S3 {
region: String,
Expand All @@ -219,6 +236,7 @@ pub struct S3 {
key: Option<String>,
}

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

Expand Down Expand Up @@ -257,6 +275,7 @@ impl TryFrom<&str> for S3 {
}
}

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

#[cfg(feature = "s3")]
#[test]
fn parse_s3() {
assert_eq!(
Expand Down Expand Up @@ -311,6 +331,7 @@ mod tests {
);
}

#[cfg(feature = "s3")]
#[test]
fn parse_s3_custom_region() {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion csaf/csaf-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ openssl = { workspace = true, optional = true }

# internal
csaf-walker = { workspace = true, features = ["csaf"] }
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger"] }
walker-common = { workspace = true, features = ["openpgp", "clap", "env_logger", "s3"] }
walker-extras = { workspace = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion sbom/sbom-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tokio = { workspace = true, features = ["full"] }

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

# just there for the feature
Expand Down