Skip to main content

aws_ssm_bridge/
lib.rs

1//! # AWS SSM Bridge
2//!
3//! A high-performance Rust library implementing the AWS Systems Manager (SSM)
4//! Session Manager protocol with first-class Python bindings.
5//!
6//! ## Architecture Philosophy
7//!
8//! **Flat module structure** - Following Rust best practices (tokio, serde, reqwest):
9//! - Direct module access without deep nesting
10//! - Clear naming makes deep hierarchies unnecessary
11//! - The crate boundary provides encapsulation
12//!
13//! ## Module Organization
14//!
15//! ### Public API (re-exported at crate root)
16//! - [`SessionManager`] - High-level session management
17//! - [`Session`] - Active session handle with streaming API
18//! - [`SessionConfig`] - Session configuration
19//! - [`Error`], [`Result`] - Error handling
20//!
21//! ### Public Modules (for advanced usage)
22//! - [`errors`] - Domain-specific error types with retry classification
23//! - [`protocol`] - SSM protocol message types and framing
24//! - [`session`] - Session management internals
25//! - [`retry`] - Exponential backoff and circuit breaker patterns
26//!
27//! ### Internal Modules (implementation details)
28//! - `connection` - WebSocket connection lifecycle
29//! - `channels` - Channel multiplexing for stdin/stdout/stderr
30//!
31//! ## Usage
32//!
33//! ```rust,no_run
34//! use aws_ssm_bridge::{SessionConfig, SessionManager};
35//! use futures::StreamExt;
36//!
37//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
38//! // Create session manager
39//! let manager = SessionManager::new().await?;
40//!
41//! // Start a session
42//! let mut session = manager.start_session(SessionConfig {
43//!     target: "i-1234567890abcdef0".to_string(),
44//!     ..Default::default()
45//! }).await?;
46//!
47//! // Stream output
48//! let mut output = session.output();
49//! tokio::spawn(async move {
50//!     while let Some(data) = output.next().await {
51//!         print!("{}", String::from_utf8_lossy(&data));
52//!     }
53//! });
54//!
55//! // Send commands
56//! session.send(bytes::Bytes::from("ls -la\n")).await?;
57//!
58//! // Clean shutdown
59//! session.terminate().await?;
60//! # Ok(())
61//! # }
62//! ```
63//!
64//! ## Disclaimer
65//!
66//! This project is not affiliated with, endorsed by, or sponsored by
67//! Amazon Web Services, Inc. or any of its affiliates.
68
69#![deny(unsafe_code)]
70#![warn(missing_docs, rust_2018_idioms)]
71
72/// Library version
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");
74
75/// Maximum message payload size (10MB)
76pub const MAX_PAYLOAD_SIZE: usize = 10 * 1024 * 1024;
77
78// ============================================================================
79// Public Modules
80// ============================================================================
81
82/// Error types and result aliases
83pub mod errors;
84
85/// SSM protocol message types and framing
86pub mod protocol;
87
88/// Binary protocol implementation (AWS-compatible)
89pub mod binary_protocol;
90
91/// Session management and lifecycle
92pub mod session;
93
94/// Retry logic with exponential backoff and circuit breaker
95pub mod retry;
96
97/// Token bucket rate limiting for DoS protection
98pub mod rate_limit;
99
100/// Session builder for fluent API
101pub mod builder;
102
103/// Type-safe SSM document definitions
104pub mod documents;
105
106/// Port forwarding implementation
107pub mod port_forward;
108
109/// AWS SSM handshake protocol (3-phase)
110pub mod handshake;
111
112/// Acknowledgment and retransmission with RTT tracking
113pub mod ack;
114
115/// Cross-platform terminal handling for interactive shells
116pub mod terminal;
117
118/// Interactive shell sessions with full terminal support
119pub mod interactive;
120
121/// Metrics and observability hooks
122pub mod metrics;
123
124/// Graceful shutdown utilities
125pub mod shutdown;
126
127/// Session pool for managing multiple concurrent sessions
128pub mod pool;
129
130/// Session reconnection with exponential backoff
131pub mod reconnect;
132
133/// Structured tracing for distributed observability
134pub mod tracing_ext;
135
136// ============================================================================
137// Internal Modules (not re-exported)
138// ============================================================================
139
140mod channels;
141mod connection;
142
143// ============================================================================
144// Feature-Gated Modules
145// ============================================================================
146
147/// Python bindings via PyO3
148#[cfg(feature = "python")]
149pub mod python;
150
151// ============================================================================
152// Crate-Root Re-exports (convenience)
153// ============================================================================
154
155// Primary API types
156pub use session::{Session, SessionConfig, SessionManager, SessionState};
157
158// Builder pattern for ergonomic session creation
159pub use builder::SessionBuilder;
160
161// Error handling
162pub use errors::{Error, Result};
163
164// Protocol types
165pub use protocol::{MessageType, SessionType};
166
167// Retry utilities
168pub use retry::{CircuitBreaker, CircuitState, RetryConfig, RetryStrategy};
169
170// Rate limiting
171pub use rate_limit::{RateLimitConfig, RateLimitResult, RateLimiter};
172
173// Port forwarding
174pub use port_forward::{PortForwardConfig, PortForwarder};
175
176// Streaming API
177pub use channels::OutputStream;
178
179// Terminal handling
180pub use terminal::{Terminal, TerminalConfig, TerminalInput, TerminalSize};
181
182// Interactive shell
183pub use interactive::{InteractiveConfig, InteractiveShell};
184
185// Metrics (observability hooks)
186pub use metrics::{register_metrics, MetricsRecorder};
187
188// Graceful shutdown
189pub use shutdown::{install_signal_handlers, ShutdownGuard, ShutdownSignal};
190
191// Session pool
192pub use pool::{PoolConfig, PoolStats, SessionPool};
193
194// Reconnection
195pub use reconnect::{ReconnectConfig, ReconnectEvent, ReconnectStats, ReconnectingSession};
196
197// Tracing
198pub use tracing_ext::{
199    span_connection, span_handshake, span_receive, span_send, span_session, SessionSpan,
200    TraceContext,
201};