Giter Club home page Giter Club logo

cloud-detect's Introduction

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

cloud-detect's People

Contributors

nikhil-prabhu avatar

Stargazers

 avatar

Watchers

 avatar

cloud-detect's Issues

Add tests

The crate is currently manually tested for correctness. While manual testing is required in our case to ensure that the providers are correctly detected in real-world scenarios, unit tests should also be added for testing functional and logical correctness.

Current blockers

  • The methods that check the provider metadata servers make real HTTP requests to third party URLs. We need a way to mock/patch this as these requests won't work in unit tests.
  • The methods that check the provider vendor files must be mocked/patched as the vendor files won't actually exist in our test environment.
  • mockall seems like a good option for now for mocking. However, writing unit tests using mocks doesn't provide code coverage.
  • guerrilla seems promising for monkey patching our methods (and also provides code coverage), but doesn't seem to be working fully as expected in my limited testing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.