Skip to content

Commit

Permalink
feat!: Change the way we approach licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed Jul 25, 2024
1 parent 176ec4f commit 8c1e26e
Show file tree
Hide file tree
Showing 13 changed files with 9,712 additions and 3,250 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions genealogos/src/bom/cyclonedx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,22 @@ impl TryFrom<ModelLicense> for LicenseChoice {
type Error = Error;

fn try_from(model: ModelLicense) -> Result<Self> {
if let Some(id) = model.id {
Ok(LicenseChoice::Expression(SpdxExpression::parse_lax(id)?))
let identifier = if let Some(id) = model.id {
LicenseIdentifier::SpdxId(SpdxIdentifier::try_from(id)?)
} else if let Some(name) = model.name {
Ok(LicenseChoice::License(License {
license_identifier: LicenseIdentifier::Name(NormalizedString::new(&name)),
text: None,
url: None,
bom_ref: None,
licensing: None,
properties: None,
}))
LicenseIdentifier::Name(NormalizedString::new(&name))
} else {
unreachable!("We only construct ModelLicense with at least id or name")
}
};

Ok(LicenseChoice::License(License {
license_identifier: identifier,
text: None,
url: None,
bom_ref: None,
licensing: None,
properties: None,
}))
}
}

Expand Down
6 changes: 3 additions & 3 deletions genealogos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub enum Error {
#[error("Errors constructing CycloneDX XML output: {0}")]
CycloneDXXML(#[from] cyclonedx_bom::errors::XmlWriteError),

/// Holds errors encountered while constructing attempting to parse the provided SPDX expression
#[error("Errors constructing CycloneDX SPDX expression: {0}")]
CycloneDXSpdxExpression(#[from] cyclonedx_bom::external_models::spdx::SpdxExpressionError),
/// Holds errors encountered while constructing attempting to parse the provided SPDX identifier
#[error("Errors constructing CycloneDX SPDX Identifier: {0}")]
CycloneDXSpdxExpression(#[from] cyclonedx_bom::external_models::spdx::SpdxIdentifierError),

/// String conversion error from UTF8 bytes
#[error("Errors constructing Converting to String output: {0}")]
Expand Down
Loading

0 comments on commit 8c1e26e

Please sign in to comment.