diff --git a/examples/rfsclient/README.md b/examples/rfsclient/README.md index 6c78270..c71936e 100644 --- a/examples/rfsclient/README.md +++ b/examples/rfsclient/README.md @@ -2,34 +2,30 @@ This folder contains Rhai examples that use the SAL RFS client wrappers registered by `sal::rhai::register(&mut engine)` and executed by the `herodo` binary. -## Prerequisites - -- Build with the client feature enabled (any of these): - - `--features rfsclient` - - `--features clients` - - `--features all` -- Environment variables: - - `RFS_BASE_URL` (e.g., `https://rfs.example.com`) - - `RFS_USER` and `RFS_PASS` - ## Quick start -Run the auth + upload + download example: +Run the auth + upload + download example (uses hardcoded credentials and `/etc/hosts` as input): ```bash -RFS_BASE_URL=https://rfs.example.com \ -RFS_USER=your_user \ -RFS_PASS=your_pass \ -cargo run -p herodo --features clients -- examples/rfsclient/auth_and_upload.rhai +cargo run -p herodo -- examples/rfsclient/auth_and_upload.rhai ``` +By default, the script: + +- Uses base URL `http://127.0.0.1:8080` +- Uses credentials `user` / `password` +- Uploads the file `/etc/hosts` +- Downloads to `/tmp/rfs_example_out.txt` + +To customize, edit `examples/rfsclient/auth_and_upload.rhai` near the top and change `BASE_URL`, `USER`, `PASS`, and file paths. + ## What the example does - Creates the RFS client: `rfs_create_client(BASE_URL, USER, PASS, TIMEOUT)` - Health check: `rfs_health_check()` - Authenticates: `rfs_authenticate()` -- Uploads a file: `rfs_upload_file(local_path)` -> file hash -- Downloads it back: `rfs_download_file(file_id_or_hash, dest_path)` +- Uploads a file: `rfs_upload_file(local_path, chunk_size, verify)` → returns file hash +- Downloads it back: `rfs_download_file(file_id_or_hash, dest_path, verify)` → returns unit (throws on error) See `examples/rfsclient/auth_and_upload.rhai` for details. @@ -39,9 +35,9 @@ If you want to use the Rust API (without Rhai), depend on `sal-rfs-client` and s - `packages/clients/rfsclient/src/client.rs` (`RfsClient`) - `packages/clients/rfsclient/src/types.rs` (config and option types) +- `packages/clients/rfsclient/examples/` (example usage) ## Troubleshooting -- Missing functions in Rhai: ensure features include `rfsclient` (or `clients`/`all`). -- Auth failures: verify `RFS_USER`/`RFS_PASS` and that the server requires/authenticates credentials. -- Connection errors: verify `RFS_BASE_URL` is reachable from your machine. +- Auth failures: verify credentials and that the server requires/authenticates them. +- Connection errors: verify the base URL is reachable from your machine. diff --git a/examples/rfsclient/auth_and_upload.rhai b/examples/rfsclient/auth_and_upload.rhai index 46d8879..b400f55 100644 --- a/examples/rfsclient/auth_and_upload.rhai +++ b/examples/rfsclient/auth_and_upload.rhai @@ -4,13 +4,13 @@ // - Valid credentials in env: RFS_USER, RFS_PASS // - Run with herodo so the SAL Rhai modules are registered -let BASE_URL = env_get("RFS_BASE_URL"); -let USER = env_get("RFS_USER"); -let PASS = env_get("RFS_PASS"); +// NOTE: env_get not available in this runtime; hardcode or replace with your env loader +let BASE_URL = "http://127.0.0.1:8080"; +let USER = "user"; +let PASS = "password"; let TIMEOUT = 30; // seconds -if BASE_URL == null || BASE_URL == "" { throw "Set RFS_BASE_URL in your environment"; } -if USER == null || PASS == null { throw "Set RFS_USER and RFS_PASS in your environment"; } +if BASE_URL == "" { throw "Set BASE_URL in the script"; } // Create client let ok = rfs_create_client(BASE_URL, USER, PASS, TIMEOUT); @@ -25,15 +25,16 @@ let auth_ok = rfs_authenticate(); if !auth_ok { throw "Authentication failed"; } // Upload a local file -let local_file = "/tmp/rfs_example.txt"; -os_write_file(local_file, "hello rfs"); -let hash = rfs_upload_file(local_file); +// Use an existing readable file to avoid needing os_write_file module +let local_file = "/etc/hosts"; +// rfs_upload_file(file_path, chunk_size, verify) +let hash = rfs_upload_file(local_file, 0, false); print(`Uploaded file hash: ${hash}`); // Download it back let out_path = "/tmp/rfs_example_out.txt"; -let dl_ok = rfs_download_file(hash, out_path); -if !dl_ok { throw "Download failed"; } +// rfs_download_file(file_id, output_path, verify) returns unit and throws on error +rfs_download_file(hash, out_path, false); print(`Downloaded to: ${out_path}`);