nile-client-rs

Crates.ionile-client-rs
lib.rsnile-client-rs
version0.0.5
sourcesrc
created_at2023-01-03 22:24:24.95824
updated_at2023-04-04 21:31:06.171175
descriptionA Rust client for the thenile.dev/
homepagehttps://www.coredb.io
repository
max_upload_size
id750460
size288,319
Adam Hendel (ChuckHend)

documentation

https://github.com/CoreDB-io/nile-client-rs

README

Nile API Rust Client

This is a POC Rust client for the Nile API.

Usage

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?;

List all instances of an entity in a workspace

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

Poll for all events for an entity in a workspace

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

Update attributes on an existing instance

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);
}

Commit count: 0

cargo fmt