pub struct ValidManifest { /* private fields */ }Expand description
A manifest that passed validation, with its effective limits.
§Examples
use stratum_node_core::{JobCeilings, ManifestRule, MilliCpus, ValidManifest};
let json = format!(
r#"{{"name":"n","version":"1","image_id":"sha256:{}","profile":"job",
"containers":[{{"path":"a/","modes":["Read"],"operations":["PUT"]}}],
"workspace":"none","max_body_bytes":1}}"#,
"00".repeat(32)
);
let err = ValidManifest::parse(json.as_bytes(), &JobCeilings::DEFAULT).unwrap_err();
assert_eq!(err.rule(), ManifestRule::WriteOperationWithoutWrite);
assert_eq!(err.field(), "containers[0].operations");
// A lowered ceiling refuses a manifest that was valid before.
let ok = json.replace(r#""operations":["PUT"]"#, r#""operations":["GET"]"#);
let valid = ValidManifest::parse(ok.as_bytes(), &JobCeilings::DEFAULT)?;
let lowered = JobCeilings { cpus: MilliCpus::new(500), ..JobCeilings::DEFAULT };
assert_eq!(valid.check_ceilings(&lowered).unwrap_err().field(), "limits.cpus");Implementations§
Source§impl ValidManifest
impl ValidManifest
Sourcepub fn parse(json: &[u8], ceilings: &JobCeilings) -> Result<Self, ManifestError>
pub fn parse(json: &[u8], ceilings: &JobCeilings) -> Result<Self, ManifestError>
Parses and validates a manifest’s JSON bytes against ceilings.
§Errors
Returns a ManifestError naming the first member that breaks a
rule, checked in document order of the members listed under
ManifestRule.
Sourcepub fn from_value(
value: &Value,
ceilings: &JobCeilings,
) -> Result<Self, ManifestError>
pub fn from_value( value: &Value, ceilings: &JobCeilings, ) -> Result<Self, ManifestError>
Validates a manifest already parsed as JSON, such as the manifest
member of an approval request.
§Errors
Sourcepub fn check_ceilings(
&self,
ceilings: &JobCeilings,
) -> Result<(), ManifestError>
pub fn check_ceilings( &self, ceilings: &JobCeilings, ) -> Result<(), ManifestError>
Re-checks the effective limits against ceilings, as launch does.
§Errors
ManifestRule::LimitAboveCeiling naming the first limit above its
ceiling.
Sourcepub fn into_manifest(self) -> Manifest
pub fn into_manifest(self) -> Manifest
Returns the manifest, consuming the validated wrapper.
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Returns the manifest serialised as compact JSON, the form the store
keeps and ValidManifest::parse reads back.
§Panics
Never: every member serialises.
Trait Implementations§
Source§impl Clone for ValidManifest
impl Clone for ValidManifest
Source§impl Debug for ValidManifest
impl Debug for ValidManifest
impl Eq for ValidManifest
Source§impl Hash for ValidManifest
impl Hash for ValidManifest
Source§impl PartialEq for ValidManifest
impl PartialEq for ValidManifest
impl StructuralPartialEq for ValidManifest
Auto Trait Implementations§
impl Forget for ValidManifest
impl Freeze for ValidManifest
impl Move for ValidManifest
impl RefUnwindSafe for ValidManifest
impl Send for ValidManifestwhere
RawVecInner: Send,
impl Sync for ValidManifestwhere
RawVecInner: Sync,
impl Unpin for ValidManifest
impl UnsafeUnpin for ValidManifestwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<ContainerGrant>: UnsafeUnpin,
impl UnwindSafe for ValidManifestwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more