Expand description
§Rust CDEvents SDK
Rust SDK to emit CDEvents.
The SDK can be used to create CDEvents and send them as CloudEvents, as well as parse a received CloudEvent into a CDEvent.
§Create and send your first CDEvent as CloudEvent
Import the modules in your code
cdevents-sdk = "0.1"
To send a CDEvent as CloudEvent:
// from examples/pipelinerun_finished.rs
use std::error::Error;
use cdevents_sdk::{CDEvent, Subject, spec_0_3_0::pipelinerun_finished, Content};
use cloudevents::{Event, AttributesReader};
fn main() -> Result<(), Box<dyn Error>> {
let cdevent = CDEvent::from(
Subject::from(pipelinerun_finished::Content{
errors: Some("pipelineErrors".into()),
outcome: Some("success".into()),
pipeline_name: Some("testPipeline".into()),
url: Some("https://dev.pipeline.run/url".into())
})
.with_id("/dev/pipeline/run/1".try_into()?)
.with_source("https://dev.pipeline.run/source".try_into()?)
)
.with_id("271069a8-fc18-44f1-b38f-9d70a1695819".try_into()?)
.with_source("https://dev.cdevents".try_into()?)
;
let cdevent_expected = cdevent.clone();
// shortcut for creating cloudevents with
//
// ```rust
// use cloudevents::event::EventBuilderV10;
// use cdevents_sdk::cloudevents::BuilderExt;
//
// let mut cloudevent = EventBuilderV10::new().with_cdevent(cdevent.clone())?.build()?;
// ```
let cloudevent: Event = cdevent.try_into()?;
// zero transport, but cloning
let cloudevent_received: Event = cloudevent.clone();
let cdevent_extracted: CDEvent = cloudevent_received.try_into()?;
assert_eq!(cloudevent.id(), cdevent_extracted.id().to_string());
assert_eq!(cdevent_expected, cdevent_extracted);
Ok(())
}
See the CloudEvents docs as well.
§Features
- support cdevents spec 0.3.0
- support cdevents spec 0.4.1
-
support of custom event
- compile-time generation of type for custom event
- runtime validation (download of jsonschemas & validation)
-
serialize/deserialize of custom event (type
dev.cdeventsx.{subject}.{predicate}.{version}
) -
partial validation of custom event (
subject.content
is not validated, stored as json)
- Cloudevents support (provide wrapper/extractor for CDEvent)
- CDEvent stored into static types (=> no use of jsonshema at runtime)
- rutime validation for scalar types (purl, datetime, uri-reference)
- report clear and readable error messages on deserialization
- provide type with builder pattern (fluent)
- provide random/sample generator for CDEvent (property based testing)
-
test
serialization(deserialization(of spec's examples & conformances)) == spec's examples & conformances
-
test
serialization(random CDEvent) matches the jsonschemas
§References
Modules§
- artifact_
deleted_ 0_ 1_ 0 - artifact_
downloaded_ 0_ 1_ 0 - artifact_
packaged_ 0_ 1_ 1 - artifact_
packaged_ 0_ 2_ 0 - artifact_
published_ 0_ 1_ 1 - artifact_
published_ 0_ 2_ 0 - artifact_
signed_ 0_ 1_ 0 - artifact_
signed_ 0_ 2_ 0 - branch_
created_ 0_ 1_ 2 - branch_
created_ 0_ 2_ 0 - branch_
deleted_ 0_ 1_ 2 - branch_
deleted_ 0_ 2_ 0 - build_
finished_ 0_ 1_ 1 - build_
finished_ 0_ 2_ 0 - build_
queued_ 0_ 1_ 1 - build_
queued_ 0_ 2_ 0 - build_
started_ 0_ 1_ 1 - build_
started_ 0_ 2_ 0 - change_
abandoned_ 0_ 1_ 2 - change_
abandoned_ 0_ 2_ 0 - change_
created_ 0_ 1_ 2 - change_
created_ 0_ 3_ 0 - change_
merged_ 0_ 1_ 2 - change_
merged_ 0_ 2_ 0 - change_
reviewed_ 0_ 1_ 2 - change_
reviewed_ 0_ 2_ 0 - change_
updated_ 0_ 1_ 2 - change_
updated_ 0_ 2_ 0 - cloudevents
- environment_
created_ 0_ 1_ 1 - environment_
created_ 0_ 2_ 0 - environment_
deleted_ 0_ 1_ 1 - environment_
deleted_ 0_ 2_ 0 - environment_
modified_ 0_ 1_ 1 - environment_
modified_ 0_ 2_ 0 - incident_
detected_ 0_ 1_ 0 - incident_
detected_ 0_ 2_ 0 - incident_
reported_ 0_ 1_ 0 - incident_
reported_ 0_ 2_ 0 - incident_
resolved_ 0_ 1_ 0 - incident_
resolved_ 0_ 2_ 0 - latest
- pipelinerun_
finished_ 0_ 1_ 1 - pipelinerun_
finished_ 0_ 2_ 0 - pipelinerun_
queued_ 0_ 1_ 1 - pipelinerun_
queued_ 0_ 2_ 0 - pipelinerun_
started_ 0_ 1_ 1 - pipelinerun_
started_ 0_ 2_ 0 - repository_
created_ 0_ 1_ 1 - repository_
created_ 0_ 2_ 0 - repository_
deleted_ 0_ 1_ 1 - repository_
deleted_ 0_ 2_ 0 - repository_
modified_ 0_ 1_ 1 - repository_
modified_ 0_ 2_ 0 - service_
deployed_ 0_ 1_ 1 - service_
deployed_ 0_ 2_ 0 - service_
published_ 0_ 1_ 1 - service_
published_ 0_ 2_ 0 - service_
removed_ 0_ 1_ 1 - service_
removed_ 0_ 2_ 0 - service_
rolledback_ 0_ 1_ 1 - service_
rolledback_ 0_ 2_ 0 - service_
upgraded_ 0_ 1_ 1 - service_
upgraded_ 0_ 2_ 0 - spec_
0_ 3_ 0 - spec_
0_ 4_ 1 - taskrun_
finished_ 0_ 1_ 1 - taskrun_
finished_ 0_ 2_ 0 - taskrun_
started_ 0_ 1_ 1 - taskrun_
started_ 0_ 2_ 0 - testcaserun_
finished_ 0_ 1_ 0 - testcaserun_
finished_ 0_ 2_ 0 - testcaserun_
queued_ 0_ 1_ 0 - testcaserun_
queued_ 0_ 2_ 0 - testcaserun_
skipped_ 0_ 1_ 0 - testcaserun_
started_ 0_ 1_ 0 - testcaserun_
started_ 0_ 2_ 0 - testoutput_
published_ 0_ 1_ 0 - testoutput_
published_ 0_ 2_ 0 - testsuiterun_
finished_ 0_ 1_ 0 - testsuiterun_
finished_ 0_ 2_ 0 - testsuiterun_
queued_ 0_ 1_ 0 - testsuiterun_
queued_ 0_ 2_ 0 - testsuiterun_
started_ 0_ 1_ 0 - testsuiterun_
started_ 0_ 2_ 0 - ticket_
closed_ 0_ 1_ 0 - ticket_
created_ 0_ 1_ 0 - ticket_
updated_ 0_ 1_ 0
Structs§
- CDEvent
- NonEmpty
String - A non-empty string.
- Subject
- see https://github.com/cdevents/spec/blob/main/spec.md#cdevent-subject
- Uri
- UriReference
Enums§
Constants§
- ARTIFACT_
DELETED_ 0_ 1_ 0 - ARTIFACT_
DOWNLOADED_ 0_ 1_ 0 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ITERUN_
FINISHED_ 0_ 2_ 0 - TESTSUITERUN_
QUEUED_ 0_ 1_ 0 - TESTSUITERUN_
QUEUED_ 0_ 2_ 0 - TESTSUITERUN_
STARTED_ 0_ 1_ 0 - TESTSUITERUN_
STARTED_ 0_ 2_ 0 - TICKET_
CLOSED_ 0_ 1_ 0 - TICKET_
CREATED_ 0_ 1_ 0 - TICKET_
UPDATED_ 0_ 1_ 0
Functions§
- extract_
subject_ predicate - Due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples) Custom type are not supported