Crates.io | nile-client-rs |
lib.rs | nile-client-rs |
version | 0.0.5 |
source | src |
created_at | 2023-01-03 22:24:24.95824 |
updated_at | 2023-04-04 21:31:06.171175 |
description | A Rust client for the thenile.dev/ |
homepage | https://www.coredb.io |
repository | |
max_upload_size | |
id | 750460 |
size | 288,319 |
This is a POC Rust client for the Nile API.
Source the Nile environment variables into your environment.
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);
}