#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Scan<'a> {
pub critical: i64,
pub high: i64,
pub low: i64,
#[serde(borrow)]
pub manifest: AtUri<'a>,
pub medium: i64,
#[serde(borrow)]
pub repository: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub sbom_blob: Option<BlobRef<'a>>,
pub scanned_at: Datetime,
#[serde(borrow)]
pub scanner_version: CowStr<'a>,
pub total: i64,
#[serde(borrow)]
pub user_did: Did<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub vuln_report_blob: Option<BlobRef<'a>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ScanGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Scan<'a>,
}
impl<'a> Scan<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, ScanRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ScanRecord;
impl XrpcResp for ScanRecord {
const NSID: &'static str = "io.atcr.hold.scan";
const ENCODING: &'static str = "application/json";
type Output<'de> = ScanGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<ScanGetRecordOutput<'_>> for Scan<'_> {
fn from(output: ScanGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Scan<'_> {
const NSID: &'static str = "io.atcr.hold.scan";
type Record = ScanRecord;
}
impl Collection for ScanRecord {
const NSID: &'static str = "io.atcr.hold.scan";
type Record = ScanRecord;
}
impl<'a> LexiconSchema for Scan<'a> {
fn nsid() -> &'static str {
"io.atcr.hold.scan"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_io_atcr_hold_scan()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.critical;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("critical"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.high;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("high"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.low;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("low"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.medium;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("medium"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.repository;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("repository"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.sbom_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["application/spdx+json"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("sbom_blob"),
accepted: vec!["application/spdx+json".to_string()],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.scanner_version;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("scanner_version"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.total;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("total"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.vuln_report_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["application/vnd.atcr.vulnerabilities+json"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("vuln_report_blob"),
accepted: vec![
"application/vnd.atcr.vulnerabilities+json".to_string()
],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
pub mod scan_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type High;
type Low;
type Medium;
type ScannerVersion;
type Critical;
type Manifest;
type UserDid;
type Total;
type Repository;
type ScannedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type High = Unset;
type Low = Unset;
type Medium = Unset;
type ScannerVersion = Unset;
type Critical = Unset;
type Manifest = Unset;
type UserDid = Unset;
type Total = Unset;
type Repository = Unset;
type ScannedAt = Unset;
}
pub struct SetHigh<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetHigh<S> {}
impl<S: State> State for SetHigh<S> {
type High = Set<members::high>;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetLow<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLow<S> {}
impl<S: State> State for SetLow<S> {
type High = S::High;
type Low = Set<members::low>;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetMedium<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMedium<S> {}
impl<S: State> State for SetMedium<S> {
type High = S::High;
type Low = S::Low;
type Medium = Set<members::medium>;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetScannerVersion<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetScannerVersion<S> {}
impl<S: State> State for SetScannerVersion<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = Set<members::scanner_version>;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetCritical<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCritical<S> {}
impl<S: State> State for SetCritical<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = Set<members::critical>;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetManifest<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetManifest<S> {}
impl<S: State> State for SetManifest<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = Set<members::manifest>;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetUserDid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUserDid<S> {}
impl<S: State> State for SetUserDid<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = Set<members::user_did>;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetTotal<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTotal<S> {}
impl<S: State> State for SetTotal<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = Set<members::total>;
type Repository = S::Repository;
type ScannedAt = S::ScannedAt;
}
pub struct SetRepository<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRepository<S> {}
impl<S: State> State for SetRepository<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = Set<members::repository>;
type ScannedAt = S::ScannedAt;
}
pub struct SetScannedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetScannedAt<S> {}
impl<S: State> State for SetScannedAt<S> {
type High = S::High;
type Low = S::Low;
type Medium = S::Medium;
type ScannerVersion = S::ScannerVersion;
type Critical = S::Critical;
type Manifest = S::Manifest;
type UserDid = S::UserDid;
type Total = S::Total;
type Repository = S::Repository;
type ScannedAt = Set<members::scanned_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct high(());
pub struct low(());
pub struct medium(());
pub struct scanner_version(());
pub struct critical(());
pub struct manifest(());
pub struct user_did(());
pub struct total(());
pub struct repository(());
pub struct scanned_at(());
}
}
pub struct ScanBuilder<'a, S: scan_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<i64>,
Option<i64>,
Option<i64>,
Option<AtUri<'a>>,
Option<i64>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<i64>,
Option<Did<'a>>,
Option<BlobRef<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Scan<'a> {
pub fn new() -> ScanBuilder<'a, scan_state::Empty> {
ScanBuilder::new()
}
}
impl<'a> ScanBuilder<'a, scan_state::Empty> {
pub fn new() -> Self {
ScanBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Critical: scan_state::IsUnset,
{
pub fn critical(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<'a, scan_state::SetCritical<S>> {
self._fields.0 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::High: scan_state::IsUnset,
{
pub fn high(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<'a, scan_state::SetHigh<S>> {
self._fields.1 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Low: scan_state::IsUnset,
{
pub fn low(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<'a, scan_state::SetLow<S>> {
self._fields.2 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Manifest: scan_state::IsUnset,
{
pub fn manifest(
mut self,
value: impl Into<AtUri<'a>>,
) -> ScanBuilder<'a, scan_state::SetManifest<S>> {
self._fields.3 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Medium: scan_state::IsUnset,
{
pub fn medium(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<'a, scan_state::SetMedium<S>> {
self._fields.4 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Repository: scan_state::IsUnset,
{
pub fn repository(
mut self,
value: impl Into<CowStr<'a>>,
) -> ScanBuilder<'a, scan_state::SetRepository<S>> {
self._fields.5 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: scan_state::State> ScanBuilder<'a, S> {
pub fn sbom_blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_sbom_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::ScannedAt: scan_state::IsUnset,
{
pub fn scanned_at(
mut self,
value: impl Into<Datetime>,
) -> ScanBuilder<'a, scan_state::SetScannedAt<S>> {
self._fields.7 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::ScannerVersion: scan_state::IsUnset,
{
pub fn scanner_version(
mut self,
value: impl Into<CowStr<'a>>,
) -> ScanBuilder<'a, scan_state::SetScannerVersion<S>> {
self._fields.8 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::Total: scan_state::IsUnset,
{
pub fn total(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<'a, scan_state::SetTotal<S>> {
self._fields.9 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::UserDid: scan_state::IsUnset,
{
pub fn user_did(
mut self,
value: impl Into<Did<'a>>,
) -> ScanBuilder<'a, scan_state::SetUserDid<S>> {
self._fields.10 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: scan_state::State> ScanBuilder<'a, S> {
pub fn vuln_report_blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_vuln_report_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.11 = value;
self
}
}
impl<'a, S> ScanBuilder<'a, S>
where
S: scan_state::State,
S::High: scan_state::IsSet,
S::Low: scan_state::IsSet,
S::Medium: scan_state::IsSet,
S::ScannerVersion: scan_state::IsSet,
S::Critical: scan_state::IsSet,
S::Manifest: scan_state::IsSet,
S::UserDid: scan_state::IsSet,
S::Total: scan_state::IsSet,
S::Repository: scan_state::IsSet,
S::ScannedAt: scan_state::IsSet,
{
pub fn build(self) -> Scan<'a> {
Scan {
critical: self._fields.0.unwrap(),
high: self._fields.1.unwrap(),
low: self._fields.2.unwrap(),
manifest: self._fields.3.unwrap(),
medium: self._fields.4.unwrap(),
repository: self._fields.5.unwrap(),
sbom_blob: self._fields.6,
scanned_at: self._fields.7.unwrap(),
scanner_version: self._fields.8.unwrap(),
total: self._fields.9.unwrap(),
user_did: self._fields.10.unwrap(),
vuln_report_blob: self._fields.11,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Scan<'a> {
Scan {
critical: self._fields.0.unwrap(),
high: self._fields.1.unwrap(),
low: self._fields.2.unwrap(),
manifest: self._fields.3.unwrap(),
medium: self._fields.4.unwrap(),
repository: self._fields.5.unwrap(),
sbom_blob: self._fields.6,
scanned_at: self._fields.7.unwrap(),
scanner_version: self._fields.8.unwrap(),
total: self._fields.9.unwrap(),
user_did: self._fields.10.unwrap(),
vuln_report_blob: self._fields.11,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_io_atcr_hold_scan() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("io.atcr.hold.scan"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Vulnerability scan results for a container manifest. Stored in the hold's embedded PDS. Record key is deterministic: the manifest digest hex without the 'sha256:' prefix, so re-scans upsert the existing record.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("manifest"),
SmolStr::new_static("repository"),
SmolStr::new_static("userDid"),
SmolStr::new_static("critical"),
SmolStr::new_static("high"), SmolStr::new_static("medium"),
SmolStr::new_static("low"), SmolStr::new_static("total"),
SmolStr::new_static("scannerVersion"),
SmolStr::new_static("scannedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("critical"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("high"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("low"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("manifest"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI of the scanned manifest (e.g., at://did:plc:xyz/io.atcr.manifest/abc123...)",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("medium"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("repository"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Repository name (e.g., myapp)"),
),
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sbomBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("scannedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"RFC3339 timestamp of when the scan completed",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("scannerVersion"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Version of the scanner that produced this result (e.g., atcr-scanner-v1.0.0)",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("total"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("userDid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("DID of the image owner"),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("vulnReportBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}