diff --git a/cfgsync/README.md b/cfgsync/README.md index c113019..899d32c 100644 --- a/cfgsync/README.md +++ b/cfgsync/README.md @@ -238,14 +238,16 @@ serve(4400, MyMaterializer).await?; Fetching and writing artifacts: ```rust -use cfgsync_runtime::{OutputMap, fetch_and_write}; +use cfgsync_runtime::{Client, OutputMap}; # async fn run(registration: cfgsync_core::NodeRegistration) -> anyhow::Result<()> { let outputs = OutputMap::new() .route("/config.yaml", "/node-data/node-1/config.yaml") .route("deployment-settings.yaml", "/node-data/shared/deployment-settings.yaml"); -fetch_and_write(®istration, "http://127.0.0.1:4400", &outputs).await?; +Client::new("http://127.0.0.1:4400") + .fetch_and_write(®istration, &outputs) + .await?; # Ok(()) # } ``` diff --git a/cfgsync/runtime/examples/minimal_cfgsync.rs b/cfgsync/runtime/examples/minimal_cfgsync.rs index b2aabda..d61f1d7 100644 --- a/cfgsync/runtime/examples/minimal_cfgsync.rs +++ b/cfgsync/runtime/examples/minimal_cfgsync.rs @@ -4,7 +4,7 @@ use cfgsync_adapter::{ }; use cfgsync_artifacts::{ArtifactFile, ArtifactSet}; use cfgsync_core::NodeRegistration; -use cfgsync_runtime::{OutputMap, fetch_and_write, serve}; +use cfgsync_runtime::{Client, OutputMap, serve}; use tempfile::tempdir; use tokio::time::{Duration, sleep}; @@ -48,7 +48,9 @@ async fn main() -> anyhow::Result<()> { let outputs = OutputMap::new().route("/config.yaml", &config_path); let registration = NodeRegistration::new("node-1", "127.0.0.1".parse()?); - fetch_and_write(®istration, "http://127.0.0.1:4400", &outputs).await?; + Client::new("http://127.0.0.1:4400") + .fetch_and_write(®istration, &outputs) + .await?; println!("{}", std::fs::read_to_string(&config_path)?); diff --git a/cfgsync/runtime/src/client.rs b/cfgsync/runtime/src/client.rs index e9a19da..04484fa 100644 --- a/cfgsync/runtime/src/client.rs +++ b/cfgsync/runtime/src/client.rs @@ -159,34 +159,6 @@ enum ClientEnvError { InvalidIp { value: String }, } -/// Registers a node and fetches its artifact payload from cfgsync. -/// -/// Prefer [`Client::register_and_fetch`] when you already hold a runtime -/// client value. -pub async fn register_and_fetch( - registration: &NodeRegistration, - server_addr: &str, -) -> Result { - Client::new(server_addr) - .register_and_fetch(registration) - .await -} - -/// Registers a node, fetches its artifact payload, and writes the files using -/// the provided output routing policy. -/// -/// Prefer [`Client::fetch_and_write`] when you already hold a runtime client -/// value. -pub async fn fetch_and_write( - registration: &NodeRegistration, - server_addr: &str, - outputs: &OutputMap, -) -> Result<()> { - Client::new(server_addr) - .fetch_and_write(registration, outputs) - .await -} - fn ensure_schema_version(config: &NodeArtifactsPayload) -> Result<()> { if config.schema_version != CFGSYNC_SCHEMA_VERSION { bail!( @@ -244,12 +216,12 @@ pub async fn run_client_from_env(default_port: u16) -> Result<()> { let metadata = parse_registration_payload_env()?; let outputs = build_output_map(); - fetch_and_write( - &NodeRegistration::new(identifier, ip).with_payload(metadata), - &server_addr, - &outputs, - ) - .await + Client::new(&server_addr) + .fetch_and_write( + &NodeRegistration::new(identifier, ip).with_payload(metadata), + &outputs, + ) + .await } fn parse_ip_env(ip_str: &str) -> Result { @@ -325,13 +297,13 @@ mod tests { .expect("run cfgsync server"); }); - fetch_and_write( - &NodeRegistration::new("node-1", "127.0.0.1".parse().expect("parse ip")), - &address, - &OutputMap::default(), - ) - .await - .expect("pull config files"); + Client::new(&address) + .fetch_and_write( + &NodeRegistration::new("node-1", "127.0.0.1".parse().expect("parse ip")), + &OutputMap::default(), + ) + .await + .expect("pull config files"); server.abort(); let _ = server.await; diff --git a/cfgsync/runtime/src/lib.rs b/cfgsync/runtime/src/lib.rs index ab6032b..479091e 100644 --- a/cfgsync/runtime/src/lib.rs +++ b/cfgsync/runtime/src/lib.rs @@ -3,7 +3,7 @@ pub use cfgsync_core as core; mod client; mod server; -pub use client::{Client, OutputMap, fetch_and_write, register_and_fetch, run_client_from_env}; +pub use client::{Client, OutputMap, run_client_from_env}; pub use server::{ LoadServerConfigError, ServerConfig, ServerSource, build_persisted_router, build_router, serve, serve_from_config, serve_persisted,