Skip to content

Commit

Permalink
refactor(rust): propagate the async constraint when using an in-memor…
Browse files Browse the repository at this point in the history
…y repository
  • Loading branch information
etorreborre committed Nov 22, 2023
1 parent da59d08 commit 4ab99ce
Show file tree
Hide file tree
Showing 99 changed files with 358 additions and 295 deletions.
2 changes: 1 addition & 1 deletion examples/rust/example_projects/no_std/examples/01-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use ockam::{node, Context, Result};

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Stop the node as soon as it starts.
info!("Stop the node as soon as it starts.");
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/example_projects/no_std/examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use ockam::{node, route, Context, Result};

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let mut node = node(ctx);
let mut node = node(ctx).await?;
let bob = node.create_identity().await?;

// Create a secure channel listener for Bob that will wait for requests to
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/file_transfer/examples/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Worker for FileReception {

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Create an Identity to represent Receiver.
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/file_transfer/examples/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Opt {
async fn main(ctx: Context) -> Result<()> {
let opt = Opt::from_args();

let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Create an Identity to represent Sender.
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/01-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main(ctx: Context) -> Result<()> {
print_title(vec!["Run a node & stop it right away"]);

// Create a node.
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Stop the node as soon as it starts.
node.stop().await
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/02-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam::{node, Context, Result};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Start a worker, of type Echoer, at address "echoer"
node.start_worker("echoer", Echoer).await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/03-routing-many-hops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam::{node, route, Context, Result};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Start an Echoer worker at address "echoer"
node.start_worker("echoer", Echoer).await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/03-routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam::{node, route, Context, Result};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Start a worker, of type Echoer, at address "echoer"
node.start_worker("echoer", Echoer).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ockam::{node, route, Context, Result, TcpConnectionOptions, TcpTransportExte
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Initialize the TCP Transport.
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ockam::{node, Context, Result, TcpListenerOptions, TcpTransportExtension};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ockam::{node, route, Context, Result, TcpConnectionOptions, TcpTransportExte
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, Tcp
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ockam::{node, Context, Result, TcpListenerOptions, TcpTransportExtension};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam_transport_udp::{UdpTransportExtension, UDP};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Initialize the UDP Transport
let _udp = node.create_udp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ockam_transport_udp::UdpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the UDP Transport
let udp = node.create_udp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam_transport_uds::{UdsTransportExtension, UDS};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Initialize the UDS Transport
let uds = node.create_uds_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ockam_transport_uds::UdsTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the UDS Transport
let uds = node.create_uds_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ockam::{node, route, Context, Result, TcpConnectionOptions, TcpTransportExte
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Create an Identity to represent Alice.
let alice = node.create_identity().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, Tcp
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ockam::{node, Context, Result, TcpListenerOptions, TcpTransportExtension};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;

// Initialize the TCP Transport.
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ockam_vault::{EdDSACurve25519SecretKey, SigningSecret, SoftwareVaultForSigni

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let identity_vault = SoftwareVaultForSigning::create();
let identity_vault = SoftwareVaultForSigning::create().await?;
// Import the signing secret key to the Vault
let secret = identity_vault
.import_key(SigningSecret::EdDSACurve25519(EdDSACurve25519SecretKey::new(
Expand All @@ -21,10 +21,10 @@ async fn main(ctx: Context) -> Result<()> {
.await?;

// Create a default Vault but use the signing vault with our secret in it
let mut vault = Vault::create();
let mut vault = Vault::create().await?;
vault.identity_vault = identity_vault;

let mut node = Node::builder().with_vault(vault).build(&ctx).await?;
let mut node = Node::builder().await?.with_vault(vault).build(&ctx).await?;
// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use ockam::{Context, Result, TcpListenerOptions};
use ockam::{Node, TcpTransportExtension};
use ockam::access_control::AllowAll;
use ockam::access_control::IdentityIdAccessControl;
use ockam::identity::SecureChannelListenerOptions;
use ockam::identity::{CredentialsIssuer, Vault};
use ockam::{Context, Result, TcpListenerOptions};
use ockam::{Node, TcpTransportExtension};
use ockam::identity::SecureChannelListenerOptions;
use ockam_api::DefaultAddress;
use ockam_vault::{EdDSACurve25519SecretKey, SigningSecret, SoftwareVaultForSigning};

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let identity_vault = SoftwareVaultForSigning::create();
let identity_vault = SoftwareVaultForSigning::create().await?;
// Import the signing secret key to the Vault
let secret = identity_vault
.import_key(SigningSecret::EdDSACurve25519(EdDSACurve25519SecretKey::new(
Expand All @@ -21,10 +21,10 @@ async fn main(ctx: Context) -> Result<()> {
.await?;

// Create a default Vault but use the signing vault with our secret in it
let mut vault = Vault::create();
let mut vault = Vault::create().await?;
vault.identity_vault = identity_vault;

let node = Node::builder().with_vault(vault).build(&ctx).await?;
let node = Node::builder().await?.with_vault(vault).build(&ctx).await?;

let issuer_identity = hex::decode("81a201583ba20101025835a4028201815820afbca9cf5d440147450f9f0d0a038a337b3fe5c17086163f2c54509558b62ef403f4041a64dd404a051a77a9434a0282018158407754214545cda6e7ff49136f67c9c7973ec309ca4087360a9f844aac961f8afe3f579a72c0c9530f3ff210f02b7c5f56e96ce12ee256b01d7628519800723805").unwrap();
let issuer = node.import_private_identity(None, &issuer_identity, &secret).await?;
Expand Down Expand Up @@ -82,7 +82,7 @@ async fn main(ctx: Context) -> Result<()> {
allow_known,
AllowAll,
)
.await?;
.await?;

// Initialize TCP Transport, create a TCP listener, and wait for connections.
let tcp = node.create_tcp_transport().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ockam_vault::{EdDSACurve25519SecretKey, SigningSecret, SoftwareVaultForSigni

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let identity_vault = SoftwareVaultForSigning::create();
let identity_vault = SoftwareVaultForSigning::create().await?;
// Import the signing secret key to the Vault
let secret = identity_vault
.import_key(SigningSecret::EdDSACurve25519(EdDSACurve25519SecretKey::new(
Expand All @@ -26,10 +26,10 @@ async fn main(ctx: Context) -> Result<()> {
.await?;

// Create a default Vault but use the signing vault with our secret in it
let mut vault = Vault::create();
let mut vault = Vault::create().await?;
vault.identity_vault = identity_vault;

let node = Node::builder().with_vault(vault).build(&ctx).await?;
let node = Node::builder().await?.with_vault(vault).build(&ctx).await?;

// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/09-streams-initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ockam_transport_tcp::TcpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Set the address of the Kafka node you created here. (e.g. "192.0.2.1:4000")
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/09-streams-responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ockam_transport_tcp::TcpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Start an echoer worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ockam_transport_tcp::TcpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Set the address of the Kafka node you created here. (e.g. "192.0.2.1:4000")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ockam_transport_tcp::TcpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Start an echoer worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn main(ctx: Context) -> Result<()> {
/// start the control node
async fn start_node(ctx: Context, project_information_path: &str, token: OneTimeCode) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;
// Initialize the TCP transport
let tcp = node.create_tcp_transport().await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn main(ctx: Context) -> Result<()> {
/// start the edge node
async fn start_node(ctx: Context, project_information_path: &str, token: OneTimeCode) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;
// Use the TCP transport
let tcp = node.create_tcp_transport().await?;

Expand Down Expand Up @@ -107,8 +107,11 @@ async fn start_node(ctx: Context, project_information_path: &str, token: OneTime
.await?;

// 3. create an access control policy checking the value of the "component" attribute of the caller
let access_control =
AbacAccessControl::create(identities().identity_attributes_repository(), "component", "control");
let access_control = AbacAccessControl::create(
identities().await?.identity_attributes_repository(),
"component",
"control",
);

// 4. create a tcp inlet with the above policy

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/alice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;
// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/bob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Worker for Echoer {
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let node = node(ctx);
let node = node(ctx).await?;
// Initialize the TCP Transport
let tcp = node.create_tcp_transport().await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ockam::{node, route, Context, Result};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create a node with default implementations
let mut node = node(ctx);
let mut node = node(ctx).await?;
// Create an Identity to represent Bob
let bob = node.create_identity().await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/get_started/examples/vault-and-identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ockam::{Context, Result};
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Create default node to safely store secret keys for Alice
let mut node = node(ctx);
let mut node = node(ctx).await?;

// Create an Identity to represent Alice.
let _alice = node.create_identity().await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/ockam_kafka/examples/ockam_kafka_alice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Initialize the TCP Transport.
let mut node = node(ctx);
let mut node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Create an Identity to represent Alice.
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/ockam_kafka/examples/ockam_kafka_bob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Worker for Echoer {
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Initialize the TCP Transport.
let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Create an Identity to represent Bob.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ockam_transport_tcp::TcpTransportExtension;
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
// Initialize the TCP Transport.
let node = node(ctx);
let node = node(ctx).await?;
let tcp = node.create_tcp_transport().await?;

// Expect second command line argument to be the TCP address of a target TCP server.
Expand Down
Loading

0 comments on commit 4ab99ce

Please sign in to comment.