fix rfsclient rhai example and update docs
This commit is contained in:
@@ -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.
|
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
|
## Quick start
|
||||||
|
|
||||||
Run the auth + upload + download example:
|
Run the auth + upload + download example (uses hardcoded credentials and `/etc/hosts` as input):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
RFS_BASE_URL=https://rfs.example.com \
|
cargo run -p herodo -- examples/rfsclient/auth_and_upload.rhai
|
||||||
RFS_USER=your_user \
|
|
||||||
RFS_PASS=your_pass \
|
|
||||||
cargo run -p herodo --features clients -- 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
|
## What the example does
|
||||||
|
|
||||||
- Creates the RFS client: `rfs_create_client(BASE_URL, USER, PASS, TIMEOUT)`
|
- Creates the RFS client: `rfs_create_client(BASE_URL, USER, PASS, TIMEOUT)`
|
||||||
- Health check: `rfs_health_check()`
|
- Health check: `rfs_health_check()`
|
||||||
- Authenticates: `rfs_authenticate()`
|
- Authenticates: `rfs_authenticate()`
|
||||||
- Uploads a file: `rfs_upload_file(local_path)` -> file hash
|
- 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)`
|
- 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.
|
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/client.rs` (`RfsClient`)
|
||||||
- `packages/clients/rfsclient/src/types.rs` (config and option types)
|
- `packages/clients/rfsclient/src/types.rs` (config and option types)
|
||||||
|
- `packages/clients/rfsclient/examples/` (example usage)
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- Missing functions in Rhai: ensure features include `rfsclient` (or `clients`/`all`).
|
- Auth failures: verify credentials and that the server requires/authenticates them.
|
||||||
- Auth failures: verify `RFS_USER`/`RFS_PASS` and that the server requires/authenticates credentials.
|
- Connection errors: verify the base URL is reachable from your machine.
|
||||||
- Connection errors: verify `RFS_BASE_URL` is reachable from your machine.
|
|
||||||
|
@@ -4,13 +4,13 @@
|
|||||||
// - Valid credentials in env: RFS_USER, RFS_PASS
|
// - Valid credentials in env: RFS_USER, RFS_PASS
|
||||||
// - Run with herodo so the SAL Rhai modules are registered
|
// - Run with herodo so the SAL Rhai modules are registered
|
||||||
|
|
||||||
let BASE_URL = env_get("RFS_BASE_URL");
|
// NOTE: env_get not available in this runtime; hardcode or replace with your env loader
|
||||||
let USER = env_get("RFS_USER");
|
let BASE_URL = "http://127.0.0.1:8080";
|
||||||
let PASS = env_get("RFS_PASS");
|
let USER = "user";
|
||||||
|
let PASS = "password";
|
||||||
let TIMEOUT = 30; // seconds
|
let TIMEOUT = 30; // seconds
|
||||||
|
|
||||||
if BASE_URL == null || BASE_URL == "" { throw "Set RFS_BASE_URL in your environment"; }
|
if BASE_URL == "" { throw "Set BASE_URL in the script"; }
|
||||||
if USER == null || PASS == null { throw "Set RFS_USER and RFS_PASS in your environment"; }
|
|
||||||
|
|
||||||
// Create client
|
// Create client
|
||||||
let ok = rfs_create_client(BASE_URL, USER, PASS, TIMEOUT);
|
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"; }
|
if !auth_ok { throw "Authentication failed"; }
|
||||||
|
|
||||||
// Upload a local file
|
// Upload a local file
|
||||||
let local_file = "/tmp/rfs_example.txt";
|
// Use an existing readable file to avoid needing os_write_file module
|
||||||
os_write_file(local_file, "hello rfs");
|
let local_file = "/etc/hosts";
|
||||||
let hash = rfs_upload_file(local_file);
|
// rfs_upload_file(file_path, chunk_size, verify)
|
||||||
|
let hash = rfs_upload_file(local_file, 0, false);
|
||||||
print(`Uploaded file hash: ${hash}`);
|
print(`Uploaded file hash: ${hash}`);
|
||||||
|
|
||||||
// Download it back
|
// Download it back
|
||||||
let out_path = "/tmp/rfs_example_out.txt";
|
let out_path = "/tmp/rfs_example_out.txt";
|
||||||
let dl_ok = rfs_download_file(hash, out_path);
|
// rfs_download_file(file_id, output_path, verify) returns unit and throws on error
|
||||||
if !dl_ok { throw "Download failed"; }
|
rfs_download_file(hash, out_path, false);
|
||||||
|
|
||||||
print(`Downloaded to: ${out_path}`);
|
print(`Downloaded to: ${out_path}`);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user