Rust library that detects a host's cloud service provider.
This library is heavily inspired by the Python cloud-detect module, and replicates most of its functionality (even most of the code is structured similarly).
- Supports the identification of the following providers:
- Amazon Web Services (
aws
) - Microsoft Azure (
azure
) - Google Cloud Platform (
gcp
) - Alibaba Cloud (
alibaba
) - OpenStack (
openstack
) - DigitalOcean (
digitalocean
) - Oracle Cloud Infrastructure (
oci
) - Vultr (
vultr
)
- Amazon Web Services (
- Fast, simple and extensible.
- Real-time logging in the console.
OpenSSL 1.0.1, 1.0.2, 1.1.0, or 1.1.1 with headers (see https://github.com/sfackler/rust-openssl)
$ sudo apt-get install pkg-config libssl-dev
$ sudo dnf install pkg-config perl-FindBin openssl-devel
OR
$ sudo yum install pkg-config perl-FindBin openssl-devel
$ sudo zypper in pkg-config libopenssl-devel
$ sudo pacman -S pkg-config openssl
First, add the library to your project by adding the following to your Cargo.toml
file:
[dependencies]
cloud-detect = "1.0.0"
tokio = { version = "1.29.1", features = ["full"] }
tracing-subscriber = "0.3.17" # Only needed if real-time logging is required.
Next, you can detect the current host's cloud provider as follows:
use cloud_detect::detect;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init(); // Only needed if real-time logging is required.
// With default timeout (5 seconds).
let provider = detect(None).await;
// With custom timeout.
let provider = detect(Some(1)).await; // 1 second.
// 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.
use cloud_detect::SUPPORTED_PROVIDERS;
#[tokio::main]
async fn main() {
println!("{}", SUPPORTED_PROVIDERS.join(", "));
}
NOTE: Currently, only asynchronous detection is supported. Blocking detection may be added to a future release.
TODO