linera_service/cli_wrappers/
mod.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Helper module to call the binaries of `linera-service` with appropriate command-line
5//! arguments.
6
7#[cfg(feature = "kubernetes")]
8/// How to run Docker operations
9pub mod docker;
10
11#[cfg(feature = "kubernetes")]
12/// How to run helmfile operations
13mod helmfile;
14#[cfg(feature = "kubernetes")]
15/// How to run kind operations
16mod kind;
17#[cfg(feature = "kubernetes")]
18/// How to run `kubectl` operations
19mod kubectl;
20#[cfg(feature = "kubernetes")]
21/// How to run Linera validators locally as a Kubernetes deployment.
22pub mod local_kubernetes_net;
23/// How to run Linera validators locally as native processes.
24pub mod local_net;
25#[cfg(all(with_testing, feature = "remote-net"))]
26/// How to connect to running GCP devnet.
27pub mod remote_net;
28#[cfg(feature = "kubernetes")]
29/// Utility functions for the wrappers
30mod util;
31/// How to run a Linera wallet and its GraphQL service.
32mod wallet;
33
34use anyhow::Result;
35use async_trait::async_trait;
36pub use linera_faucet_client::Faucet;
37#[cfg(with_testing)]
38pub use wallet::NotificationsExt;
39pub use wallet::{ApplicationWrapper, ClientWrapper, FaucetService, NodeService, OnClientDrop};
40
41/// The information needed to start a Linera net of a particular kind.
42#[async_trait]
43pub trait LineraNetConfig {
44    type Net: LineraNet + Sized + Send + Sync + 'static;
45
46    async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)>;
47}
48
49/// A running Linera net.
50#[async_trait]
51pub trait LineraNet {
52    async fn ensure_is_running(&mut self) -> Result<()>;
53
54    async fn make_client(&mut self) -> ClientWrapper;
55
56    async fn terminate(&mut self) -> Result<()>;
57}
58
59/// Network protocol in use
60#[derive(Copy, Clone)]
61pub enum Network {
62    Grpc,
63    Grpcs,
64    Tcp,
65    Udp,
66}
67
68/// Network protocol in use outside and inside a Linera net.
69#[derive(Copy, Clone)]
70pub struct NetworkConfig {
71    /// The internal network (e.g. proxy to validator)
72    pub internal: Network,
73    /// The external network (e.g. proxy to the exterior)
74    pub external: Network,
75}
76
77impl Network {
78    fn toml(&self) -> &'static str {
79        match self {
80            Network::Grpc => "{ Grpc = \"ClearText\" }",
81            Network::Grpcs => "{ Grpc = \"Tls\" }",
82            Network::Tcp => "{ Simple = \"Tcp\" }",
83            Network::Udp => "{ Simple = \"Udp\" }",
84        }
85    }
86
87    pub fn short(&self) -> &'static str {
88        match self {
89            Network::Grpc => "grpc",
90            Network::Grpcs => "grpcs",
91            Network::Tcp => "tcp",
92            Network::Udp => "udp",
93        }
94    }
95
96    pub fn drop_tls(&self) -> Self {
97        match self {
98            Network::Grpc => Network::Grpc,
99            Network::Grpcs => Network::Grpc,
100            Network::Tcp => Network::Tcp,
101            Network::Udp => Network::Udp,
102        }
103    }
104
105    pub fn localhost(&self) -> &'static str {
106        match self {
107            Network::Grpc | Network::Grpcs => "localhost",
108            Network::Tcp | Network::Udp => "127.0.0.1",
109        }
110    }
111
112    /// Returns the protocol schema to use in the node address tuple.
113    pub fn schema(&self) -> &'static str {
114        match self {
115            Network::Grpc | Network::Grpcs => "grpc",
116            Network::Tcp => "tcp",
117            Network::Udp => "udp",
118        }
119    }
120}