holochain_conductor_api/config/
interface.rs

1use holochain_types::websocket::AllowedOrigins;
2use schemars::JsonSchema;
3use serde::Deserialize;
4use serde::Serialize;
5
6/// Information neeeded to spawn an admin interface
7#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, JsonSchema)]
8pub struct AdminInterfaceConfig {
9    /// By what means the interface will be exposed.
10    /// Currently the only option is a local websocket running on a configurable port.
11    pub driver: InterfaceDriver,
12}
13
14/// Configuration for interfaces, specifying the means by which an interface
15/// should be opened.
16///
17/// **NB**: This struct is used in both [`ConductorConfig`]
18/// and [`ConductorState`],
19/// so any change to the serialization strategy is a breaking change.
20///
21/// [`ConductorConfig`]: crate::conductor::ConductorConfig
22/// [`ConductorState`]: https://docs.rs/holochain/latest/holochain/conductor/state/struct.ConductorState.html
23#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, JsonSchema)]
24#[serde(tag = "type", rename_all = "snake_case")]
25pub enum InterfaceDriver {
26    /// An interface implemented via websockets
27    Websocket {
28        /// The port on which to establish the WebsocketListener
29        port: u16,
30
31        /// Allowed origins for this interface.
32        ///
33        /// This should be one of:
34        /// - A comma separated list of origins - `http://localhost:3000,http://localhost:3001`,
35        /// - A single origin - `http://localhost:3000`,
36        /// - Any origin - `*`
37        ///
38        /// Connections from any origin which is not permitted by this config will be rejected.
39        allowed_origins: AllowedOrigins,
40    },
41}
42
43impl InterfaceDriver {
44    /// Get the port for this driver.
45    pub fn port(&self) -> u16 {
46        match self {
47            InterfaceDriver::Websocket { port, .. } => *port,
48        }
49    }
50
51    /// Get the allowed origins for this driver.
52    pub fn allowed_origins(&self) -> &AllowedOrigins {
53        match self {
54            InterfaceDriver::Websocket {
55                allowed_origins, ..
56            } => allowed_origins,
57        }
58    }
59}