diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9433b33..98fffdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -272,13 +272,14 @@ jobs: # Test breeder purge with force flag echo "Testing: breeder purge --force" - $BINARY_PATH --hostname=localhost --port=4010 --force breeder purge --id=550e8400-e29b-41d4-a716-446655440000 + $BINARY_PATH --hostname=localhost --port=4010 breeder purge --force --id=550e8400-e29b-41d4-a716-446655440000 # Test help shows new commands - echo "Testing: help shows stop/start/force commands" + echo "Testing: help shows stop/start commands" $BINARY_PATH --help | grep -q "stop" && echo "✅ stop command documented" || echo "❌ stop command missing" $BINARY_PATH --help | grep -q "start" && echo "✅ start command documented" || echo "❌ start command missing" - $BINARY_PATH --help | grep -q "force" && echo "✅ force flag documented" || echo "❌ force flag missing" + echo "Testing: breeder purge --help shows --force flag" + $BINARY_PATH breeder purge --help | grep -q "force" && echo "✅ --force flag documented in purge" || echo "❌ --force flag missing from purge" # Test help commands echo "Testing: help commands" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..16eefd6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1566 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "clap" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "godon-cli" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "reqwest", + "serde", + "serde_json", + "serde_yaml", + "tokio", + "urlencoding", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..94c3261 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "godon-cli" +version = "0.1.0" +edition = "2021" +authors = ["Matthias Tafelmeier"] +description = "CLI for the Godon API" +license = "AGPL-3.0" + +[[bin]] +name = "godon_cli" +path = "src/main.rs" + +[dependencies] +clap = { version = "4", features = ["derive", "env"] } +reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +serde_yaml = "0.9" +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +anyhow = "1" +urlencoding = "2" diff --git a/flake.nix b/flake.nix index 8bf58f4..774a01d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,93 +1,70 @@ { - description = "Godon CLI - Nim-based CLI for Godon API"; + description = "Godon CLI - Rust-based CLI for Godon API"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; }; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, rust-overlay }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - - # Build static binary using glibc with proper static libraries - godon-cli = { version ? (if builtins.getEnv "GODON_VERSION" == "" then "DEV_BUILD" else builtins.getEnv "GODON_VERSION") }: pkgs.stdenv.mkDerivation { - pname = "godon-cli"; - inherit version; - src = ./.; - - nativeBuildInputs = with pkgs; [ - cacert - nim2 - nimble - git - pkg-config - ]; - - buildInputs = with pkgs; [ - openssl - ]; - - env = { - SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - }; - - configurePhase = '' - export HOME=$TMPDIR - ''; - - buildPhase = '' - echo "Building godon-cli version: ${version}" - - # Refresh package list and install dependencies only - nimble refresh --verbose - # Install yaml dependency without building our package - nimble install -y --depsOnly --verbose - - # Build the CLI - mkdir -p bin - nim c --hints:on --path:src -d:release -d:ssl -d:VERSION="${version}" \ - -o:bin/godon_cli src/godon_cli.nim - ''; - - installPhase = '' - mkdir -p $out/bin - - # Install the binary - cp bin/godon_cli $out/bin/godon_cli - chmod +x $out/bin/godon_cli - ''; - - meta = with pkgs.lib; { - description = "CLI for the Godon API"; - license = licenses.agpl3Only; - platforms = platforms.linux; + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.pkgsBuildHost.rust-bin.stable.latest.default; + + godon-cli = { version ? (if builtins.getEnv "GODON_VERSION" == "" then + "DEV_BUILD" + else + builtins.getEnv "GODON_VERSION") }: + pkgs.stdenv.mkDerivation { + pname = "godon-cli"; + inherit version; + src = ./.; + + nativeBuildInputs = with pkgs; [ rustToolchain pkg-config ]; + + buildInputs = with pkgs; [ openssl ]; + + env = { + SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + }; + + buildPhase = '' + echo "Building godon-cli version: ${version}" + export CARGO_HOME=$PWD/.cargo-home + cargo build --release + ''; + + installPhase = '' + mkdir -p $out/bin + cp target/release/godon_cli $out/bin/godon_cli + chmod +x $out/bin/godon_cli + ''; + + meta = with pkgs.lib; { + description = "CLI for the Godon API"; + license = licenses.agpl3Only; + platforms = platforms.linux; + }; }; - }; - + in { packages.default = godon-cli { }; packages.godon-cli = godon-cli; - - # Allow building with custom version + packages.godon-cli-custom = version: godon-cli { inherit version; }; - - # Development shell with Nim and build tools + devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - nim2 - nimble - git - ]; - + buildInputs = with pkgs; [ rustToolchain rust-analyzer cargo-watch ]; + shellHook = '' echo "Godon CLI development environment" - echo "Nim: $(nim --version | head -n1)" - echo "Nimble: $(nimble --version | head -n1)" + echo "Rust: $(rustc --version)" ''; }; }); -} \ No newline at end of file +} diff --git a/godon_cli.nimble b/godon_cli.nimble deleted file mode 100644 index cdde55e..0000000 --- a/godon_cli.nimble +++ /dev/null @@ -1,39 +0,0 @@ -# Package information - -version = "0.1.0" -author = "Matthias Tafelmeier" -description = "CLI for the Godon API" -license = "AGPL-3.0" - -# Dependencies - -requires "nim >= 2.0.0" -requires "yaml == 2.1.1" - -# Task definitions - -task build, "Build the CLI": - exec "nim c -d:release -o:bin/godon_cli src/godon_cli.nim" - -task build_debug, "Build the CLI with debug symbols": - exec "nim c -g -o:bin/godon_cli src/godon_cli.nim" - -task clean, "Clean build artifacts": - exec "rm -rf bin" - -task test, "Run tests": - exec "nim c -r tests/test_all.nim" - -task docker_build, "Build Docker image": - exec "docker build -t godon-cli:latest ." - -task docker_run, "Run Docker image": - exec "docker run --rm -it godon-cli:latest --help" - -# Binary definition -bin = @["godon_cli"] - -# Install script (when installed via nimble) -installDirs = @["bin"] -installFiles = @["bin/godon_cli"] -installExt = @[] \ No newline at end of file diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..eae552e --- /dev/null +++ b/src/client.rs @@ -0,0 +1,390 @@ +use crate::{ApiConfig, ApiResponse, Breeder, BreederCreateRequest, BreederSummary, BreederUpdateRequest, Credential}; +use anyhow::{Context, Result}; +use reqwest::Client; +use std::time::Duration; + +pub struct GodonClient { + config: ApiConfig, + client: Client, + debug: bool, +} + +impl GodonClient { + pub fn new(hostname: String, port: u16, api_version: String, insecure: bool, debug: bool) -> Result { + let mut builder = Client::builder() + .timeout(Duration::from_secs(30)); + + if insecure { + builder = builder.danger_accept_invalid_certs(true); + } + + let client = builder.build() + .context("Failed to create HTTP client")?; + + Ok(Self { + config: ApiConfig { + hostname, + port, + api_version, + }, + client, + debug, + }) + } + + fn base_url(&self) -> String { + let scheme = if self.config.hostname.starts_with("https://") { + "https" + } else if self.config.hostname.starts_with("http://") { + "http" + } else { + "http" + }; + + let clean_host = self.config.hostname + .trim_start_matches("https://") + .trim_start_matches("http://"); + + format!("{}://{}:{}", scheme, clean_host, self.config.port) + } + + async fn handle_response(&self, response: reqwest::Response) -> ApiResponse { + let status = response.status(); + + if status.is_success() { + match response.text().await { + Ok(body) => { + if self.debug { + eprintln!("Raw response body: {}", body); + } + + if body.is_empty() { + return ApiResponse::error("Empty response body"); + } + + match serde_json::from_str::(&body) { + Ok(data) => ApiResponse::success(data), + Err(e) => { + if self.debug { + eprintln!("JSON parse error: {}", e); + } + ApiResponse::error(format!("JSON parse error: {}", e)) + } + } + } + Err(e) => ApiResponse::error(format!("Failed to read response: {}", e)), + } + } else { + match response.text().await { + Ok(body) => { + if self.debug { + eprintln!("HTTP Error Response Body: {}", body); + } + + let error_msg = serde_json::from_str::(&body) + .ok() + .and_then(|v| v.get("message").and_then(|m| m.as_str()).map(String::from)) + .unwrap_or_else(|| format!("HTTP Error: {}", status)); + + ApiResponse::error(error_msg) + } + Err(_) => ApiResponse::error(format!("HTTP Error: {}", status)), + } + } + } + + pub async fn list_breeders(&self) -> ApiResponse> { + let url = format!("{}/breeders", self.base_url()); + + match self.client.get(&url).send().await { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn create_breeder(&self, request: BreederCreateRequest) -> ApiResponse { + let url = format!("{}/breeders", self.base_url()); + + if self.debug { + eprintln!("Sending JSON: {}", serde_json::to_string_pretty(&request).unwrap_or_default()); + } + + match self.client + .post(&url) + .json(&request) + .send() + .await + { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn create_breeder_from_yaml(&self, yaml_content: &str, name: &str) -> ApiResponse { + let config: serde_json::Value = match serde_yaml::from_str(yaml_content) { + Ok(c) => c, + Err(e) => return ApiResponse::error(format!("YAML parse error: {}", e)), + }; + + let request = BreederCreateRequest { + name: name.to_string(), + config, + }; + + self.create_breeder(request).await + } + + pub async fn get_breeder(&self, uuid: &str) -> ApiResponse { + let url = format!("{}/breeders/{}", self.base_url(), urlencoding::encode(uuid)); + + match self.client.get(&url).send().await { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn update_breeder(&self, request: BreederUpdateRequest) -> ApiResponse { + let url = format!("{}/breeders/{}", self.base_url(), urlencoding::encode(&request.uuid)); + + let config: serde_json::Value = match serde_json::from_str(&request.config) { + Ok(c) => c, + Err(e) => return ApiResponse::error(format!("Config JSON parse error: {}", e)), + }; + + let body = serde_json::json!({ + "name": request.name, + "description": request.description, + "config": config + }); + + match self.client + .put(&url) + .json(&body) + .send() + .await + { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn update_breeder_from_yaml(&self, yaml_content: &str) -> ApiResponse { + let yaml_data: serde_yaml::Value = match serde_yaml::from_str(yaml_content) { + Ok(d) => d, + Err(e) => return ApiResponse::error(format!("YAML parse error: {}", e)), + }; + + let uuid = yaml_data.get("uuid") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + + let name = yaml_data.get("name") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + + let description = yaml_data.get("description") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + + let config = yaml_data.get("config") + .map(|c| serde_json::to_string(c).unwrap_or_else(|_| "{}".to_string())) + .unwrap_or_else(|| "{}".to_string()); + + let request = BreederUpdateRequest { + uuid, + name, + description, + config, + }; + + self.update_breeder(request).await + } + + pub async fn delete_breeder(&self, uuid: &str, force: bool) -> ApiResponse { + let mut url = format!("{}/breeders/{}", self.base_url(), urlencoding::encode(uuid)); + + if force { + url.push_str("?force=true"); + } + + match self.client.delete(&url).send().await { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn stop_breeder(&self, uuid: &str) -> ApiResponse { + let url = format!("{}/breeders/{}/stop", self.base_url(), urlencoding::encode(uuid)); + + match self.client.post(&url).send().await { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn start_breeder(&self, uuid: &str) -> ApiResponse { + let url = format!("{}/breeders/{}/start", self.base_url(), urlencoding::encode(uuid)); + + match self.client.post(&url).send().await { + Ok(response) => self.handle_response(response).await, + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn list_credentials(&self) -> ApiResponse> { + let url = format!("{}/credentials", self.base_url()); + + match self.client.get(&url).send().await { + Ok(response) => { + let status = response.status(); + + if status.is_success() { + match response.text().await { + Ok(body) => { + let json: serde_json::Value = match serde_json::from_str(&body) { + Ok(j) => j, + Err(e) => return ApiResponse::error(format!("JSON parse error: {}", e)), + }; + + let credentials: Vec = if json.is_array() { + match serde_json::from_value(json) { + Ok(c) => c, + Err(e) => return ApiResponse::error(format!("Parse error: {}", e)), + } + } else if let Some(arr) = json.get("credentials") { + match serde_json::from_value(arr.clone()) { + Ok(c) => c, + Err(e) => return ApiResponse::error(format!("Parse error: {}", e)), + } + } else { + return ApiResponse::error("Unexpected response format"); + }; + + ApiResponse::success(credentials) + } + Err(e) => ApiResponse::error(e.to_string()), + } + } else { + ApiResponse::error(format!("HTTP Error: {}", status)) + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn create_credential(&self, credential_data: serde_json::Value) -> ApiResponse { + let url = format!("{}/credentials", self.base_url()); + + match self.client + .post(&url) + .json(&credential_data) + .send() + .await + { + Ok(response) => { + let status = response.status(); + + if status.is_success() { + match response.text().await { + Ok(body) => { + match serde_json::from_str::(&body) { + Ok(cred) => ApiResponse::success(cred), + Err(e) => ApiResponse::error(format!("Parse error: {}", e)), + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } else { + ApiResponse::error(format!("HTTP Error: {}", status)) + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn get_credential(&self, credential_id: &str) -> ApiResponse { + let url = format!("{}/credentials/{}", self.base_url(), urlencoding::encode(credential_id)); + + match self.client.get(&url).send().await { + Ok(response) => { + let status = response.status(); + + if status.is_success() { + match response.text().await { + Ok(body) => { + match serde_json::from_str::(&body) { + Ok(cred) => ApiResponse::success(cred), + Err(e) => ApiResponse::error(format!("Parse error: {}", e)), + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } else { + ApiResponse::error(format!("HTTP Error: {}", status)) + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn delete_credential(&self, credential_id: &str) -> ApiResponse { + let url = format!("{}/credentials/{}", self.base_url(), urlencoding::encode(credential_id)); + + match self.client.delete(&url).send().await { + Ok(response) => { + let status = response.status(); + + if status.is_success() { + match response.text().await { + Ok(body) => { + match serde_json::from_str(&body) { + Ok(v) => ApiResponse::success(v), + Err(e) => ApiResponse::error(format!("Parse error: {}", e)), + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } else { + ApiResponse::error(format!("HTTP Error: {}", status)) + } + } + Err(e) => ApiResponse::error(e.to_string()), + } + } + + pub async fn create_credential_from_yaml(&self, yaml_content: &str) -> ApiResponse { + let yaml_data: std::collections::HashMap = match serde_yaml::from_str(yaml_content) { + Ok(d) => d, + Err(e) => return ApiResponse::error(format!("YAML parse error: {}", e)), + }; + + let name = match yaml_data.get("name") { + Some(n) => n.clone(), + None => return ApiResponse::error("Missing required field: name"), + }; + + let credential_type = match yaml_data.get("credentialType") { + Some(t) => t.clone(), + None => return ApiResponse::error("Missing required field: credentialType"), + }; + + let content = match yaml_data.get("content") { + Some(c) => c.clone(), + None => return ApiResponse::error("Missing required field: content"), + }; + + let description = yaml_data.get("description").cloned().unwrap_or_default(); + + let credential_data = serde_json::json!({ + "name": name, + "credentialType": credential_type, + "description": description, + "content": content + }); + + self.create_credential(credential_data).await + } +} diff --git a/src/godon/breeder.nim b/src/godon/breeder.nim deleted file mode 100644 index 2f4926a..0000000 --- a/src/godon/breeder.nim +++ /dev/null @@ -1,139 +0,0 @@ -## Breeder API Methods -## Implementation of breeder-related API endpoints - -import std/[httpclient, json, strutils, uri] -import yaml, yaml/tojson -import client, types - -proc listBreeders*(client: GodonClient): ApiResponse[seq[BreederSummary]] = - ## List all configured breeders - try: - let url = client.baseUrl() & "/breeders" - let response = client.httpClient.get(url) - result = handleResponse[seq[BreederSummary]](client, response) - except CatchableError as e: - result = ApiResponse[seq[BreederSummary]](success: false, data: @[], error: e.msg) - -proc createBreeder*(client: GodonClient, request: BreederCreateRequest): ApiResponse[BreederSummary] = - ## Create a new breeder - try: - let url = client.baseUrl() & "/breeders" - # Config is already a JsonNode, no parsing needed - var jsonData = %*{ - "name": request.name, - "config": request.config - } - if client.debug: - echo "Sending JSON: ", $jsonData - client.httpClient.headers = newHttpHeaders({"Content-Type": "application/json"}) - let response = client.httpClient.post(url, $jsonData) - result = handleResponse[BreederSummary](client, response) - except CatchableError as e: - result = ApiResponse[BreederSummary](success: false, data: default(BreederSummary), error: e.msg) - -proc createBreederFromYamlWithName*(client: GodonClient, yamlContent: string, name: string): ApiResponse[BreederSummary] = - ## Create a breeder from YAML content with explicit name parameter - ## YAML contains only the config (no name field), name comes from parameter - try: - # Parse YAML and convert to JsonNode - let jsonNodes = loadToJson(yamlContent) - - # Take the first document (should be only one) - if jsonNodes.len == 0: - return ApiResponse[BreederSummary](success: false, data: default(BreederSummary), error: "No YAML documents found") - - let configNode = jsonNodes[0] - - # Create BreederCreateRequest with name from parameter and config from YAML - let request = BreederCreateRequest( - name: name, - config: configNode - ) - result = client.createBreeder(request) - except CatchableError as e: - result = ApiResponse[BreederSummary](success: false, data: default(BreederSummary), error: e.msg) - -proc getBreeder*(client: GodonClient, uuid: string): ApiResponse[Breeder] = - ## Get breeder details by UUID - try: - let url = client.baseUrl() & "/breeders/" & encodeUrl(uuid) - let response = client.httpClient.get(url) - result = handleResponse[Breeder](client, response) - except CatchableError as e: - result = ApiResponse[Breeder](success: false, data: default(Breeder), error: e.msg) - -proc updateBreeder*(client: GodonClient, request: BreederUpdateRequest): ApiResponse[Breeder] = - ## Update an existing breeder - try: - let url = client.baseUrl() & "/breeders/" & encodeUrl(request.uuid) - # Config is a string (JSON), parse it first - var jsonData = %*{ - "name": request.name, - "description": request.description, - "config": parseJson(request.config) - } - client.httpClient.headers = newHttpHeaders({"Content-Type": "application/json"}) - let response = client.httpClient.put(url, $jsonData) - result = handleResponse[Breeder](client, response) - except CatchableError as e: - result = ApiResponse[Breeder](success: false, data: default(Breeder), error: e.msg) - -proc updateBreederFromYaml*(client: GodonClient, yamlContent: string): ApiResponse[Breeder] = - ## Update a breeder from YAML content - try: - # Parse YAML and convert to JsonNode - let jsonNodes = loadToJson(yamlContent) - - # Take the first document (should be only one) - if jsonNodes.len == 0: - return ApiResponse[Breeder](success: false, data: default(Breeder), error: "No YAML documents found") - - let yamlData = jsonNodes[0] - - # Extract fields from YAML - let uuid = if yamlData.hasKey("uuid"): yamlData["uuid"].getStr() else: "" - let name = if yamlData.hasKey("name"): yamlData["name"].getStr() else: "" - let description = if yamlData.hasKey("description"): yamlData["description"].getStr() else: "" - - # Config should be a nested object - convert to JSON string - let config = if yamlData.hasKey("config"): $yamlData["config"] else: "{}" - - let request = BreederUpdateRequest( - uuid: uuid, - name: name, - description: description, - config: config - ) - result = client.updateBreeder(request) - except CatchableError as e: - result = ApiResponse[Breeder](success: false, data: default(Breeder), error: e.msg) - -proc deleteBreeder*(client: GodonClient, uuid: string, force: bool = false): ApiResponse[JsonNode] = - ## Delete/purge a breeder by UUID - ## Set force=true to cancel workers immediately (default: false for safe deletion) - try: - var url = client.baseUrl() & "/breeders/" & encodeUrl(uuid) - if force: - url = url & "?force=true" - let response = client.httpClient.delete(url) - result = handleResponse[JsonNode](client, response) - except CatchableError as e: - result = ApiResponse[JsonNode](success: false, data: nil, error: e.msg) - -proc stopBreeder*(client: GodonClient, uuid: string): ApiResponse[JsonNode] = - ## Stop a breeder (graceful shutdown) - try: - let url = client.baseUrl() & "/breeders/" & encodeUrl(uuid) & "/stop" - let response = client.httpClient.post(url) - result = handleResponse[JsonNode](client, response) - except CatchableError as e: - result = ApiResponse[JsonNode](success: false, data: nil, error: e.msg) - -proc startBreeder*(client: GodonClient, uuid: string): ApiResponse[JsonNode] = - ## Start/resume a stopped breeder - try: - let url = client.baseUrl() & "/breeders/" & encodeUrl(uuid) & "/start" - let response = client.httpClient.post(url) - result = handleResponse[JsonNode](client, response) - except CatchableError as e: - result = ApiResponse[JsonNode](success: false, data: nil, error: e.msg) \ No newline at end of file diff --git a/src/godon/client.nim b/src/godon/client.nim deleted file mode 100644 index 8e79360..0000000 --- a/src/godon/client.nim +++ /dev/null @@ -1,114 +0,0 @@ -## Godon HTTP Client -## Core HTTP client for Godon API - -import std/[httpclient, json, uri, strutils, net] -import types - -const - DefaultHostname* = "localhost" - DefaultPort* = 8080 - DefaultApiVersion* = "v0" - -type - GodonClient* = ref object - config*: ApiConfig - httpClient*: HttpClient - insecure*: bool - debug*: bool - -proc newGodonClient*(hostname: string = DefaultHostname, - port: int = DefaultPort, - apiVersion: string = DefaultApiVersion, - insecure: bool = false, - debug: bool = false): GodonClient = - ## Create a new Godon API client - let config = ApiConfig( - hostname: hostname, - port: port, - apiVersion: apiVersion - ) - - # Configure HTTP client with SSL verification settings - var httpClient: HttpClient - if insecure: - # Create insecure SSL context that skips certificate verification - let sslContext = newContext(verifyMode = CVerifyNone) - httpClient = newHttpClient(sslContext = sslContext) - else: - httpClient = newHttpClient() - - GodonClient(config: config, httpClient: httpClient, insecure: insecure, debug: debug) - -proc baseUrl*(client: GodonClient): string = - ## Get the base URL for API requests - ## Auto-detect protocol if hostname includes https:// or http:// prefix - let scheme = if client.config.hostname.startsWith("https://"): - "https" - elif client.config.hostname.startsWith("http://"): - "http" - else: - "http" # default to HTTP - - # Strip protocol prefix from hostname if present - let cleanHost = if client.config.hostname.startsWith("https://") or - client.config.hostname.startsWith("http://"): - client.config.hostname.split("://", 1)[1] - else: - client.config.hostname - - result = scheme & "://" & cleanHost & ":" & $client.config.port - -proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T] = - ## Handle HTTP response and convert to ApiResponse - let statusCode = parseInt(split(response.status, " ")[0]) - if statusCode >= 200 and statusCode < 300: - try: - if client.debug: - echo "Raw response body: ", response.body - let jsonData = parseJson(response.body) - - # Handle nested response structures like {"breeders": [...]} or {"credentials": [...]} - if jsonData.kind == JObject: - # Check for wrapped list responses - when T is seq: - for key, value in jsonData.pairs: - if value.kind == JArray: - result = ApiResponse[T](success: true, data: value.to(T), error: "") - return - # For single objects, try direct conversion first (bare objects) - else: - try: - result = ApiResponse[T](success: true, data: jsonData.to(T), error: "") - return - except CatchableError: - # If direct conversion fails, try finding wrapped object - for key, value in jsonData.pairs: - if value.kind == JObject: - result = ApiResponse[T](success: true, data: value.to(T), error: "") - return - - # Fallback to direct conversion - result = ApiResponse[T](success: true, data: jsonData.to(T), error: "") - except CatchableError as e: - result = ApiResponse[T](success: false, data: default(T), error: "JSON parse error: " & e.msg) - else: - try: - if client.debug: - echo "HTTP Error Response Body: ", response.body - let errorJson = parseJson(response.body) - let errorMsg = errorJson{"message"}.getStr("HTTP Error: " & $statusCode) - result = ApiResponse[T](success: false, data: default(T), error: errorMsg) - except CatchableError: - result = ApiResponse[T](success: false, data: default(T), error: "HTTP Error: " & $statusCode) - -proc handleError*(client: GodonClient, response: Response): ref CatchableError = - ## Convert HTTP error response to exception - let statusCode = parseInt(split(response.status, " ")[0]) - var errorMsg = "HTTP Error: " & $statusCode - try: - let errorJson = parseJson(response.body) - errorMsg = errorJson{"message"}.getStr(errorMsg) - except CatchableError: - discard - - newException(CatchableError, errorMsg) \ No newline at end of file diff --git a/src/godon/credential.nim b/src/godon/credential.nim deleted file mode 100644 index d6f9363..0000000 --- a/src/godon/credential.nim +++ /dev/null @@ -1,165 +0,0 @@ -import std/[httpclient, json, uri, tables] -import yaml -import client, types - -# Credential API client methods - -proc listCredentials*(client: GodonClient): ApiResponse[seq[Credential]] = - ## List all credentials - let url = client.baseUrl() & "/credentials" - - try: - let response = client.httpClient.get(url) - if response.code == Http200: - let body = parseJson(response.body) - var credentials: seq[Credential] = @[] - - # Handle both bare array and wrapped responses - let jsonArray = if body.kind == JArray: - body - elif body.hasKey("credentials"): - body["credentials"] - else: - raise newException(ValueError, "Unexpected response format") - - for credJson in jsonArray.items: - credentials.add(parseCredentialFromJson(credJson)) - - return ApiResponse[seq[Credential]]( - success: true, - data: credentials, - error: "" - ) - else: - return ApiResponse[seq[Credential]]( - success: false, - data: @[], - error: "Failed to list credentials: " & response.status - ) - except Exception as e: - return ApiResponse[seq[Credential]]( - success: false, - data: @[], - error: "Exception: " & e.msg - ) - -proc createCredential*(client: GodonClient, credentialData: JsonNode): ApiResponse[Credential] = - ## Create a new credential - let url = client.baseUrl() & "/credentials" - - try: - client.httpClient.headers = newHttpHeaders({"Content-Type": "application/json"}) - let response = client.httpClient.post(url, $credentialData) - if response.code == Http201: - let body = parseJson(response.body) - let credential = parseCredentialFromJson(body) - return ApiResponse[Credential]( - success: true, - data: credential, - error: "" - ) - else: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Failed to create credential: " & response.status - ) - except Exception as e: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Exception: " & e.msg - ) - -proc getCredential*(client: GodonClient, credentialId: string): ApiResponse[Credential] = - ## Get a specific credential by ID (including content) - let url = client.baseUrl() & "/credentials/" & encodeUrl(credentialId) - - try: - let response = client.httpClient.get(url) - if response.code == Http200: - let body = parseJson(response.body) - let credential = parseCredentialFromJson(body) - return ApiResponse[Credential]( - success: true, - data: credential, - error: "" - ) - else: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Failed to get credential: " & response.status - ) - except Exception as e: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Exception: " & e.msg - ) - -proc deleteCredential*(client: GodonClient, credentialId: string): ApiResponse[JsonNode] = - ## Delete a credential by ID - let url = client.baseUrl() & "/credentials/" & encodeUrl(credentialId) - - try: - let response = client.httpClient.delete(url) - if response.code == Http200: - let body = parseJson(response.body) - - return ApiResponse[JsonNode]( - success: true, - data: body, - error: "" - ) - else: - return ApiResponse[JsonNode]( - success: false, - data: nil, - error: "Failed to delete credential: " & response.status - ) - except Exception as e: - return ApiResponse[JsonNode]( - success: false, - data: nil, - error: "Exception: " & e.msg - ) - -proc createCredentialFromYaml*(client: GodonClient, yamlContent: string): ApiResponse[Credential] = - ## Create credential from YAML content - ## This is a convenience method that parses YAML and converts to JSON - - try: - # Parse YAML to a generic table, then construct JsonNode manually - let yamlData = yaml.loadAs[Table[string, string]](yamlContent) - - # Build JsonNode from the parsed YAML - var credentialData = newJObject() - - # Add required fields - credentialData.add("name", newJString(yamlData["name"])) - credentialData.add("credentialType", newJString(yamlData["credentialType"])) - - # Add optional fields - if "description" in yamlData: - credentialData.add("description", newJString(yamlData["description"])) - else: - credentialData.add("description", newJString("")) - - # Ensure content field exists for credentials - if "content" in yamlData: - credentialData.add("content", newJString(yamlData["content"])) - else: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Missing required field: content" - ) - - return client.createCredential(credentialData) - except Exception as e: - return ApiResponse[Credential]( - success: false, - data: Credential(), - error: "Failed to parse YAML: " & e.msg - ) \ No newline at end of file diff --git a/src/godon/types.nim b/src/godon/types.nim deleted file mode 100644 index 42972d4..0000000 --- a/src/godon/types.nim +++ /dev/null @@ -1,91 +0,0 @@ -## Godon API Types -## Generated based on OpenAPI specification - -import std/json - -type - BreederSummary* = object - id*: string - name*: string - status*: string - createdAt*: string - - Breeder* = object - id*: string - name*: string - status*: string - config*: JsonNode - createdAt*: string - - BreederCreateRequest* = object - name*: string - config*: JsonNode - - BreederUpdateRequest* = object - uuid*: string - name*: string - description*: string - config*: string - - Credential* = object - id*: string - name*: string - credentialType*: string - description*: string - windmillVariable*: string - createdAt*: string - lastUsedAt*: string - content*: string - - ApiConfig* = object - hostname*: string - port*: int - apiVersion*: string - - ApiResponse*[T] = object - success*: bool - data*: T - error*: string - - ApiResponseSingle*[T] = object - success*: bool - data*: T - error*: string - - ApiResponseList*[T] = object - success*: bool - data*: seq[T] - error*: string - - ApiError* = object - code*: int - message*: string - details*: JsonNode - -# Helper proc to parse credential from JSON -proc parseCredentialFromJson*(json: JsonNode): Credential = - result = Credential() - if json.hasKey("id"): - result.id = json["id"].getStr() - if json.hasKey("name"): - result.name = json["name"].getStr() - if json.hasKey("credentialType"): - result.credentialType = json["credentialType"].getStr() - if json.hasKey("description"): - result.description = json["description"].getStr() - else: - result.description = "" - if json.hasKey("windmillVariable"): - result.windmillVariable = json["windmillVariable"].getStr() - if json.hasKey("createdAt"): - result.createdAt = json["createdAt"].getStr() - else: - result.createdAt = "" - if json.hasKey("lastUsedAt"): - result.lastUsedAt = json["lastUsedAt"].getStr() - else: - result.lastUsedAt = "" - if json.hasKey("content"): - result.content = json["content"].getStr() - else: - result.content = "" \ No newline at end of file diff --git a/src/godon_cli.nim b/src/godon_cli.nim deleted file mode 100644 index 571c302..0000000 --- a/src/godon_cli.nim +++ /dev/null @@ -1,430 +0,0 @@ -import std/[parseopt, strutils, os, json] -import yaml, yaml/presenter, yaml/dumping -import godon/[client, breeder, credential, types] - -type - OutputFormat* = enum - Text = "text" - Json = "json" - Yaml = "yaml" - -proc writeHelp() = - echo """Godon CLI - Command line interface for Godon API - -Usage: - godon_cli [options] [command-options] - -Commands: - breeder list List all configured breeders - breeder create --name --file Create a breeder from file - breeder show --id Show breeder details - breeder update --file Update a breeder from file - breeder stop --id Stop breeder workers (graceful shutdown) - breeder start --id Start/resume a stopped breeder - breeder purge [--force] --id Delete a breeder (use --force to cancel workers immediately) - - credential list List all credentials - credential create --file Create a credential from file - credential show --id Show credential details (including content) - credential delete --id Delete a credential - -Global Options: - --hostname, -h Godon hostname (default: localhost) - --port, -p Godon port (default: 8080) - --api-version, -v API version (default: v0) - --output, -o Output format: text, json, or yaml (default: text) - --force Force immediate deletion (skip graceful shutdown) - --insecure Skip SSL certificate verification (HTTPS only) - --help Show this help message - -Examples: - godon_cli breeder list - godon_cli --hostname api.example.com --port 9090 breeder list - godon_cli breeder create --name my-breeder --file breeder-config.yaml - godon_cli breeder show --id 550e8400-e29b-41d4-a716-446655440000 - godon_cli breeder stop --id 550e8400-e29b-41d4-a716-446655440000 - godon_cli breeder purge --force --id 550e8400-e29b-41d4-a716-446655440000 - godon_cli credential list - godon_cli credential create --file credential.yaml - godon_cli credential show --id 550e8400-e29b-41d4-a716-446655440001 -""" - -proc writeError(message: string) = - stderr.writeLine("Error: " & message) - quit(1) - -proc parseArgs(): (string, string, int, string, bool, bool, bool, OutputFormat, seq[string]) = - var command = "" - var hostname = "localhost" - var port = 8080 - var apiVersion = "v0" - var insecure = false - var debug = false - var force = false - var outputFormat = OutputFormat.Text - var args: seq[string] = @[] - - var p = initOptParser(commandLineParams()) - - for kind, key, val in p.getopt(): - case kind - of cmdArgument: - if command.len == 0: - command = key - else: - args.add(key) - - of cmdLongOption, cmdShortOption: - case key.normalize() - of "hostname": - hostname = val - of "port": - if val.len == 0: - writeError("Port option requires a value") - try: - port = parseInt(val) - except ValueError: - writeError("Invalid port number: " & val) - of "api-version": - apiVersion = val - of "file": - # Reconstruct as argument for subcommand parsing - args.add("--file=" & val) - of "name": - # Reconstruct as argument for subcommand parsing - args.add("--name=" & val) - of "id": - # Reconstruct as argument for subcommand parsing - args.add("--id=" & val) - of "force": - force = true - of "insecure": - insecure = true - of "debug": - debug = true - of "output", "o": - if val.len == 0: - writeError("Output option requires a value (text, json, or yaml)") - case val.normalize() - of "text": - outputFormat = OutputFormat.Text - of "json": - outputFormat = OutputFormat.Json - of "yaml": - outputFormat = OutputFormat.Yaml - else: - writeError("Unknown output format: " & val & ". Use text, json, or yaml") - of "help": - writeHelp() - quit(0) - else: - writeError("Unknown option: " & key) - - of cmdEnd: - discard - - if command.len == 0: - writeHelp() - quit(0) - - # Also check for DEBUG environment variable - if existsEnv("DEBUG"): - debug = true - - (command, hostname, port, apiVersion, insecure, debug, force, outputFormat, args) - -proc formatOutput*[T](data: T, outputFormat: OutputFormat) = - ## Format data according to output format preference - case outputFormat - of OutputFormat.Text: - # Text mode is handled by caller with custom formatting - discard - of OutputFormat.Json: - echo pretty(%*data) - of OutputFormat.Yaml: - # Convert to YAML by dumping JSON as text and transforming it - let jsonString = pretty(%*data) - var dumper = blockOnlyDumper() - echo dumper.transform(jsonString) - -proc handleBreederCommand(client: GodonClient, command: string, args: seq[string], force: bool, outputFormat: OutputFormat) = - let subCommand = if args.len > 0: args[0] else: "" - - case subCommand: - of "list": - let response = client.listBreeders() - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeders:" - for breeder in response.data: - echo " ID: ", breeder.id - echo " Name: ", breeder.name - echo " Status: ", breeder.status - echo " Created: ", breeder.createdAt - echo " ---" - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "create": - var file = "" - var name = "" - for arg in args: - if arg.startsWith("--file="): - file = arg.split("=")[1] - elif arg.startsWith("--name="): - name = arg.split("=")[1] - - if file.len == 0: - writeError("breeder create requires --file ") - - if name.len == 0: - writeError("breeder create requires --name ") - - if not fileExists(file): - writeError("File not found: " & file) - - let content = readFile(file) - let response = client.createBreederFromYamlWithName(content, name) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeder created successfully:" - echo " ID: ", response.data.id - echo " Name: ", response.data.name - echo " Status: ", response.data.status - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "show": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("breeder show requires --id ") - - let response = client.getBreeder(id) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeder Details:" - echo " ID: ", response.data.id - echo " Name: ", response.data.name - echo " Status: ", response.data.status - echo " Config: ", pretty(response.data.config) - echo " Created: ", response.data.createdAt - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "update": - var file = "" - for arg in args: - if arg.startsWith("--file="): - file = arg.split("=")[1] - break - - if file.len == 0: - writeError("breeder update requires --file ") - - if not fileExists(file): - writeError("File not found: " & file) - - let content = readFile(file) - let response = client.updateBreederFromYaml(content) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeder updated successfully:" - echo " ID: ", response.data.id - echo " Name: ", response.data.name - echo " Status: ", response.data.status - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "purge": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("breeder purge requires --id ") - - let response = client.deleteBreeder(id, force) - if response.success: - if outputFormat == OutputFormat.Text: - if force: - echo "Breeder force deleted (workers cancelled): ", id - else: - echo "Breeder deleted: ", id - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "stop": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("breeder stop requires --id ") - - let response = client.stopBreeder(id) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeder stop requested (graceful shutdown): ", id - echo "Workers will finish current trial before stopping." - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "start": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("breeder start requires --id ") - - let response = client.startBreeder(id) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Breeder started/resumed: ", id - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - else: - writeError("Unknown breeder command: " & subCommand) - -proc handleCredentialCommand(client: GodonClient, command: string, args: seq[string], outputFormat: OutputFormat) = - let subCommand = if args.len > 0: args[0] else: "" - - case subCommand: - of "list": - let response = client.listCredentials() - if response.success: - if outputFormat == OutputFormat.Text: - echo "Credentials:" - for credential in response.data: - echo " ID: ", credential.id - echo " Name: ", credential.name - echo " Type: ", credential.credentialType - echo " Description: ", credential.description - echo " windmillVariable: ", credential.windmillVariable - echo " Created: ", credential.createdAt - echo " ---" - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "create": - var file = "" - for arg in args: - if arg.startsWith("--file="): - file = arg.split("=")[1] - break - - if file.len == 0: - writeError("credential create requires --file ") - - if not fileExists(file): - writeError("File not found: " & file) - - let content = readFile(file) - let response = client.createCredentialFromYaml(content) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Credential created successfully:" - echo " ID: ", response.data.id - echo " Name: ", response.data.name - echo " Type: ", response.data.credentialType - echo " windmillVariable: ", response.data.windmillVariable - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "show": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("credential show requires --id ") - - let response = client.getCredential(id) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Credential Details:" - echo " ID: ", response.data.id - echo " Name: ", response.data.name - echo " Type: ", response.data.credentialType - echo " Description: ", response.data.description - echo " windmillVariable: ", response.data.windmillVariable - echo " Created: ", response.data.createdAt - echo " Last Used: ", response.data.lastUsedAt - echo " Content:" - echo " ", response.data.content - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - of "delete": - var id = "" - for arg in args: - if arg.startsWith("--id="): - id = arg.split("=")[1] - break - - if id.len == 0: - writeError("credential delete requires --id ") - - let response = client.deleteCredential(id) - if response.success: - if outputFormat == OutputFormat.Text: - echo "Credential deleted successfully: ", id - else: - formatOutput(response.data, outputFormat) - else: - writeError(response.error) - - else: - writeError("Unknown credential command: " & subCommand) - -let (command, hostname, port, apiVersion, insecure, debug, force, outputFormat, args) = parseArgs() - -let godonClient = newGodonClient(hostname, port, apiVersion, insecure, debug) - -case command: -of "breeder": - if args.len == 0: - writeError("breeder command requires a subcommand (list, create, show, update, stop, start, purge)") - handleBreederCommand(godonClient, command, args, force, outputFormat) - -of "credential": - if args.len == 0: - writeError("credential command requires a subcommand (list, create, show, delete)") - handleCredentialCommand(godonClient, command, args, outputFormat) - -else: - writeError("Unknown command: " & command) \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a7c2100 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,98 @@ +pub mod client; + +pub use client::GodonClient; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BreederSummary { + pub id: String, + pub name: String, + pub status: String, + #[serde(rename = "createdAt")] + pub created_at: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Breeder { + pub id: String, + pub name: String, + pub status: String, + pub config: serde_json::Value, + #[serde(rename = "createdAt")] + pub created_at: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BreederCreateRequest { + pub name: String, + pub config: serde_json::Value, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BreederUpdateRequest { + pub uuid: String, + pub name: String, + pub description: String, + pub config: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Credential { + pub id: String, + pub name: String, + #[serde(rename = "credentialType")] + pub credential_type: String, + pub description: Option, + #[serde(rename = "windmillVariable")] + pub windmill_variable: String, + #[serde(rename = "createdAt")] + pub created_at: Option, + #[serde(rename = "lastUsedAt")] + pub last_used_at: Option, + pub content: Option, +} + +#[derive(Debug, Clone)] +pub struct ApiConfig { + pub hostname: String, + pub port: u16, + pub api_version: String, +} + +impl Default for ApiConfig { + fn default() -> Self { + Self { + hostname: "localhost".to_string(), + port: 8080, + api_version: "v0".to_string(), + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ApiResponse { + pub success: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub data: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option, +} + +impl ApiResponse { + pub fn success(data: T) -> Self { + Self { + success: true, + data: Some(data), + error: None, + } + } + + pub fn error(msg: impl Into) -> Self { + Self { + success: false, + data: None, + error: Some(msg.into()), + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..27fbbeb --- /dev/null +++ b/src/main.rs @@ -0,0 +1,393 @@ +use clap::{Parser, Subcommand}; +use godon_cli::{Breeder, BreederSummary, Credential, GodonClient}; +use std::path::PathBuf; + +#[derive(Parser)] +#[command(name = "godon_cli")] +#[command(about = "CLI for the Godon API", long_about = None)] +struct Cli { + #[arg(short = 'H', long, default_value = "localhost")] + hostname: String, + + #[arg(short, long, default_value_t = 8080)] + port: u16, + + #[arg(short = 'V', long, default_value = "v0")] + api_version: String, + + #[arg(short, long, value_enum, default_value = "text")] + output: OutputFormat, + + #[arg(long)] + insecure: bool, + + #[arg(long, env = "DEBUG")] + debug: bool, + + #[command(subcommand)] + command: Commands, +} + +#[derive(clap::ValueEnum, Clone, Default)] +enum OutputFormat { + #[default] + Text, + Json, + Yaml, +} + +#[derive(Subcommand)] +enum Commands { + Breeder { + #[command(subcommand)] + subcommand: BreederCommands, + }, + Credential { + #[command(subcommand)] + subcommand: CredentialCommands, + }, +} + +#[derive(Subcommand)] +enum BreederCommands { + List, + + Create { + #[arg(long)] + name: String, + #[arg(long)] + file: PathBuf, + }, + + Show { + #[arg(long)] + id: String, + }, + + Update { + #[arg(long)] + file: PathBuf, + }, + + Stop { + #[arg(long)] + id: String, + }, + + Start { + #[arg(long)] + id: String, + }, + + Purge { + #[arg(long)] + id: String, + #[arg(long)] + force: bool, + }, +} + +#[derive(Subcommand)] +enum CredentialCommands { + List, + + Create { + #[arg(long)] + file: PathBuf, + }, + + Show { + #[arg(long)] + id: String, + }, + + Delete { + #[arg(long)] + id: String, + }, +} + +fn write_error(message: &str) -> ! { + eprintln!("Error: {}", message); + std::process::exit(1); +} + +fn format_output(data: &T, format: &OutputFormat) { + match format { + OutputFormat::Json => { + println!("{}", serde_json::to_string_pretty(data).unwrap_or_default()); + } + OutputFormat::Yaml => { + println!("{}", serde_yaml::to_string(data).unwrap_or_default()); + } + OutputFormat::Text => {} + } +} + +fn format_breeder_list(breeders: &[BreederSummary]) { + println!("Breeders:"); + for breeder in breeders { + println!(" ID: {}", breeder.id); + println!(" Name: {}", breeder.name); + println!(" Status: {}", breeder.status); + println!(" Created: {}", breeder.created_at); + println!(" ---"); + } +} + +fn format_breeder(breeder: &Breeder) { + println!("Breeder Details:"); + println!(" ID: {}", breeder.id); + println!(" Name: {}", breeder.name); + println!(" Status: {}", breeder.status); + println!(" Config: {}", serde_json::to_string_pretty(&breeder.config).unwrap_or_default()); + println!(" Created: {}", breeder.created_at); +} + +fn format_breeder_summary(breeder: &BreederSummary) { + println!("Breeder created successfully:"); + println!(" ID: {}", breeder.id); + println!(" Name: {}", breeder.name); + println!(" Status: {}", breeder.status); +} + +fn format_credential_list(credentials: &[Credential]) { + println!("Credentials:"); + for credential in credentials { + println!(" ID: {}", credential.id); + println!(" Name: {}", credential.name); + println!(" Type: {}", credential.credential_type); + println!(" Description: {}", credential.description.as_deref().unwrap_or("")); + println!(" windmillVariable: {}", credential.windmill_variable); + println!(" Created: {}", credential.created_at.as_deref().unwrap_or("")); + println!(" ---"); + } +} + +fn format_credential(credential: &Credential) { + println!("Credential Details:"); + println!(" ID: {}", credential.id); + println!(" Name: {}", credential.name); + println!(" Type: {}", credential.credential_type); + println!(" Description: {}", credential.description.as_deref().unwrap_or("")); + println!(" windmillVariable: {}", credential.windmill_variable); + println!(" Created: {}", credential.created_at.as_deref().unwrap_or("")); + println!(" Last Used: {}", credential.last_used_at.as_deref().unwrap_or("")); + println!(" Content:"); + println!(" {}", credential.content.as_deref().unwrap_or("")); +} + +fn format_credential_created(credential: &Credential) { + println!("Credential created successfully:"); + println!(" ID: {}", credential.id); + println!(" Name: {}", credential.name); + println!(" Type: {}", credential.credential_type); + println!(" windmillVariable: {}", credential.windmill_variable); +} + +#[tokio::main] +async fn main() { + let cli = Cli::parse(); + + let client = match GodonClient::new( + cli.hostname, + cli.port, + cli.api_version, + cli.insecure, + cli.debug, + ) { + Ok(c) => c, + Err(e) => write_error(&e.to_string()), + }; + + match cli.command { + Commands::Breeder { subcommand } => handle_breeder_command(&client, subcommand, &cli.output).await, + Commands::Credential { subcommand } => handle_credential_command(&client, subcommand, &cli.output).await, + } +} + +async fn handle_breeder_command(client: &GodonClient, cmd: BreederCommands, output: &OutputFormat) { + match cmd { + BreederCommands::List => { + let response = client.list_breeders().await; + if response.success { + if let Some(breeders) = response.data { + if matches!(output, OutputFormat::Text) { + format_breeder_list(&breeders); + } else { + format_output(&breeders, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Create { name, file } => { + let content = match std::fs::read_to_string(&file) { + Ok(c) => c, + Err(e) => write_error(&format!("Failed to read file: {}", e)), + }; + + let response = client.create_breeder_from_yaml(&content, &name).await; + if response.success { + if let Some(breeder) = response.data { + if matches!(output, OutputFormat::Text) { + format_breeder_summary(&breeder); + } else { + format_output(&breeder, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Show { id } => { + let response = client.get_breeder(&id).await; + if response.success { + if let Some(breeder) = response.data { + if matches!(output, OutputFormat::Text) { + format_breeder(&breeder); + } else { + format_output(&breeder, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Update { file } => { + let content = match std::fs::read_to_string(&file) { + Ok(c) => c, + Err(e) => write_error(&format!("Failed to read file: {}", e)), + }; + + let response = client.update_breeder_from_yaml(&content).await; + if response.success { + if matches!(output, OutputFormat::Text) { + if let Some(ref data) = response.data { + let id = data.get("id").and_then(|v| v.as_str()).unwrap_or("unknown"); + println!("Breeder updated successfully: {}", id); + } + } else if let Some(data) = response.data { + format_output(&data, output); + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Stop { id } => { + let response = client.stop_breeder(&id).await; + if response.success { + if matches!(output, OutputFormat::Text) { + println!("Breeder stop requested (graceful shutdown): {}", id); + println!("Workers will finish current trial before stopping."); + } else if let Some(data) = response.data { + format_output(&data, output); + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Start { id } => { + let response = client.start_breeder(&id).await; + if response.success { + if matches!(output, OutputFormat::Text) { + println!("Breeder started/resumed: {}", id); + } else if let Some(data) = response.data { + format_output(&data, output); + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + BreederCommands::Purge { id, force } => { + let response = client.delete_breeder(&id, force).await; + if response.success { + if matches!(output, OutputFormat::Text) { + if force { + println!("Breeder force deleted (workers cancelled): {}", id); + } else { + println!("Breeder deleted: {}", id); + } + } else if let Some(data) = response.data { + format_output(&data, output); + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + } +} + +async fn handle_credential_command(client: &GodonClient, cmd: CredentialCommands, output: &OutputFormat) { + match cmd { + CredentialCommands::List => { + let response = client.list_credentials().await; + if response.success { + if let Some(credentials) = response.data { + if matches!(output, OutputFormat::Text) { + format_credential_list(&credentials); + } else { + format_output(&credentials, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + CredentialCommands::Create { file } => { + let content = match std::fs::read_to_string(&file) { + Ok(c) => c, + Err(e) => write_error(&format!("Failed to read file: {}", e)), + }; + + let response = client.create_credential_from_yaml(&content).await; + if response.success { + if let Some(credential) = response.data { + if matches!(output, OutputFormat::Text) { + format_credential_created(&credential); + } else { + format_output(&credential, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + CredentialCommands::Show { id } => { + let response = client.get_credential(&id).await; + if response.success { + if let Some(credential) = response.data { + if matches!(output, OutputFormat::Text) { + format_credential(&credential); + } else { + format_output(&credential, output); + } + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + + CredentialCommands::Delete { id } => { + let response = client.delete_credential(&id).await; + if response.success { + if matches!(output, OutputFormat::Text) { + println!("Credential deleted successfully: {}", id); + } else if let Some(data) = response.data { + format_output(&data, output); + } + } else { + write_error(response.error.as_deref().unwrap_or("Unknown error")); + } + } + } +}