reactive_graph_client/client/args/
connection.rs

1use clap::Parser;
2use reactive_graph_remotes_model::DEFAULT_ENDPOINT_DYNAMIC_GRAPH;
3use reactive_graph_remotes_model::DEFAULT_ENDPOINT_GRAPHQL;
4use reactive_graph_remotes_model::DEFAULT_ENDPOINT_PLUGIN;
5use reactive_graph_remotes_model::DEFAULT_ENDPOINT_RUNTIME;
6use reactive_graph_remotes_model::DEFAULT_HOSTNAME;
7use reactive_graph_remotes_model::DEFAULT_PORT;
8use reactive_graph_remotes_model::InstanceAddress;
9
10#[derive(Parser, Debug, Clone)]
11pub struct ClientConnectionArguments {
12    /// The hostname to connect to.
13    #[arg(long)]
14    client_hostname: Option<String>,
15
16    /// The port to connect to.
17    #[arg(long)]
18    client_port: Option<u16>,
19
20    /// If true, connects via HTTPS.
21    #[arg(long)]
22    client_secure: Option<bool>,
23
24    /// The endpoint to use.
25    #[arg(long)]
26    endpoint_graphql: Option<String>,
27
28    /// The endpoint to use.
29    #[arg(long)]
30    endpoint_dynamic_graph: Option<String>,
31
32    /// The endpoint to use.
33    #[arg(long)]
34    endpoint_runtime: Option<String>,
35
36    /// The endpoint to use.
37    #[arg(long)]
38    endpoint_plugins: Option<String>,
39
40    /// The authentication token.
41    #[arg(long)]
42    bearer: Option<String>,
43
44    /// Controls the use of certificate validation.
45    ///
46    /// Defaults to `false`.
47    ///
48    /// Warning: You should think very carefully before using this method. If
49    /// invalid certificates are trusted, *any* certificate for *any* site
50    /// will be trusted for use. This includes expired certificates. This
51    /// introduces significant vulnerabilities, and should only be used
52    /// as a last resort.
53    #[arg(long)]
54    danger_accept_invalid_certs: Option<bool>,
55
56    /// Controls the use of hostname verification.
57    ///
58    /// Defaults to `false`.
59    ///
60    /// Warning: You should think very carefully before you use this method. If
61    /// hostname verification is not used, any valid certificate for any
62    /// site will be trusted for use from any other. This introduces a
63    /// significant vulnerability to man-in-the-middle attacks.
64    danger_accept_invalid_hostnames: Option<bool>,
65}
66
67impl From<&ClientConnectionArguments> for InstanceAddress {
68    fn from(args: &ClientConnectionArguments) -> Self {
69        InstanceAddress::builder()
70            .hostname(args.client_hostname.clone().unwrap_or(DEFAULT_HOSTNAME.to_string()))
71            .port(args.client_port.unwrap_or(DEFAULT_PORT))
72            .secure(args.client_secure.unwrap_or_default())
73            .endpoint_graphql(args.endpoint_graphql.clone().unwrap_or(DEFAULT_ENDPOINT_GRAPHQL.to_string()))
74            .endpoint_dynamic_graph(args.endpoint_dynamic_graph.clone().unwrap_or(DEFAULT_ENDPOINT_DYNAMIC_GRAPH.to_string()))
75            .endpoint_runtime(args.endpoint_runtime.clone().unwrap_or(DEFAULT_ENDPOINT_RUNTIME.to_string()))
76            .endpoint_plugin(args.endpoint_plugins.clone().unwrap_or(DEFAULT_ENDPOINT_PLUGIN.to_string()))
77            .bearer(args.bearer.clone())
78            .danger_accept_invalid_certs(args.danger_accept_invalid_certs)
79            .danger_accept_invalid_hostnames(args.danger_accept_invalid_hostnames)
80            .build()
81    }
82}