Skip to main content

flow_domain/
connection.rs

1use serde::{Deserialize, Serialize};
2
3/// Connection profile metadata. Secrets (password / token) live in the OS
4/// keyring under `flow-security`'s `zowe:<id>` account; this struct only
5/// carries non-secret fields.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ConnectionProfile {
8    pub id: String,
9    pub name: String,
10    /// Connection type - `"zosmf"` is the only one supported in v1; reserved
11    /// for `"ssh"`, `"db2"`, etc. as adapters land.
12    #[serde(rename = "type")]
13    pub kind: String,
14    pub host: String,
15    pub port: u16,
16    pub user: String,
17    /// `"https"` (default) or `"http"` for plaintext zosmf endpoints.
18    #[serde(default = "default_protocol")]
19    pub protocol: String,
20    /// When false, refuse to connect over TLS to a server with a self-signed
21    /// or otherwise untrusted certificate. Defaults to `true` for safety;
22    /// users who need to talk to internal LPARs with self-signed certs flip it.
23    #[serde(default = "default_reject_unauthorized", rename = "rejectUnauthorized")]
24    pub reject_unauthorized: bool,
25}
26
27fn default_protocol() -> String {
28    "https".into()
29}
30
31fn default_reject_unauthorized() -> bool {
32    true
33}
34
35impl ConnectionProfile {
36    pub fn new_zosmf(
37        id: impl Into<String>,
38        name: impl Into<String>,
39        host: impl Into<String>,
40        port: u16,
41        user: impl Into<String>,
42    ) -> Self {
43        Self {
44            id: id.into(),
45            name: name.into(),
46            kind: "zosmf".into(),
47            host: host.into(),
48            port,
49            user: user.into(),
50            protocol: "https".into(),
51            reject_unauthorized: true,
52        }
53    }
54}