change context syntax
This commit is contained in:
@@ -12,7 +12,7 @@ The example involves three key participants:
|
||||
|
||||
3. **Charlie (`charlie_pk`)**: An unauthorized user. He attempts to run `charlie.rhai`, which is identical to Bob's script.
|
||||
|
||||
The core of the access control mechanism lies within the `rhailib_worker`. When a script is submitted for execution, the worker automatically enforces that the `CALLER_PUBLIC_KEY` matches the worker's own `CIRCLE_PUBLIC_KEY` for any write operations. This ensures that only the owner (Alice) can modify her data.
|
||||
The core of the access control mechanism lies within the `rhailib_worker`. When a script is submitted for execution, the worker automatically enforces that the `CALLER_ID` matches the worker's own `CONTEXT_ID` for any write operations. This ensures that only the owner (Alice) can modify her data.
|
||||
|
||||
## Scenario and Expected Outcomes
|
||||
|
||||
|
@@ -31,7 +31,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
shutdown_rx,
|
||||
false, // use_sentinel
|
||||
));
|
||||
|
||||
|
||||
log::info!("Rhai worker spawned for circle: {}", ALICE_ID);
|
||||
|
||||
// Give the worker a moment to start up
|
||||
@@ -44,12 +44,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
client_alice.new_play_request()
|
||||
.recipient_id(&ALICE_ID)
|
||||
client_alice
|
||||
.new_play_request()
|
||||
.worker_id(&ALICE_ID)
|
||||
.context_id(&ALICE_ID)
|
||||
.script_path("examples/access_control/alice.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Alice's database populated.");
|
||||
|
||||
// Bob queries Alice's rhai worker
|
||||
@@ -58,13 +62,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.caller_id(BOB_ID)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
client_bob.new_play_request()
|
||||
.recipient_id(&ALICE_ID)
|
||||
|
||||
client_bob
|
||||
.new_play_request()
|
||||
.worker_id(&ALICE_ID)
|
||||
.context_id(&ALICE_ID)
|
||||
.script_path("examples/access_control/bob.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Bob's query to Alice's database completed.");
|
||||
|
||||
// Charlie queries Alice's rhai worker
|
||||
@@ -73,16 +81,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.caller_id(CHARLIE_ID)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
client_charlie.new_play_request()
|
||||
.recipient_id(&ALICE_ID)
|
||||
|
||||
client_charlie
|
||||
.new_play_request()
|
||||
.worker_id(&ALICE_ID)
|
||||
.context_id(&ALICE_ID)
|
||||
.script_path("examples/access_control/charlie.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Charlie's query to Alice's database completed.");
|
||||
|
||||
|
||||
// Spawn the Rhai worker for Alice's and Charlie's circle
|
||||
let engine = rhailib_engine::create_heromodels_engine();
|
||||
let (shutdown_tx, shutdown_rx) = mpsc::channel(1);
|
||||
@@ -102,41 +113,52 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
client_circle.new_play_request()
|
||||
.recipient_id(&CIRCLE_ID)
|
||||
client_circle
|
||||
.new_play_request()
|
||||
.worker_id(&CIRCLE_ID)
|
||||
.context_id(&CIRCLE_ID)
|
||||
.script_path("examples/access_control/circle.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Circles's database populated.");
|
||||
|
||||
// Give the worker a moment to start up
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
// Give the worker a moment to start up
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
// Alice queries the rhai worker of their circle with Charlie.
|
||||
client_alice.new_play_request()
|
||||
.recipient_id(&CIRCLE_ID)
|
||||
.script_path("examples/access_control/alice.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
// Alice queries the rhai worker of their circle with Charlie.
|
||||
client_alice
|
||||
.new_play_request()
|
||||
.worker_id(&CIRCLE_ID)
|
||||
.context_id(&CIRCLE_ID)
|
||||
.script_path("examples/access_control/alice.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Bob's query to Alice's database completed.");
|
||||
log::info!("Bob's query to Alice's database completed.");
|
||||
|
||||
// Charlie queries Alice's rhai worker
|
||||
let client_charlie = RhaiClientBuilder::new()
|
||||
.redis_url(REDIS_URL)
|
||||
.caller_id(CHARLIE_ID)
|
||||
.build()
|
||||
.unwrap();
|
||||
// Charlie queries Alice's rhai worker
|
||||
let client_charlie = RhaiClientBuilder::new()
|
||||
.redis_url(REDIS_URL)
|
||||
.caller_id(CHARLIE_ID)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
client_charlie.new_play_request()
|
||||
.recipient_id(&ALICE_ID)
|
||||
.script_path("examples/access_control/charlie.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response().await.unwrap();
|
||||
|
||||
log::info!("Charlie's query to Alice's database completed.");
|
||||
client_charlie
|
||||
.new_play_request()
|
||||
.worker_id(&ALICE_ID)
|
||||
.context_id(&ALICE_ID)
|
||||
.script_path("examples/access_control/charlie.rhai")
|
||||
.timeout(Duration::from_secs(10))
|
||||
.await_response()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
log::info!("Charlie's query to Alice's database completed.");
|
||||
|
||||
// 5. Shutdown the worker (optional, could also let it run until program exits)
|
||||
log::info!("Signaling worker to shutdown...");
|
||||
|
Reference in New Issue
Block a user