1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! `AgileConfig` client for the [`config`] crate.
//!
//! This crate talks to an [AgileConfig](https://github.com/dotnetcore/AgileConfig)
//! cluster over HTTP and WebSocket and exposes configuration through two types:
//!
//! - [`Client`] loads published key/value items, optionally caches them on
//! disk, and can keep a WebSocket session for live reload notifications.
//! - [`Source`] implements [`config::AsyncSource`] so the snapshot can be
//! composed with other sources (files, environment variables, and so on).
//!
//! # Building a client
//!
//! Construct [`ClientOptions`] directly or use [`Client::builder`]:
//!
//! ```no_run
//! use agile_config_client::{Client, ClientOptions};
//!
//! let from_struct = Client::new(ClientOptions {
//! app_id: "app".into(),
//! secret: "secret".into(),
//! nodes: vec!["http://localhost:5000".into()],
//! env: "DEV".into(),
//! ..ClientOptions::default()
//! })?;
//!
//! let from_builder = Client::builder()
//! .app_id("app")
//! .secret("secret")
//! .nodes(["http://localhost:5000"])
//! .env("DEV")
//! .build()?;
//! # Ok::<(), agile_config_client::Error>(())
//! ```
//!
//! # One-shot load with `config`
//!
//! [`Source::collect`][source::Source] (via [`Client::source`]) performs HTTP
//! (and cache fallback). It does **not** open a WebSocket.
//!
//! ```no_run
//! use agile_config_client::{Client, ClientOptions};
//!
//! # async fn demo() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new(ClientOptions {
//! app_id: "app".into(),
//! secret: "secret".into(),
//! nodes: vec!["http://localhost:5000".into()],
//! ..ClientOptions::default()
//! })?;
//!
//! let settings = config::Config::builder()
//! .add_async_source(client.source())
//! .build()
//! .await?;
//!
//! let connection = settings.get_string("db.connection")?;
//! # let _ = connection;
//! # Ok(())
//! # }
//! ```
//!
//! Keys that the C# client exposes as `group:key` become dotted paths for the
//! `config` crate (`db:connection` → `db.connection`).
//!
//! # Live updates
//!
//! Call [`Client::connect`] to pull configuration and start WebSocket
//! reconnect/heartbeat. Keep the `Client` alive, then listen with
//! [`Client::subscribe`]. This crate never rebuilds [`config::Config`] for you.
//!
//! ```no_run
//! use agile_config_client::{Client, ClientOptions};
//!
//! # async fn demo() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new(ClientOptions {
//! app_id: "app".into(),
//! secret: "secret".into(),
//! nodes: vec!["http://localhost:5000".into()],
//! ..ClientOptions::default()
//! })?;
//! client.connect().await?;
//!
//! let mut rx = client.subscribe();
//! while rx.changed().await.is_ok() {
//! let snapshot = client.snapshot();
//! // Rebuild `config::Config` or swap application state here.
//! let _ = snapshot.get("db:connection");
//! }
//! # Ok(())
//! # }
//! ```
//!
//! Lookups on [`ConfigSnapshot`] are case-sensitive.
//!
//! # Features
//!
//! | Feature | Default | Purpose |
//! | --- | --- | --- |
//! | `cache-encrypt` | off | AES-ECB encryption for the local cache file (C# compatible) |
pub use Client;
pub use Error;
pub use ;
pub use ConfigItem;
pub use Source;
pub use ConfigSnapshot;