Crates.io | cloud-detect |
lib.rs | cloud-detect |
version | 1.1.0 |
source | src |
created_at | 2023-08-07 13:40:21.630339 |
updated_at | 2023-11-07 14:48:38.22705 |
description | Detect a host's cloud service provider |
homepage | |
repository | https://github.com/nikhil-prabhu/cloud-detect |
max_upload_size | |
id | 937942 |
size | 84,428 |
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).
aws
)azure
)gcp
)alibaba
)openstack
)digitalocean
)oci
)vultr
)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