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;
37pub use wallet::{ApplicationWrapper, ClientWrapper, FaucetService, NodeService, OnClientDrop};
38
39/// The information needed to start a Linera net of a particular kind.
40#[async_trait]
41pub trait LineraNetConfig {
42    type Net: LineraNet + Sized + Send + Sync + 'static;
43
44    async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)>;
45}
46
47/// A running Linera net.
48#[async_trait]
49pub trait LineraNet {
50    async fn ensure_is_running(&mut self) -> Result<()>;
51
52    async fn make_client(&mut self) -> ClientWrapper;
53
54    async fn terminate(&mut self) -> Result<()>;
55}
56
57/// Network protocol in use
58#[derive(Copy, Clone)]
59pub enum Network {
60    Grpc,
61    Grpcs,
62    Tcp,
63    Udp,
64}
65
66/// Network protocol in use outside and inside a Linera net.
67#[derive(Copy, Clone)]
68pub struct NetworkConfig {
69    /// The internal network (e.g. proxy to validator)
70    pub internal: Network,
71    /// The external network (e.g. proxy to the exterior)
72    pub external: Network,
73}
74
75impl Network {
76    fn toml(&self) -> &'static str {
77        match self {
78            Network::Grpc => "{ Grpc = \"ClearText\" }",
79            Network::Grpcs => "{ Grpc = \"Tls\" }",
80            Network::Tcp => "{ Simple = \"Tcp\" }",
81            Network::Udp => "{ Simple = \"Udp\" }",
82        }
83    }
84
85    pub fn short(&self) -> &'static str {
86        match self {
87            Network::Grpc => "grpc",
88            Network::Grpcs => "grpcs",
89            Network::Tcp => "tcp",
90            Network::Udp => "udp",
91        }
92    }
93
94    pub fn drop_tls(&self) -> Self {
95        match self {
96            Network::Grpc => Network::Grpc,
97            Network::Grpcs => Network::Grpc,
98            Network::Tcp => Network::Tcp,
99            Network::Udp => Network::Udp,
100        }
101    }
102
103    pub fn localhost(&self) -> &'static str {
104        match self {
105            Network::Grpc | Network::Grpcs => "localhost",
106            Network::Tcp | Network::Udp => "127.0.0.1",
107        }
108    }
109
110    /// Returns the protocol schema to use in the node address tuple.
111    pub fn schema(&self) -> &'static str {
112        match self {
113            Network::Grpc | Network::Grpcs => "grpc",
114            Network::Tcp => "tcp",
115            Network::Udp => "udp",
116        }
117    }
118}