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

Download history 2/week @ 2024-09-18 2/week @ 2024-09-25 1/week @ 2024-10-09 1/week @ 2024-10-16 1/week @ 2024-10-30 1/week @ 2024-11-06 112/week @ 2024-12-11 141/week @ 2024-12-18

253 downloads per month

GPL-3.0 license

115KB
2.5K SLoC

cloud-detect

maintenance-status crates-badge License: GPL v3 CI CD

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)
  • 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 Rust nightly 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