fly_sdk/lib.rs
1//! # Unofficial Fly SDK
2//!
3//! The Fly SDK provides an interface for interacting with the Fly.io Machines API.
4//! It allows you to manage applications, machines, volumes, and secrets on Fly.io.
5//! The SDK is designed to simplify the usage of the Fly.io API with convenient methods for common tasks.
6//!
7//! ## Example
8//!
9//! ```rust
10//! use fly_sdk::FlyControl;
11//!
12//! let api_token = "your_api_token".to_string();
13//! let fly_control = FlyControl::new(api_token);
14//!
15//! // Now you can use fly_control to manage apps, machines, secrets, and volumes
16//! ```
17//!
18//! The `FlyControl` struct is the main entry point for interacting with the Fly.io API.
19//! It encapsulates managers for applications, machines, volumes, and secrets, allowing
20//! you to manage these entities using a single unified interface.
21//!
22//! # Fields
23//! - `apps`: Manages Fly.io applications.
24//! - `machines`: Manages Fly.io machines.
25//! - `volumes`: Manages Fly.io volumes.
26//! - `secrets`: Manages Fly.io secrets.
27//!
28//! # Example usage
29//! - `fly_control.apps.create_app(...);`
30//! - `fly_control.machines.list_machines(...);`
31//! - `fly_control.volumes.create_volume(...);`
32//! - `fly_control.secrets.set_secret(...);`
33//!
34//! # Features
35//! This crate supports the following features:
36//! - `apps`: Enable app management.
37//! - `machines`: Enable machine management.
38//! - `volumes`: Enable volume management.
39//! - `secrets`: Enable secret management.
40//! - `full`: Enable all features.
41
42#[cfg(feature = "apps")]
43pub mod apps;
44
45#[cfg(feature = "machines")]
46pub mod machines;
47
48#[cfg(feature = "secrets")]
49pub mod secrets;
50
51#[cfg(feature = "volumes")]
52pub mod volumes;
53
54use reqwest::Client;
55
56const API_BASE_URL: &str = "https://api.machines.dev/v1";
57
58pub struct FlyControl {
59 #[cfg(feature = "apps")]
60 pub apps: apps::AppManager,
61
62 #[cfg(feature = "machines")]
63 pub machines: machines::MachineManager,
64
65 #[cfg(feature = "volumes")]
66 pub volumes: volumes::VolumeManager,
67
68 #[cfg(feature = "secrets")]
69 pub secrets: secrets::SecretsManager,
70}
71
72impl FlyControl {
73 pub fn new(api_token: String) -> Self {
74 let client = Client::new();
75 FlyControl {
76 #[cfg(feature = "apps")]
77 apps: apps::AppManager::new(client.clone(), api_token.clone()),
78
79 #[cfg(feature = "machines")]
80 machines: machines::MachineManager::new(client.clone(), api_token.clone()),
81
82 #[cfg(feature = "volumes")]
83 volumes: volumes::VolumeManager::new(client.clone(), api_token.clone()),
84
85 #[cfg(feature = "secrets")]
86 secrets: secrets::SecretsManager::new(client.clone(), api_token.clone()),
87 }
88 }
89}