Skip to content

nikhil-prabhu/cloud-detect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.2", features = ["env-filter"] }# Optional; for logging.

Detect the cloud provider and print the result (with default timeout).

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 custom timeout).

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"
}

You can also check the list of currently supported cloud providers.

use cloud_detect::supported_providers;

#[tokio::main]
async fn main() {
    println!("Supported providers: {:?}", supported_providers.await);
}

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.