Skip to main content

dex_sdk/
client_options.rs

1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Sustainable Use License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
9use std::sync::Arc;
10
11use crate::{Credential, FlowServiceTlsOptions};
12
13#[derive(Clone, Debug)]
14/// Configures how a [`crate::Client`] reaches Dex.
15///
16/// [`ClientOptions::new`] connects to `127.0.0.1:8801` over plaintext gRPC and requires no
17/// inbound Worker endpoint. All Flows use pull Workers.
18pub struct ClientOptions {
19    server_address: String,
20    credential: Option<Arc<dyn Credential>>,
21    flow_service_tls: Option<FlowServiceTlsOptions>,
22}
23
24impl ClientOptions {
25    /// Creates options with the local Dex server default and pull Worker routing.
26    pub fn new() -> Self {
27        Self {
28            server_address: "127.0.0.1:8801".to_string(),
29            credential: None,
30            flow_service_tls: None,
31        }
32    }
33
34    /// Sets the FlowService address used for every Client request.
35    ///
36    /// With TLS, accepts `host:port`, `dns:///host:port`, or `dns://authority/host:port`.
37    pub fn server_address(mut self, value: impl Into<String>) -> Self {
38        self.server_address = value.into();
39        self
40    }
41
42    /// Enables TLS for every outbound Client FlowService connection.
43    ///
44    /// Omitted by default, preserving plaintext gRPC. Takes ownership of `value` and returns
45    /// these options with TLS enabled. [`crate::Client::try_new`] validates the address,
46    /// additional roots, and server name, returning [`crate::SdkError::InvalidArgument`] for
47    /// invalid input. See [`FlowServiceTlsOptions`] for defaults and a complete example.
48    pub fn flow_service_tls(mut self, value: FlowServiceTlsOptions) -> Self {
49        self.flow_service_tls = Some(value);
50        self
51    }
52
53    /// Sends a bearer token before every FlowService request.
54    ///
55    /// The default sends no authorization metadata. The credential may be called concurrently;
56    /// its error fails the request locally. The token uses the configured Dex connection. Enable
57    /// TLS with [`Self::flow_service_tls`] to protect it. See [`crate::FileCredential`] for file rotation.
58    pub fn credential(mut self, value: Arc<dyn Credential>) -> Self {
59        self.credential = Some(value);
60        self
61    }
62
63    pub(crate) fn server_address_value(&self) -> &str {
64        &self.server_address
65    }
66
67    pub(crate) fn flow_service_tls_value(&self) -> Option<&FlowServiceTlsOptions> {
68        self.flow_service_tls.as_ref()
69    }
70
71    pub(crate) fn credential_value(&self) -> Option<Arc<dyn Credential>> {
72        self.credential.clone()
73    }
74}
75
76impl Default for ClientOptions {
77    fn default() -> Self {
78        Self::new()
79    }
80}