Skip to main content

Crate cnb

Crate cnb 

Source
Expand description

§cnb — Rust client for the CNB (Cloud Native Build) platform.

An async, typed, production-grade SDK for the CNB public API, covering all 241 operations across 28 tag groups (repositories, issues, pulls, git, releases, builds, artifactories, workspaces, AI helpers, …).

This crate is not officially affiliated with CNB.

§Quick start

use cnb::ApiClient;

// Picks up `CNB_TOKEN` from the environment.
let client = ApiClient::new()?;

let me = client.users().get_user_info().await?;
println!("{me:?}");

Every resource method returns a Result<T> where T is a typed DTO from the models module (or serde_json::Value for endpoints where the upstream spec did not pin a schema).

§Features

FeatureDefaultDescription
rustls-tlsUse rustls as the TLS backend (no OpenSSL).
native-tlsUse the system TLS (OpenSSL / Secure Transport).
retryAutomatic retries with exponential back-off.
tracingEmit tracing spans for each API call.
streamStream-based pagination helpers.
all-resourcesEnable every resource module. Disable to slim.
per-resourceactivities, ai, …, workspace — see Cargo.toml.

TLS backends are mutually exclusive. When disabling the default, pick one:

cnb = { version = "0.2", default-features = false, features = ["native-tls", "retry", "all-resources"] }

§Error handling

All errors are a ApiError. Non-2xx responses preserve the raw body plus any parsed code / message / request_id fields:

use cnb::{ApiClient, ApiError};

let client = ApiClient::new()?;
match client.repositories().get_by_id("owner/name".into()).await {
    Ok(repo) => println!("{repo:?}"),
    Err(ApiError::Http { status: 404, .. }) => println!("not found"),
    Err(ApiError::Http { status, body, .. }) => println!("HTTP {status}: {body}"),
    Err(e) => println!("transport error: {e}"),
}

Modules§

activitiesactivities
aiai
artifactoryartifactory
assetsassets
badgebadge
buildbuild
chargecharge
eventevent
followersfollowers
gitgit
git_settingsgit_settings
http
Shared HTTP transport. All resource modules call into HttpInner::execute or HttpInner::execute_with_body.
issuesissues
knowledge_baseknowledge_base
membersmembers
missionsmissions
models
Typed request / response DTOs generated from definitions in the CNB OpenAPI specification.
organizationsorganizations
pagination
Generic pagination helpers behind the stream feature.
pullspulls
rankrank
registriesregistries
releasesreleases
repo_code_issuerepo_code_issue
repo_contributorrepo_contributor
repo_labelsrepo_labels
repositoriesrepositories
searchsearch
securitysecurity
starringstarring
usersusers
wikiwiki
workspaceworkspace

Structs§

ApiClient
Top-level entry point of the SDK.
ClientBuilder
Builder for ApiClient. See module docs for examples.
RetryConfig
Retry configuration. Construct with RetryConfig::default for sensible defaults or adjust individual fields.

Enums§

ApiError
Every error surfaced by the SDK.

Constants§

CNB_API_ACCEPT
Wire format the CNB API uses for successful JSON responses. We pre-set this in the shared reqwest::Client’s default headers so callers never need to think about it.
DEFAULT_BASE_URL
Default base URL — the production CNB endpoint.
TOKEN_ENV_VAR
Environment variable consulted by ClientBuilder::build when no explicit token is provided.

Type Aliases§

Result
Crate-wide Result alias.