Skip to main content

function_sdk_rust/
lib.rs

1//! A Rust SDK for writing Crossplane composition functions.
2//!
3//! Composition functions are gRPC servers implementing the
4//! [`FunctionRunnerService`] defined by Crossplane's
5//! `apiextensions.fn.proto.v1` API. This SDK provides the generated protocol
6//! types, a spec-compliant server runtime, and helpers for working with
7//! requests and responses.
8//!
9//! The most important protocol rule: desired state is a fully specified
10//! server-side apply intent, not a merge patch. Build responses with
11//! [`response::to`] so the desired state and context accumulated by earlier
12//! pipeline steps are copied forward; anything left out is deleted from the
13//! cluster.
14//!
15//! [`FunctionRunnerService`]: proto::v1::function_runner_service_server::FunctionRunnerService
16
17mod metrics;
18
19pub mod context;
20pub mod logging;
21pub mod proto;
22pub mod request;
23pub mod resource;
24pub mod response;
25pub mod server;
26
27pub use server::{Args, serve};
28
29/// Errors returned by the SDK.
30#[derive(Debug, thiserror::Error)]
31pub enum Error {
32    /// A JSON conversion failed.
33    #[error("JSON conversion failed: {0}")]
34    Json(#[from] serde_json::Error),
35
36    /// A source serialized to a JSON value that is not an object.
37    #[error("source must serialize to a JSON object")]
38    NotAnObject,
39
40    /// The request has no function input.
41    #[error("the request has no function input")]
42    MissingInput,
43
44    /// The resource has no JSON representation to deserialize.
45    #[error("the resource has no JSON representation")]
46    MissingResource,
47
48    /// The listen address could not be parsed.
49    #[error("cannot parse listen address: {0}")]
50    InvalidAddress(#[from] std::net::AddrParseError),
51
52    /// Neither --tls-certs-dir nor --insecure was supplied.
53    #[error("no credentials were provided - supply --tls-certs-dir or use --insecure")]
54    MissingTlsCertsDir,
55
56    /// A TLS certificate or key could not be read.
57    #[error("cannot read TLS certificate or key from {path}: {source}")]
58    ReadCertificate {
59        path: std::path::PathBuf,
60        source: std::io::Error,
61    },
62
63    /// The gRPC server failed.
64    #[error("gRPC server error: {0}")]
65    Transport(#[from] tonic::transport::Error),
66
67    /// The gRPC reflection service could not be built.
68    #[error("cannot build gRPC reflection service: {0}")]
69    Reflection(#[from] tonic_reflection::server::Error),
70}