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;
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}
22
23impl ClientOptions {
24 /// Creates options with the local Dex server default and pull Worker routing.
25 pub fn new() -> Self {
26 Self {
27 server_address: "127.0.0.1:8801".to_string(),
28 credential: None,
29 }
30 }
31
32 /// Sets the plaintext gRPC `host:port` used for every client request.
33 pub fn server_address(mut self, value: impl Into<String>) -> Self {
34 self.server_address = value.into();
35 self
36 }
37
38 /// Sends a bearer token before every FlowService request.
39 ///
40 /// The default sends no authorization metadata. The credential may be called concurrently;
41 /// its error fails the request locally. The token uses the plaintext Dex connection, so
42 /// protect the network path. See [`crate::FileCredential`] for file rotation.
43 pub fn credential(mut self, value: Arc<dyn Credential>) -> Self {
44 self.credential = Some(value);
45 self
46 }
47
48 pub(crate) fn server_address_value(&self) -> &str {
49 &self.server_address
50 }
51
52 pub(crate) fn credential_value(&self) -> Option<Arc<dyn Credential>> {
53 self.credential.clone()
54 }
55}
56
57impl Default for ClientOptions {
58 fn default() -> Self {
59 Self::new()
60 }
61}