A Rust library to detect the cloud service provider of a host.
This library is inspired by the Python-based cloud-detect and the Go-based satellite modules.
Like these modules, cloud-detect uses a combination of checking vendor files and metadata endpoints to accurately
determine the cloud provider of a host.
- Currently, this module supports the identification of the following providers:
- Akamai Cloud (
akamai) - Amazon Web Services (
aws) - Microsoft Azure (
azure) - Google Cloud Platform (
gcp) - Alibaba Cloud (
alibaba) - OpenStack (
openstack) - DigitalOcean (
digitalocean) - Oracle Cloud Infrastructure (
oci) - Vultr (
vultr)
- Akamai Cloud (
- Fast, simple and extensible.
- Real-time console logging using the
tracingcrate.
First, add the library to your project by adding the following to your Cargo.toml file:
[dependencies]
# ...
cloud-detect = "3"
tokio = { version = "1", features = ["full"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Optional; for logging.To use the non-async blocking API instead, enable the blocking feature:
[dependencies]
# ...
cloud-detect = { version = "3", features = ["blocking"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Optional; for logging.Detect the cloud provider and print the result (with default timeout; async).
use cloud_detect::detect;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init(); // Optional; for logging
let provider = detect(None).await;
// When tested on AWS:
println!("{}", provider); // "aws"
// When tested on local/non-supported cloud environment:
println!("{}", provider); // "unknown"
}Detect the cloud provider and print the result (with default timeout; blocking).
use cloud_detect::blocking::detect;
fn main() {
tracing_subscriber::fmt::init(); // Optional; for logging
let provider = detect(None).unwrap();
// When tested on AWS:
println!("{}", provider); // "aws"
// When tested on local/non-supported cloud environment:
println!("{}", provider); // "unknown"
}Detect the cloud provider and print the result (with custom timeout; async).
use cloud_detect::detect;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init(); // Optional; for logging
let provider = detect(Some(10)).await;
// When tested on AWS:
println!("{}", provider); // "aws"
// When tested on local/non-supported cloud environment:
println!("{}", provider); // "unknown"
}Detect the cloud provider and print the result (with custom timeout; blocking).
use cloud_detect::blocking::detect;
fn main() {
tracing_subscriber::fmt::init(); // Optional; for logging
let provider = detect(Some(10)).unwrap();
// When tested on AWS:
println!("{}", provider); // "aws"
// When tested on local/non-supported cloud environment:
println!("{}", provider); // "unknown"
}You can also check the list of currently supported cloud providers.
Async:
use cloud_detect::supported_providers;
#[tokio::main]
async fn main() {
println!("Supported providers: {:?}", supported_providers().await);
}Blocking:
use cloud_detect::blocking::supported_providers;
fn main() {
println!("Supported providers: {:?}", supported_providers().unwrap());
}For more detailed documentation, please refer to the Crate Documentation.
Contributions are welcome and greatly appreciated! If you’d like to contribute to cloud-detect, here’s how you can help.
If you encounter a bug, unexpected behavior, or have a feature request, please open an issue. Be sure to include:
- A clear description of the issue.
- Steps to reproduce, if applicable.
- Details about your environment.
If you're submitting a pull request, please ensure the following.
- Your code is formatted using
cargo fmt(the Rustnightlychannel is required, as a few unstable features are used).
cargo fmt +nightly --all
cargo fmt +nightly --all --check- Code lints pass with:
cargo clippy --all-targets --all-features --workspace -- -D warnings- Your code contains sufficient unit tests and that all tests pass.
cargo test --locked --all-features --workspaceIf you find areas in the documentation that are unclear or incomplete, feel free to update the README or crate-level documentation. Open a pull request with your improvements.
You can also contribute by reviewing open pull requests. Providing constructive feedback helps maintain a high-quality codebase.