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
17pub mod context;
18pub mod logging;
19pub mod proto;
20pub mod request;
21pub mod resource;
22pub mod response;
23pub mod server;
24
25pub use server::{Args, serve};
26
27/// Errors returned by the SDK.
28#[derive(Debug, thiserror::Error)]
29pub enum Error {
30    /// A JSON conversion failed.
31    #[error("JSON conversion failed: {0}")]
32    Json(#[from] serde_json::Error),
33
34    /// A source serialized to a JSON value that is not an object.
35    #[error("source must serialize to a JSON object")]
36    NotAnObject,
37
38    /// The request has no function input.
39    #[error("the request has no function input")]
40    MissingInput,
41
42    /// The listen address could not be parsed.
43    #[error("cannot parse listen address: {0}")]
44    InvalidAddress(#[from] std::net::AddrParseError),
45
46    /// Neither --tls-certs-dir nor --insecure was supplied.
47    #[error("no credentials were provided - supply --tls-certs-dir or use --insecure")]
48    MissingTlsCertsDir,
49
50    /// A TLS certificate or key could not be read.
51    #[error("cannot read TLS certificate or key from {path}: {source}")]
52    ReadCertificate {
53        path: std::path::PathBuf,
54        source: std::io::Error,
55    },
56
57    /// The gRPC server failed.
58    #[error("gRPC server error: {0}")]
59    Transport(#[from] tonic::transport::Error),
60
61    /// The gRPC reflection service could not be built.
62    #[error("cannot build gRPC reflection service: {0}")]
63    Reflection(#[from] tonic_reflection::server::Error),
64}