Crate cdevents_sdk

Source
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
NonEmptyString
A non-empty string.
Subject
see https://github.com/cdevents/spec/blob/main/spec.md#cdevent-subject
Uri
UriReference

Enums§

Content
Error

Constants§

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
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
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
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

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

Type Aliases§

Id
Name