diff --git a/Cargo.lock b/Cargo.lock index 0f3a1f8..6b43947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,16 +1558,25 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", - "progenitor", - "reqwest", - "schemars", - "serde", + "patagia-client", "tokio", "tracing", "tracing-chrome", "tracing-subscriber", ] +[[package]] +name = "patagia-client" +version = "0.0.1" +dependencies = [ + "anyhow", + "chrono", + "progenitor", + "reqwest", + "schemars", + "serde", +] + [[package]] name = "patagia-controller" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index bd87172..6540a46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,13 @@ resolver = "2" members = [ "agent", + "client", "controller", "xtask", ] default-members = [ "agent", + "client", "controller", "xtask", ] diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 9a87168..467eabb 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -7,14 +7,11 @@ license = "MPL-2.0" [dependencies] anyhow.workspace = true clap.workspace = true -progenitor.workspace = true -reqwest.workspace = true -schemars.workspace = true -serde.workspace = true +patagia-client = { path = "../client" } tokio.workspace = true +tracing.workspace = true tracing-chrome.workspace = true tracing-subscriber.workspace = true -tracing.workspace = true [[bin]] name = "patagia-agent" diff --git a/agent/src/main.rs b/agent/src/main.rs index c3e72ed..a3e4a95 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -3,8 +3,6 @@ use clap::Parser; use tokio::time::{sleep, Duration}; use tracing_subscriber::prelude::*; -mod patagia_api; - #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Cli {} @@ -21,7 +19,7 @@ async fn main() -> Result<()> { tracing::info!("Patagia Agent"); - let client = patagia_api::Client::new("http://localhost:9474"); + let client = patagia_client::Client::new("http://localhost:9474"); let result = client.version().await?; tracing::info!("Result: {:?}", result); diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..b619654 --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "patagia-client" +version = "0.0.1" +license = "MPL-2.0" +edition = "2021" + +[dependencies] +anyhow.workspace = true +chrono = { version = "0.4.0", default-features = false, features = ["serde"] } +progenitor.workspace = true +reqwest.workspace = true +schemars.workspace = true +serde.workspace = true diff --git a/agent/src/patagia_api.rs b/client/src/lib.rs similarity index 99% rename from agent/src/patagia_api.rs rename to client/src/lib.rs index 841b609..8dca05c 100644 --- a/agent/src/patagia_api.rs +++ b/client/src/lib.rs @@ -1,3 +1,4 @@ use progenitor::generate_api; + generate_api!(spec = "../api.json", derives = [schemars::JsonSchema]); diff --git a/flake.nix b/flake.nix index ee7135b..2edb4bb 100644 --- a/flake.nix +++ b/flake.nix @@ -52,14 +52,23 @@ pkg-config ]; - jsonFilter = path: _type: builtins.match ".*json$" path != null; - sourceAndFixtures = path: type: - (jsonFilter path type) || (craneLib.filterCargoSources path type); + sourceAndFixtures = path: type: (craneLib.filterCargoSources path type); src = pkgs.lib.cleanSourceWith { src = ./.; filter = sourceAndFixtures; }; + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + nixfmt.package = pkgs.nixfmt-rfc-style; + shfmt.enable = true; + rustfmt.enable = true; + }; + settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt"; + }; + commonArgs = { inherit src stdenv nativeBuildInputs; strictDeps = true; @@ -86,6 +95,7 @@ ./Cargo.toml ./Cargo.lock (craneLib.fileset.commonCargoSources ./agent) + (craneLib.fileset.commonCargoSources ./client) (craneLib.fileset.commonCargoSources ./controller) (craneLib.fileset.commonCargoSources ./xtask) (craneLib.fileset.commonCargoSources crate) @@ -118,18 +128,6 @@ src = fileSetForCrate ./xtask; } ); - - treefmtEval = treefmt-nix.lib.evalModule pkgs { - projectRootFile = "flake.nix"; - programs = { - nixfmt.enable = true; - nixfmt.package = pkgs.nixfmt-rfc-style; - shfmt.enable = true; - rustfmt.enable = true; - }; - settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt"; - }; - in { # `nix build` @@ -167,7 +165,6 @@ ( commonArgs // { - inherit cargoArtifacts; src = fileSetForCrate ./xtask; } ) @@ -191,7 +188,6 @@ cargo-nextest cargo-watch hyperfine - openssl just rust-dev-toolchain watchexec