11 releases (6 stable)
new 2.1.1 | Jan 5, 2025 |
---|---|
2.0.1 | Dec 20, 2024 |
1.1.0 | Nov 7, 2023 |
0.5.0 | Aug 9, 2023 |
#390 in Web programming
253 downloads per month
115KB
2.5K
SLoC
cloud-detect
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.
Features
- Currently, this module 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 console logging using the
tracing
crate.
Usage
First, add the library to your project by adding the following to your Cargo.toml
file:
[dependencies]
# ...
cloud-detect = "2"
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 = "2", 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.
Contributing
Contributions are welcome and greatly appreciated! If you’d like to contribute to cloud-detect, here’s how you can help.
1. Report Issues
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.
2. Submit Pull Requests
If you're submitting a pull request, please ensure the following.
- Your code is formatted using
cargo fmt
(the Rustnightly
channel 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 --workspace
3. Improve Documentation
If 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.
4. Review Pull Requests
You can also contribute by reviewing open pull requests. Providing constructive feedback helps maintain a high-quality codebase.
Dependencies
~7–18MB
~241K SLoC