fix rfsclient rhai example and update docs

This commit is contained in:
Sameh Abouel-saad
2025-08-27 22:29:25 +03:00
parent c2969621b1
commit 536779f521
2 changed files with 27 additions and 30 deletions

View File

@@ -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.