Port SDK (Rust)
Rust crate for interacting with the Port REST APIs. The SDK aims to wrap the Swagger definition at https://api.port.io/swagger/json with type-safe request/response models, predictable error handling, and ergonomics that match the Rust ecosystem.
Status
Actively under construction. See TODO.md for the current implementation plan.
Getting Started
- Install Rust toolchain
Userustupto install the latest stable toolchain. - Clone the repo
- Verify the code compiles
Usage Guide
use ;
#
# async
- Authentication helpers live under
port_sdk::auth. - High-level flows are available in
port_sdk::apis(e.g.,apis::blueprints::list). - See
docs/usage.mdfor end-to-end walkthroughs and troubleshooting tips.
Crate Layout
src/lib.rs– crate root re-exporting the public API surface.src/client.rs– HTTP client that wrapsreqwestand applies authentication.src/error.rs– error types surfaced to SDK consumers.src/types.rs– placeholder for structs generated from the Swagger schema (to be implemented).src/apis.rs– placeholder for higher-level endpoint wrappers (to be implemented).docs/– developer-facing documentation (architecture, build, testing, release).TODO.md– detailed roadmap for completing the SDK.
Development Workflow
- Follow the tasks in
TODO.mdsequentially. Each task explains why it exists so newcomers can learn the rationale. - Keep the documentation under
docs/updated when adding new functionality. - Run the standard cargo commands:
- When adding network calls, prefer dependency injection or test doubles for unit tests to avoid flaky integration runs.
Configuration & Authentication
- Load configuration from a
.envfile or shell environment variables. CallPortClient::from_env()orPortConfig::from_env()to bootstrap defaults. - Provide OAuth client credentials via
PORT_CLIENT_IDandPORT_CLIENT_SECRET(optionallyPORT_TOKEN_URL). The SDK automatically exchanges them for access tokens. - Supply a pre-issued access token with
PORT_ACCESS_TOKEN(or legacyPORT_API_TOKEN) if you manage tokens externally. - Control the target region using
PORT_REGION(eudefault,ussupported) or override withPORT_BASE_URL. Base URL defaults to the EU endpoint when not specified. - Configure outbound proxies with
PORT_PROXY_URL(falls back toHTTP_PROXY/HTTPS_PROXY) and optionalPROXY_AUTH_USERNAME/PROXY_AUTH_PASSWORD. - Tune request behaviour with
PORT_TIMEOUT(milliseconds) andPORT_MAX_RETRIES. Disable retries by settingPORT_RETRY_DISABLED=1. - Enable request tracing by setting
PORT_TRACING_ENABLED=1when the crate is built with thetelemetryfeature.
Testing with .env
- Copy the skeleton file and fill in credentials:
- Provide either
PORT_CLIENT_ID/PORT_CLIENT_SECRET(plus overrides such asPORT_TOKEN_URL) or a pre-issued token viaPORT_ACCESS_TOKEN. - Run
cargo testto ensure the SDK can authenticate using the supplied values—end-to-end tests read from the environment at runtime. - For manual experiments, run snippets from the
examples/directory (cargo run --example ...) or the code indocs/usage.md; the runtime automatically loads.envviadotenvy.
Documentation
Additional context lives in:
docs/architecture.md– module responsibilities, data flow, and security guidelines.docs/build_and_release.md– end-to-end instructions for building, testing, and publishing the crate.docs/testing_strategy.md– recommended testing layers, including unit, integration, and contract testing.CHANGELOG.md– history of notable changes and release notes.docs/feature_flags.md– overview of optional crate features and how to enable them.docs/logging.md– tracing integration and safe logging practices.docs/examples.md– guide to the walkthroughs in theexamples/directory.
Releasing
High-level release checklist:
- Ensure
cargo fmt,cargo clippy, andcargo testpass on the main branch. - Update
CHANGELOG.md(to be added) with notable changes. - Bump the crate version in
Cargo.toml. - Follow
docs/build_and_release.mdforcargo publishpreparation steps (audit, dry run, tagging).
Contributing
Issues and pull requests are welcome. Please include tests and documentation updates for any new feature to keep the SDK reliable and easy to understand.