cloud-detect

Crates.iocloud-detect
lib.rscloud-detect
version1.1.0
sourcesrc
created_at2023-08-07 13:40:21.630339
updated_at2023-11-07 14:48:38.22705
descriptionDetect a host's cloud service provider
homepage
repositoryhttps://github.com/nikhil-prabhu/cloud-detect
max_upload_size
id937942
size84,428
Nikhil Prabhu (nikhil-prabhu)

documentation

https://docs.rs/cloud-detect

README

cloud-detect

maintenance-status crates-badge License: GPL v3

Pylon Logo

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

Features

  • 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 logging in the console.

Requirements

Linux

OpenSSL 1.0.1, 1.0.2, 1.1.0, or 1.1.1 with headers (see https://github.com/sfackler/rust-openssl)

Ubuntu and Debian-based distributions

$ sudo apt-get install pkg-config libssl-dev

Fedora and RHEL-based distributions

$ sudo dnf install pkg-config perl-FindBin openssl-devel

OR

$ sudo yum install pkg-config perl-FindBin openssl-devel

SLES and openSUSE

$ sudo zypper in pkg-config libopenssl-devel

Arch Linux

$ sudo pacman -S pkg-config openssl

Usage

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.

Contributing

TODO

Commit count: 57

cargo fmt