8 个版本

0.0.5 2023 年 4 月 4 日
0.0.4 2023 年 3 月 24 日
0.0.2 2023 年 1 月 28 日

#365 in 网络编程

MIT 许可证

195KB
4K SLoC

Nile API Rust 客户端

这是一个 Nile API 的 Rust 版本 POC 客户端。

使用方法

将 Nile 环境变量源码导入您的环境。

export NILE_DEVELOPER_EMAIL=
export NILE_DEVELOPER_PASSWORD=
export NILE_ENTITY_NAME=
export NILE_ORGANIZATION_NAME=
export NILE_WORKSPACE=
export NILE_INSTANCE_ID=

NILE_URL=https://prod.thenile.dev
use std::env;

use dotenv::dotenv;
use nile_client_rs::{EntityInstance, InstanceUpdate, NileClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let username = env::var("NILE_DEVELOPER_EMAIL").expect("NILE_DEVELOPER_EMAIL must be set");
    let password = env::var("NILE_DEVELOPER_PASSWORD").expect("NILE_DEVELOPER_PASSWORD must be set");
    let workspace = env::var("NILE_WORKSPACE").expect("NILE_WORKSPACE must be set");
    let entity_name = env::var("NILE_ENTITY_NAME").expect("NILE_ENTITY_NAME must be set");
    let org = env::var("NILE_ORGANIZATION_NAME").expect("NILE_ORGANIZATION_NAME must be set");


    let mut client = NileClient::default();
    client
        .authenticate(username, password)
        .await?;

列出工作空间中实体的所有实例

let instances = client.get_instances(&workspace, &entity_name).await?;
println!("instances: {:#?}", instances);

轮询工作空间中实体的所有事件

let events = client.get_events(&workspace, &entity_name, 0, 20).await?;
println!("events: {:#?}", events);

更新现有实例的属性

let mut updates = Vec::new();

// update the number of pods
let pod_ct = InstanceUpdate {
    op: "replace".to_owned(),
    path: "/numPods".to_owned(),
    value: "5".to_owned(),
};
updates.push(pod_ct);

// update database status
let status_update = InstanceUpdate {
    op: "replace".to_owned(),
    path: "/status".to_owned(),
    value: "Up".to_owned(),
};
updates.push(status_update);

// send the updates to the Nile
let status: EntityInstance = client
    .patch_instance(&workspace, &org, &entity_name, &instance_id, updates)
    .await?;
println!("status: {:#?}", status);
}

依赖项

~6–19MB
~271K SLoC