7 个版本 (2 个稳定版本)
1.1.0 | 2023年11月7日 |
---|---|
1.0.0 | 2023年11月4日 |
0.5.0 | 2023年8月9日 |
0.4.0 | 2023年8月8日 |
0.1.0 | 2023年8月7日 |
#2053 在 网络编程
每月37次下载
48KB
491 行
cloud-detect
Rust 库,用于检测主机的云服务提供商。
此库深受 Python cloud-detect 模块的启发,并复制了其大部分功能(甚至代码结构也相似)。
功能
- 支持以下提供商的识别
- 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 (
- 快速、简单且可扩展。
- 控制台实时记录。
要求
Linux
OpenSSL 1.0.1、1.0.2、1.1.0 或 1.1.1 与头文件(见 https://github.com/sfackler/rust-openssl)
Ubuntu 和 Debian 发行版
$ sudo apt-get install pkg-config libssl-dev
Fedora 和 RHEL 发行版
$ sudo dnf install pkg-config perl-FindBin openssl-devel
或者
$ sudo yum install pkg-config perl-FindBin openssl-devel
SLES 和 openSUSE
$ sudo zypper in pkg-config libopenssl-devel
Arch Linux
$ sudo pacman -S pkg-config openssl
用法
首先,通过将以下内容添加到您的 Cargo.toml
文件将库添加到您的项目中
[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.
然后,您可以通过以下方式检测当前主机的云提供商
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"
}
您还可以检查当前支持的云提供商列表。
use cloud_detect::SUPPORTED_PROVIDERS;
#[tokio::main]
async fn main() {
println!("{}", SUPPORTED_PROVIDERS.join(", "));
}
注意:当前仅支持异步检测。可能会在未来版本中添加阻塞检测。
贡献
待办事项
依赖关系
~6–18MB
~278K SLoC