From 563bb47097e4bf41238abe1f646b2116288d8633 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 05:28:39 +0200 Subject: [PATCH 01/28] partway there --- Cargo.lock | 2130 ++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 4 + src/commands.rs | 127 +-- src/config.rs | 125 ++- src/main.rs | 39 +- src/modes.rs | 291 +++---- 6 files changed, 2133 insertions(+), 583 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7f944a..e7aabf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,55 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" -version = "0.7.19" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -49,22 +89,93 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "async-broadcast" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "async-trait" +version = "0.1.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backoff" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" +dependencies = [ + "getrandom", + "instant", + "rand", +] + +[[package]] +name = "backtrace" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] [[package]] name = "base-x" @@ -72,6 +183,18 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "beef" version = "0.5.2" @@ -84,6 +207,21 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bstr" version = "0.2.17" @@ -92,26 +230,35 @@ checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", - "regex-automata", + "regex-automata 0.1.10", ] [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] -name = "cc" -version = "1.0.73" +name = "byteorder" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] -name = "cfg-if" -version = "0.1.10" +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "cc" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +dependencies = [ + "shlex 1.3.0", +] [[package]] name = "cfg-if" @@ -121,17 +268,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ + "android-tzdata", "iana-time-zone", "js-sys", - "num-integer", "num-traits", - "time 0.1.44", + "serde", "wasm-bindgen", - "winapi", + "windows-targets", ] [[package]] @@ -142,7 +289,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags", + "bitflags 1.3.2", "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", @@ -151,32 +298,32 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.16" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", - "indexmap", + "indexmap 1.9.3", "once_cell", "strsim 0.10.0", "termcolor", - "textwrap 0.15.0", + "textwrap 0.16.1", ] [[package]] name = "clap_derive" -version = "3.2.15" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ "heck", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.98", + "syn 1.0.109", ] [[package]] @@ -188,106 +335,110 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const_fn" -version = "0.4.9" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373e9fafaa20882876db20562275ff58d50e0caa2590077fe7ce7bef90211d0d" + +[[package]] +name = "core-foundation" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] -name = "crossbeam" -version = "0.8.2" +name = "cpufeatures" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-channel 0.5.6", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils 0.8.11", + "libc", ] [[package]] -name = "crossbeam-channel" -version = "0.4.4" +name = "crossbeam" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" dependencies = [ - "crossbeam-utils 0.7.2", - "maybe-uninit", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", ] [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.10" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", - "memoffset", - "once_cell", - "scopeguard", + "crossbeam-utils", ] [[package]] name = "crossbeam-queue" -version = "0.3.6" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.7.2" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] -name = "crossbeam-utils" -version = "0.8.11" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "cfg-if 1.0.0", - "once_cell", + "generic-array", + "typenum", ] [[package]] @@ -296,8 +447,18 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core 0.20.10", + "darling_macro 0.20.10", ] [[package]] @@ -311,7 +472,21 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.9.3", - "syn 1.0.98", + "syn 1.0.109", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.11.1", + "syn 2.0.79", ] [[package]] @@ -320,18 +495,29 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ - "darling_core", + "darling_core 0.10.2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core 0.20.10", "quote", - "syn 1.0.98", + "syn 2.0.79", ] [[package]] name = "defer-drop" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "828aca0e5e4341b0320a319209cbc6255b8b06254849ce8a5f33d33f7f2fa0f0" +checksum = "f613ec9fa66a6b28cdb1842b27f9adf24f39f9afc4dcdd9fdecee4aca7945c57" dependencies = [ - "crossbeam-channel 0.4.4", + "crossbeam-channel", "once_cell", ] @@ -341,11 +527,11 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" dependencies = [ - "darling", + "darling 0.10.2", "derive_builder_core", "proc-macro2", "quote", - "syn 1.0.98", + "syn 1.0.109", ] [[package]] @@ -354,10 +540,10 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" dependencies = [ - "darling", + "darling 0.10.2", "proc-macro2", "quote", - "syn 1.0.98", + "syn 1.0.109", ] [[package]] @@ -366,6 +552,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dirs" version = "4.0.0" @@ -381,7 +577,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] @@ -419,12 +615,50 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -439,151 +673,685 @@ dependencies = [ ] [[package]] -name = "fnv" -version = "1.0.7" +name = "equivalent" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "fuzzy-matcher" -version = "0.3.7" +name = "event-listener" +version = "5.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" dependencies = [ - "thread_local", + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] -name = "getrandom" -version = "0.2.7" +name = "event-listener-strategy" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "event-listener", + "pin-project-lite", ] [[package]] -name = "hashbrown" -version = "0.12.3" +name = "fluent-uri" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "17c704e9dbe1ddd863da1e6ff3567795087b1eb201ce80d8fa81162e1516500d" +dependencies = [ + "bitflags 1.3.2", +] [[package]] -name = "heck" -version = "0.4.0" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "form_urlencoded" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ - "libc", + "percent-encoding", ] [[package]] -name = "humantime" -version = "2.1.0" +name = "futures" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] [[package]] -name = "iana-time-zone" -version = "0.1.46" +name = "futures-channel" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2bfd338099682614d3ee3fe0cd72e0b6a41ca6a87f6a74a3bd593c91650501" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ - "android_system_properties", - "core-foundation-sys", - "js-sys", - "wasm-bindgen", - "winapi", + "futures-core", + "futures-sink", ] [[package]] -name = "ident_case" -version = "1.0.1" +name = "futures-core" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] -name = "indexmap" -version = "1.9.1" +name = "futures-io" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] -name = "itertools" -version = "0.10.3" +name = "futures-macro" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ - "either", + "proc-macro2", + "quote", + "syn 2.0.79", ] [[package]] -name = "itoa" -version = "1.0.2" +name = "futures-sink" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] -name = "js-sys" -version = "0.3.60" +name = "futures-task" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" -dependencies = [ - "wasm-bindgen", -] +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] -name = "kubesess" -version = "1.2.11" +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ - "assert_cmd", - "clap 3.2.16", - "dirs", - "lazy_static", - "serde", - "serde_yaml", - "skim", - "thiserror", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "fuzzy-matcher" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" +dependencies = [ + "thread_local", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + +[[package]] +name = "headers" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9" +dependencies = [ + "base64 0.21.7", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1 0.10.6", +] + +[[package]] +name = "headers-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" +dependencies = [ + "http", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-http-proxy" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d06dbdfbacf34d996c6fb540a71a684a7aae9056c71951163af8a8a4c07b9a4" +dependencies = [ + "bytes", + "futures-util", + "headers", + "http", + "hyper", + "hyper-rustls", + "hyper-util", + "pin-project-lite", + "rustls-native-certs 0.7.3", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "log", + "rustls", + "rustls-native-certs 0.8.0", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", +] + +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "json-patch" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b1fb8864823fad91877e6caea0baca82e49e8db50f8e5c9f9a453e27d3330fc" +dependencies = [ + "jsonptr", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "jsonpath-rust" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d8fe85bd70ff715f31ce8c739194b423d79811a19602115d611a3ec85d6200" +dependencies = [ + "lazy_static", + "once_cell", + "pest", + "pest_derive", + "regex", + "serde_json", + "thiserror", +] + +[[package]] +name = "jsonptr" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c6e529149475ca0b2820835d3dce8fcc41c6b943ca608d32f35b449255e4627" +dependencies = [ + "fluent-uri", + "serde", + "serde_json", +] + +[[package]] +name = "k8s-openapi" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8847402328d8301354c94d605481f25a6bdc1ed65471fd96af8eca71141b13" +dependencies = [ + "base64 0.22.1", + "chrono", + "serde", + "serde-value", + "serde_json", +] + +[[package]] +name = "kube" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efffeb3df0bd4ef3e5d65044573499c0e4889b988070b08c50b25b1329289a1f" +dependencies = [ + "k8s-openapi", + "kube-client", + "kube-core", + "kube-derive", + "kube-runtime", +] + +[[package]] +name = "kube-client" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf471ece8ff8d24735ce78dac4d091e9fcb8d74811aeb6b75de4d1c3f5de0f1" +dependencies = [ + "base64 0.22.1", + "bytes", + "chrono", + "either", + "futures", + "home", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-http-proxy", + "hyper-rustls", + "hyper-timeout", + "hyper-util", + "jsonpath-rust", + "k8s-openapi", + "kube-core", + "pem", + "rustls", + "rustls-pemfile", + "secrecy", + "serde", + "serde_json", + "serde_yaml", + "thiserror", + "tokio", + "tokio-util", + "tower", + "tower-http", + "tracing", +] + +[[package]] +name = "kube-core" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f42346d30bb34d1d7adc5c549b691bce7aa3a1e60254e68fab7e2d7b26fe3d77" +dependencies = [ + "chrono", + "form_urlencoded", + "http", + "json-patch", + "k8s-openapi", + "schemars", + "serde", + "serde-value", + "serde_json", + "thiserror", +] + +[[package]] +name = "kube-derive" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9364e04cc5e0482136c6ee8b7fb7551812da25802249f35b3def7aaa31e82ad" +dependencies = [ + "darling 0.20.10", + "proc-macro2", + "quote", + "serde_json", + "syn 2.0.79", +] + +[[package]] +name = "kube-runtime" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fbf1f6ffa98e65f1d2a9a69338bb60605d46be7edf00237784b89e62c9bd44" +dependencies = [ + "ahash", + "async-broadcast", + "async-stream", + "async-trait", + "backoff", + "educe", + "futures", + "hashbrown 0.14.5", + "json-patch", + "jsonptr", + "k8s-openapi", + "kube-client", + "parking_lot", + "pin-project", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "kubesess" +version = "1.2.11" +dependencies = [ + "assert_cmd", + "clap 3.2.25", + "dirs", + "k8s-openapi", + "kube", + "lazy_static", + "serde", + "serde_yaml", + "skim", + "thiserror", + "tokio", + "tokio-macros", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.132" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] -name = "log" -version = "0.4.17" +name = "libredox" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "cfg-if 1.0.0", + "bitflags 2.6.0", + "libc", ] [[package]] -name = "maybe-uninit" -version = "2.0.0" +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" @@ -600,70 +1368,232 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "wasi", + "windows-sys 0.52.0", +] + [[package]] name = "nix" version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", ] [[package]] name = "nix" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", - "cfg-if 1.0.0", + "bitflags 1.3.2", + "cfg-if", "libc", "memoffset", ] [[package]] -name = "num-integer" -version = "0.1.45" +name = "num-traits" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ "num-traits", ] [[package]] -name = "num-traits" -version = "0.2.15" +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ - "autocfg", + "lock_api", + "parking_lot_core", ] [[package]] -name = "num_cpus" -version = "1.13.1" +name = "parking_lot_core" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ - "hermit-abi", + "cfg-if", "libc", + "redox_syscall", + "smallvec", + "windows-targets", ] [[package]] -name = "once_cell" -version = "1.13.0" +name = "pem" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" +dependencies = [ + "base64 0.22.1", + "serde", +] [[package]] -name = "os_str_bytes" -version = "6.2.0" +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d214365f632b123a47fd913301e14c946c61d1c183ee245fa76eb752e59a02dd" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb55586734301717aea2ac313f50b2eb8f60d2fc3dc01d190eefa2e625f60c4e" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "pest_meta" +version = "2.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "pin-project" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "predicates" @@ -701,7 +1631,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.98", + "syn 1.0.109", "version_check", ] @@ -718,77 +1648,121 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.19" +version = "0.5.20+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rayon" -version = "1.5.3" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.3" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel 0.5.6", "crossbeam-deque", - "crossbeam-utils 0.8.11", - "num_cpus", + "crossbeam-utils", ] [[package]] name = "redox_syscall" -version = "0.2.15" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", - "redox_syscall", + "libredox", "thiserror", ] [[package]] name = "regex" -version = "1.6.0" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.3.7", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + +[[package]] +name = "regex-automata" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ "aho-corasick", "memchr", @@ -796,43 +1770,190 @@ dependencies = [ ] [[package]] -name = "regex-automata" -version = "0.1.10" +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.23.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcaf18a4f2be7326cd874a5fa579fae794320a0f388d365dca7e480e55f83f8a" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.79", +] [[package]] -name = "regex-syntax" -version = "0.6.27" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "rustc_version" -version = "0.2.3" +name = "secrecy" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +checksum = "e891af845473308773346dc847b2c23ee78fe442e0472ac50e22a18a93d3ae5a" dependencies = [ - "semver", + "zeroize", ] [[package]] -name = "rustversion" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" - -[[package]] -name = "ryu" -version = "1.0.10" +name = "security-framework" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] [[package]] -name = "scopeguard" -version = "1.1.0" +name = "security-framework-sys" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "semver" @@ -851,42 +1972,64 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.141" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7af873f2c95b99fcb0bd0fe622a43e29514658873c8ceba88c4cb88833a22500" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_derive" -version = "1.0.141" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75743a150d003dd863b51dc809bcad0d73f2102c53632f1e954e738192a3413f" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.98", + "syn 2.0.79", ] [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf3" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_yaml" -version = "0.9.3" +version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27000a1af761b5fe3d1a1d659a9d3fe4b435352d3ad09301545f696932b35d78" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap", + "indexmap 2.6.0", "itoa", "ryu", "serde", @@ -902,11 +2045,33 @@ dependencies = [ "sha1_smol", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha1_smol" -version = "1.0.0" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "sha2" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] [[package]] name = "shlex" @@ -914,6 +2079,21 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "skim" version = "0.9.4" @@ -922,7 +2102,7 @@ checksum = "4b9d19f904221fab15163486d2ce116cb86e60296470bb4e956d6687f04ebbb4" dependencies = [ "atty", "beef", - "bitflags", + "bitflags 1.3.2", "chrono", "clap 2.34.0", "crossbeam", @@ -935,14 +2115,45 @@ dependencies = [ "nix 0.19.1", "rayon", "regex", - "shlex", - "time 0.2.27", + "shlex 0.1.1", + "time", "timer", "tuikit", "unicode-width", "vte", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "standback" version = "0.2.17" @@ -976,7 +2187,7 @@ dependencies = [ "quote", "serde", "serde_derive", - "syn 1.0.98", + "syn 1.0.109", ] [[package]] @@ -991,8 +2202,8 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha1", - "syn 1.0.98", + "sha1 0.6.1", + "syn 1.0.109", ] [[package]] @@ -1019,11 +2230,23 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[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 = "1.0.98" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -1032,15 +2255,21 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "term" version = "0.7.0" @@ -1054,9 +2283,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -1078,50 +2307,40 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.79", ] [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ + "cfg-if", "once_cell", ] -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.2.27" @@ -1157,7 +2376,7 @@ dependencies = [ "proc-macro2", "quote", "standback", - "syn 1.0.98", + "syn 1.0.109", ] [[package]] @@ -1169,43 +2388,200 @@ dependencies = [ "chrono", ] +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "slab", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8437150ab6bbc8c5f0f519e3d5ed4aa883a83dd4cdd3d1b21f9482936046cb97" +dependencies = [ + "base64 0.22.1", + "bitflags 2.6.0", + "bytes", + "http", + "http-body", + "mime", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[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.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +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 = "tuikit" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "667c8e002675e76d98358d8869021793a472d28e3a50fbd750284a1d211abd09" dependencies = [ - "bitflags", + "bitflags 1.3.2", "lazy_static", "log", - "nix 0.24.2", + "nix 0.24.3", "term", "unicode-width", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unsafe-libyaml" -version = "0.2.1" +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 = "9dc1c637311091be28e5d462c07db78081e5828da80ba22605c81c4ad6f7f813" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "utf8parse" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "vec_map" @@ -1215,9 +2591,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vte" @@ -1232,9 +2608,9 @@ dependencies = [ [[package]] name = "vte_generate_state_changes" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d257817081c7dffcdbab24b9e62d2def62e2ff7d00b1c20062551e6cccc145ff" +checksum = "2e369bee1b05d510a7b4ed645f5faa90619e05437111783ea5848f28d97d3c2e" dependencies = [ "proc-macro2", "quote", @@ -1250,10 +2626,13 @@ dependencies = [ ] [[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] [[package]] name = "wasi" @@ -1263,34 +2642,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.98", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1298,22 +2678,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 1.0.98", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "winapi" @@ -1333,11 +2713,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -1345,3 +2725,121 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[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_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index c7ab169..0cf903b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,10 @@ serde = { version = "1.0.141", features = ["derive"] } lazy_static = "1.4.0" skim = "0.9.4" thiserror = "1.0.56" +kube = { version = "0.96.0", features = ["runtime", "client", "derive", "config"] } +k8s-openapi = { version = "0.23.0", features = ["latest"] } +tokio = { version = "1.40.0", features = ["full"] } +tokio-macros = "=2.4.0" [dev-dependencies] assert_cmd = "2.0" diff --git a/src/commands.rs b/src/commands.rs index 8d961f2..c76ca4c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,68 +1,69 @@ -use crate::{error::SetContextError, model::KubeConfig}; use crate::config; +use crate::{error::SetContextError, model::KubeConfig}; use std::{ io::Cursor, process::{Command, Stdio}, }; extern crate skim; +use kube::config::Kubeconfig; use skim::prelude::*; -pub fn set_default_namespace(ns: &str, ctx: &str) { - Command::new("kubectl") - .arg("config") - .arg(format!( - "--kubeconfig={}/.kube/config", - dirs::home_dir().unwrap().display() - )) - .arg("set-context") - .arg(ctx) - .arg(format!("--namespace={}", ns)) - .stdout(Stdio::null()) - .spawn() - .unwrap() - .wait() - .unwrap(); -} - -pub fn set_default_context(ctx: &str) { - Command::new("kubectl") - .arg("config") - .arg(format!( - "--kubeconfig={}/.kube/config", - dirs::home_dir().unwrap().display() - )) - .arg("use-context") - .arg(ctx) - .stdout(Stdio::null()) - .spawn() - .unwrap() - .wait() - .unwrap(); -} - -pub fn get_namespaces() -> Vec { - let output = Command::new("kubectl") - .args(["get", "namespace", "-o=custom-columns=Name:.metadata.name"]) - .output() - .unwrap(); - - let string = String::from_utf8(output.stdout).unwrap(); - string.lines().skip(1).map(ToOwned::to_owned).collect() -} - -pub fn get_current_context() -> String { - let output = Command::new("kubectl") - .args(["config", "current-context"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap() - .wait_with_output() - .unwrap(); - - String::from_utf8(output.stdout).unwrap().trim().to_owned() -} +// pub fn set_default_namespace(ns: &str, ctx: &str) { +// Command::new("kubectl") +// .arg("config") +// .arg(format!( +// "--kubeconfig={}/.kube/config", +// dirs::home_dir().unwrap().display() +// )) +// .arg("set-context") +// .arg(ctx) +// .arg(format!("--namespace={}", ns)) +// .stdout(Stdio::null()) +// .spawn() +// .unwrap() +// .wait() +// .unwrap(); +// } +// +// pub fn set_default_context(ctx: &str) { +// Command::new("kubectl") +// .arg("config") +// .arg(format!( +// "--kubeconfig={}/.kube/config", +// dirs::home_dir().unwrap().display() +// )) +// .arg("use-context") +// .arg(ctx) +// .stdout(Stdio::null()) +// .spawn() +// .unwrap() +// .wait() +// .unwrap(); +// } +// +// pub fn get_namespaces() -> Vec { +// let output = Command::new("kubectl") +// .args(["get", "namespace", "-o=custom-columns=Name:.metadata.name"]) +// .output() +// .unwrap(); +// +// let string = String::from_utf8(output.stdout).unwrap(); +// string.lines().skip(1).map(ToOwned::to_owned).collect() +// } +// +// pub fn get_current_context() -> String { +// let output = Command::new("kubectl") +// .args(["config", "current-context"]) +// .stdin(Stdio::piped()) +// .stdout(Stdio::piped()) +// .spawn() +// .unwrap() +// .wait_with_output() +// .unwrap(); +// +// String::from_utf8(output.stdout).unwrap().trim().to_owned() +// } /// Prompts the user to select an item from a list. /// Returns the selected item or `None` if no item was selected @@ -81,16 +82,18 @@ pub fn selectable_list(input: Vec) -> Option { .map(|selected_items| selected_items[0].output().to_string()) } -pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &KubeConfig) { - let choice = config.contexts.iter().find(|x| x.name == ctx); - config::write(choice.unwrap(), Some(selection), temp_dir) -} +// pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &KubeConfig) { +// let choice = config.contexts.iter().find(|x| x.name == ctx); +// config::write(choice.unwrap(), Some(selection), temp_dir) +// } -pub fn set_context(ctx: &str, temp_dir: &str, config: &KubeConfig) -> Result<(), SetContextError> { +pub fn set_context(ctx: &str, temp_dir: &str, config: &Kubeconfig) -> Result<(), SetContextError> { if let Some(choice) = config.contexts.iter().find(|x| x.name == ctx) { config::write(choice, None, temp_dir); Ok(()) } else { - Err(SetContextError::KubeContextNotFound{ctx: ctx.to_owned()}) + Err(SetContextError::KubeContextNotFound { + ctx: ctx.to_owned(), + }) } } diff --git a/src/config.rs b/src/config.rs index 6285b40..0580011 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,10 +1,47 @@ -use crate::model::{KubeConfig, Context, Contexts}; +use kube::config::NamedContext; + +use crate::model::KubeConfig; use crate::{KUBECONFIG, KUBESESSCONFIG}; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; use std::path::Path; -fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> KubeConfig { +use dirs; +use kube::config::Kubeconfig; + +pub fn get() -> Kubeconfig { + let mut merged_config = Kubeconfig::default(); + + let kube_dir = dirs::home_dir() + .map(|home| home.join(".kube")) + .expect("Failed to find home directory"); + + if let Ok(entries) = fs::read_dir(&kube_dir) { + for entry in entries { + if let Ok(entry) = entry { + let path = entry.path(); + + if path.is_file() { + match Kubeconfig::read_from(&path) { + Ok(kubeconfig) => { + println!("Loaded Kubeconfig from: {:?}", path); + merged_config.contexts.extend(kubeconfig.contexts); + merged_config.clusters.extend(kubeconfig.clusters); + // base.auth_infos.extend(additional.auth_infos); + } + Err(err) => { + println!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); + } + } + } + } + } + } + + merged_config +} + +fn build(ctx: &NamedContext, ns: Option<&str>, strbuf: &str) -> KubeConfig { let mut config: KubeConfig = serde_yaml::from_str(strbuf).unwrap(); config.api_version = "v1".to_string(); config.kind = "Config".to_string(); @@ -15,22 +52,22 @@ fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> KubeConfig { None => { if !config.contexts.is_empty() && !config.contexts[0].context.namespace.is_empty() { config.contexts[0].context.namespace.to_string() - } else if !ctx.context.namespace.is_empty() { - ctx.context.namespace.to_string() + // } else if !ctx.context.namespace.is_empty() { + // ctx.context.namespace.to_string() } else { "default".to_string() } } }; - config.contexts = vec![Contexts { - context: Context { - namespace: ns, - cluster: ctx.context.cluster.to_string(), - user: ctx.context.user.to_string(), - }, - name: ctx.name.to_string(), - }]; + // config.contexts = vec![NamedContext { + // context: NamedContext { + // namespace: ns, + // cluster: ctx.context.cluster.to_string(), + // user: ctx.context.user.to_string(), + // }, + // name: ctx.name.to_string(), + // }]; config } @@ -46,7 +83,7 @@ fn get_file(path: &String) -> File { f } -fn get_path(ctx: &Contexts, dest: &str) -> String { +fn get_path(ctx: &NamedContext, dest: &str) -> String { let path = Path::new(ctx.name.as_str()); let parent = path.parent().unwrap(); let dirname = str::replace(&parent.display().to_string(), ":", "_"); @@ -59,7 +96,7 @@ fn get_path(ctx: &Contexts, dest: &str) -> String { path.display().to_string() } -pub fn write(ctx: &Contexts, namespace: Option<&str>, dest: &str) { +pub fn write(ctx: &NamedContext, namespace: Option<&str>, dest: &str) { let path = get_path(ctx, dest); let strbuf = match fs::read_to_string(&path) { @@ -74,35 +111,35 @@ pub fn write(ctx: &Contexts, namespace: Option<&str>, dest: &str) { serde_yaml::to_writer(writer, &config).unwrap(); } -pub fn get() -> KubeConfig { - let mut configs = KubeConfig::default(); - - for s in KUBECONFIG.rsplit(':') { - if s.contains("/kubesess/cache") { - continue; - } - let config: KubeConfig = get_config(s); - - configs.current_context = config.current_context; - configs.api_version = config.api_version; - configs.kind = config.kind; - configs.contexts.extend(config.contexts); - } - - let dir = format!("{}/.kube", dirs::home_dir().unwrap().display()); - for entry in fs::read_dir(dir).unwrap() { - let path = entry.unwrap().path(); - if let Some(extension) = path.extension() { - if extension == "yaml" { - let config: KubeConfig = get_config(path.to_str().unwrap()); - - configs.contexts.extend(config.contexts); - } - } - } - - configs -} +// pub fn get() -> KubeConfig { +// let mut configs = KubeConfig::default(); +// +// for s in KUBECONFIG.rsplit(':') { +// if s.contains("/kubesess/cache") { +// continue; +// } +// let config: KubeConfig = get_config(s); +// +// configs.current_context = config.current_context; +// configs.api_version = config.api_version; +// configs.kind = config.kind; +// configs.contexts.extend(config.contexts); +// } +// +// let dir = format!("{}/.kube", dirs::home_dir().unwrap().display()); +// for entry in fs::read_dir(dir).unwrap() { +// let path = entry.unwrap().path(); +// if let Some(extension) = path.extension() { +// if extension == "yaml" { +// let config: KubeConfig = get_config(path.to_str().unwrap()); +// +// configs.contexts.extend(config.contexts); +// } +// } +// } +// +// configs +// } fn get_config(path: &str) -> KubeConfig { let f = File::open(path).unwrap(); @@ -119,7 +156,7 @@ fn get_config(path: &str) -> KubeConfig { } pub fn get_current_session() -> KubeConfig { - let current= if KUBESESSCONFIG.is_empty() { + let current = if KUBESESSCONFIG.is_empty() { KUBECONFIG.split(':').next().unwrap() } else { KUBESESSCONFIG.as_str() diff --git a/src/main.rs b/src/main.rs index a516cc2..aeebbb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ mod commands; mod config; +mod error; mod model; mod modes; -mod error; use crate::error::Error; use clap::Parser; @@ -62,35 +62,36 @@ pub struct Cli { #[derive(clap::ValueEnum, Clone)] enum Mode { - Namespace, + // Namespace, Context, - DefaultContext, - DefaultNamespace, - CompletionContext, - CompletionNamespace, + // DefaultContext, + // DefaultNamespace, + // CompletionContext, + // CompletionNamespace, } impl Mode { - fn invoke(&self) -> Result <(), Error> { + fn invoke(&self) -> Result<(), Error> { let args = Cli::parse(); match self { - Mode::Namespace => modes::namespace(args), + // Mode::Namespace => modes::namespace(args), Mode::Context => modes::context(args), - Mode::DefaultContext => modes::default_context(args), - Mode::DefaultNamespace => modes::default_namespace(args), - Mode::CompletionContext => { - modes::completion_context(args); - Ok(()) - }, - Mode::CompletionNamespace => { - modes::completion_namespace(args); - Ok(()) - } + // Mode::DefaultContext => modes::default_context(args), + // Mode::DefaultNamespace => modes::default_namespace(args), + // Mode::CompletionContext => { + // modes::completion_context(args); + // Ok(()) + // } + // Mode::CompletionNamespace => { + // modes::completion_namespace(args); + // Ok(()) + // } } } } -fn main() -> Result<(), io::Error> { +#[tokio::main] +async fn main() -> Result<(), io::Error> { let args = Cli::parse(); if let Err(err) = Mode::invoke(&args.mode) { diff --git a/src/modes.rs b/src/modes.rs index eca8aaf..6473560 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -1,36 +1,41 @@ -use crate::{commands::{self}, config, error::Error, Cli, DEST, KUBECONFIG}; - -pub fn default_context(args: Cli) -> Result<(), Error> { - let config = config::get(); - - if args.current { - println!("{}", config.current_context); - return Ok(()); - } - - let ctx = match args.value { - None => { - let options : Vec = config.contexts.iter() - .map(|context| context.name.to_string()) - .collect(); - - commands::selectable_list(options) - .ok_or(Error::NoItemSelected{prompt: "context" })? - } - Some(x) => x.trim().to_string(), - }; - - commands::set_default_context(&ctx); - - let set_context_result = commands::set_context(&ctx, &DEST, &config) - .map_err(Error::SetContext); - - if set_context_result.is_ok() { - println!("{}", KUBECONFIG.as_str()); - } - - set_context_result -} +use crate::{ + commands::{self}, + config, + error::Error, + Cli, DEST, KUBECONFIG, +}; + +// pub fn default_context(args: Cli) -> Result<(), Error> { +// let config = config::get(); +// +// if args.current { +// println!("{}", config.current_context); +// return Ok(()); +// } +// +// let ctx = match args.value { +// None => { +// let options: Vec = config +// .contexts +// .iter() +// .map(|context| context.name.to_string()) +// .collect(); +// +// commands::selectable_list(options).ok_or(Error::NoItemSelected { prompt: "context" })? +// } +// Some(x) => x.trim().to_string(), +// }; +// +// commands::set_default_context(&ctx); +// +// let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); +// +// if set_context_result.is_ok() { +// println!("{}", KUBECONFIG.as_str()); +// } +// +// set_context_result +// } pub fn context(args: Cli) -> Result<(), Error> { if args.current { @@ -42,18 +47,18 @@ pub fn context(args: Cli) -> Result<(), Error> { let config = config::get(); let ctx = match args.value { None => { - let options : Vec = config.contexts.iter() + let options: Vec = config + .contexts + .iter() .map(|context| context.name.to_string()) .collect(); - commands::selectable_list(options) - .ok_or(Error::NoItemSelected{prompt: "context"})? + commands::selectable_list(options).ok_or(Error::NoItemSelected { prompt: "context" })? } Some(x) => x.trim().to_string(), }; - let set_context_result = commands::set_context(&ctx, &DEST, &config) - .map_err(Error::SetContext); + let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); if set_context_result.is_ok() { println!( @@ -67,107 +72,109 @@ pub fn context(args: Cli) -> Result<(), Error> { set_context_result } -pub fn namespace(args: Cli) -> Result<(), Error> { - let config = config::get_current_session(); - if args.current { - let ctx = config - .contexts - .iter() - .find(|x| x.name == config.current_context); - - match ctx { - Some(x) => { - if x.context.namespace.is_empty() { - println!("default"); - } else { - println!("{}", x.context.namespace); - } - } - None => println!("default"), - } - return Ok(()); - } - - let ns = match args.value { - None => { - let namespaces : Vec = commands::get_namespaces(); - commands::selectable_list(namespaces) - .ok_or(Error::NoItemSelected{prompt: "namespace"})? - } - Some(x) => x.trim().to_string(), - }; - - commands::set_namespace(&config.current_context, &ns, &DEST, &config); - - println!( - "{}/{}:{}", - &DEST.as_str(), - str::replace(&config.current_context, ":", "_"), - *KUBECONFIG - ); - Ok(()) -} - -pub fn default_namespace(args: Cli) -> Result<(), Error> { - let config = config::get(); - let ctx = commands::get_current_context(); - - if args.current { - let ctx = config - .contexts - .iter() - .find(|x| x.name == config.current_context); - - match ctx { - Some(x) => { - if x.context.namespace.is_empty() { - println!("default"); - } else { - println!("{}", x.context.namespace); - } - } - None => println!("default"), - } - - return Ok(()); - } - - let ns = match args.value { - None => { - let namespaces : Vec = commands::get_namespaces(); - commands::selectable_list(namespaces) - .ok_or(Error::NoItemSelected{prompt: "namespace"})? - } - Some(x) => x.trim().to_string(), - }; - - commands::set_default_namespace(&ns, &ctx); - commands::set_namespace(&ctx, &ns, &DEST, &config); - Ok(()) -} - -pub fn completion_context(args: Cli) { - let config = config::get(); - - let mut options = Vec::new(); - for context in &config.contexts { - if context - .name - .starts_with(&args.value.as_ref().unwrap().to_string()) - { - options.push(context.name.to_string()); - } - } - println!("{}", options.join(" ")); -} - -pub fn completion_namespace(args: Cli) { - let namespaces = commands::get_namespaces(); - let mut options = Vec::new(); - for ns in &namespaces { - if ns.starts_with(&args.value.as_ref().unwrap().to_string()) { - options.push(ns.to_string()); - } - } - println!("{}", options.join(" ")); -} +// pub fn namespace(args: Cli) -> Result<(), Error> { +// let config = config::get_current_session(); +// if args.current { +// let ctx = config +// .contexts +// .iter() +// .find(|x| x.name == config.current_context); +// +// match ctx { +// Some(x) => { +// if x.context.namespace.is_empty() { +// println!("default"); +// } else { +// println!("{}", x.context.namespace); +// } +// } +// None => println!("default"), +// } +// return Ok(()); +// } +// +// let ns = match args.value { +// None => { +// let namespaces: Vec = commands::get_namespaces(); +// commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { +// prompt: "namespace", +// })? +// } +// Some(x) => x.trim().to_string(), +// }; +// +// commands::set_namespace(&config.current_context, &ns, &DEST, &config); +// +// println!( +// "{}/{}:{}", +// &DEST.as_str(), +// str::replace(&config.current_context, ":", "_"), +// *KUBECONFIG +// ); +// Ok(()) +// } +// +// pub fn default_namespace(args: Cli) -> Result<(), Error> { +// let config = config::get(); +// let ctx = commands::get_current_context(); +// +// if args.current { +// let ctx = config +// .contexts +// .iter() +// .find(|x| x.name == config.current_context); +// +// match ctx { +// Some(x) => { +// if x.context.namespace.is_empty() { +// println!("default"); +// } else { +// println!("{}", x.context.namespace); +// } +// } +// None => println!("default"), +// } +// +// return Ok(()); +// } +// +// let ns = match args.value { +// None => { +// let namespaces: Vec = commands::get_namespaces(); +// commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { +// prompt: "namespace", +// })? +// } +// Some(x) => x.trim().to_string(), +// }; +// +// commands::set_default_namespace(&ns, &ctx); +// commands::set_namespace(&ctx, &ns, &DEST, &config); +// Ok(()) +// } +// +// pub fn completion_context(args: Cli) { +// let config = config::get(); +// +// let mut options = Vec::new(); +// for context in &config.contexts { +// if context +// .name +// .starts_with(&args.value.as_ref().unwrap().to_string()) +// { +// options.push(context.name.to_string()); +// } +// } +// println!("{}", options.join(" ")); +// } +// +// pub fn completion_namespace(args: Cli) { +// let namespaces = commands::get_namespaces(); +// let mut options = Vec::new(); +// for ns in &namespaces { +// if ns.starts_with(&args.value.as_ref().unwrap().to_string()) { +// options.push(ns.to_string()); +// } +// } +// println!("{}", options.join(" ")); +// } From b550b11e314025dbd3ebe0173ec55bcd1128143d Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 06:24:10 +0200 Subject: [PATCH 02/28] working file --- src/commands.rs | 2 +- src/config.rs | 140 +++++++++++++++++++++--------------------------- 2 files changed, 63 insertions(+), 79 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index c76ca4c..0e989c4 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -89,7 +89,7 @@ pub fn selectable_list(input: Vec) -> Option { pub fn set_context(ctx: &str, temp_dir: &str, config: &Kubeconfig) -> Result<(), SetContextError> { if let Some(choice) = config.contexts.iter().find(|x| x.name == ctx) { - config::write(choice, None, temp_dir); + config::write(choice, None, temp_dir, config); Ok(()) } else { Err(SetContextError::KubeContextNotFound { diff --git a/src/config.rs b/src/config.rs index 0580011..95db66f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,7 @@ pub fn get() -> Kubeconfig { println!("Loaded Kubeconfig from: {:?}", path); merged_config.contexts.extend(kubeconfig.contexts); merged_config.clusters.extend(kubeconfig.clusters); - // base.auth_infos.extend(additional.auth_infos); + merged_config.auth_infos.extend(kubeconfig.auth_infos); } Err(err) => { println!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); @@ -41,35 +41,59 @@ pub fn get() -> Kubeconfig { merged_config } -fn build(ctx: &NamedContext, ns: Option<&str>, strbuf: &str) -> KubeConfig { - let mut config: KubeConfig = serde_yaml::from_str(strbuf).unwrap(); - config.api_version = "v1".to_string(); - config.kind = "Config".to_string(); - config.current_context = ctx.name.to_string(); +pub fn build( + selected_context: &NamedContext, + namespace: Option<&str>, + kubeconfig: &Kubeconfig, +) -> Kubeconfig { + let context_name = &selected_context.name; - let ns = match ns { - Some(namespace) => namespace.to_string(), + // Handle the case where the context is None + let context = match &selected_context.context { + Some(ctx) => ctx, None => { - if !config.contexts.is_empty() && !config.contexts[0].context.namespace.is_empty() { - config.contexts[0].context.namespace.to_string() - // } else if !ctx.context.namespace.is_empty() { - // ctx.context.namespace.to_string() - } else { - "default".to_string() - } + eprintln!("Error: The selected context has no associated context data."); + return Kubeconfig::default(); } }; - // config.contexts = vec![NamedContext { - // context: NamedContext { - // namespace: ns, - // cluster: ctx.context.cluster.to_string(), - // user: ctx.context.user.to_string(), - // }, - // name: ctx.name.to_string(), - // }]; + // Find the corresponding cluster based on the context's cluster reference + let cluster_name = &context.cluster; + let selected_cluster = kubeconfig + .clusters + .iter() + .find(|cluster| &cluster.name == cluster_name) + .expect("Cluster for the selected context not found"); + + // Find the corresponding auth_info (user) based on the context's user reference + let user_name = &context.user; + let selected_auth_info = kubeconfig + .auth_infos + .iter() + .find(|auth_info| &auth_info.name == user_name) + .expect("Auth info for the selected context not found"); + + // Determine the namespace: use the provided one or fallback to the context's namespace + let final_namespace = match namespace { + Some(ns) => ns.to_string(), + None => context + .namespace + .clone() + .unwrap_or_else(|| "default".to_string()), + }; - config + let mut minimal_context = selected_context.clone(); + if let Some(ref mut ctx) = minimal_context.context { + ctx.namespace = Some(final_namespace); + } + + Kubeconfig { + current_context: Some(context_name.clone()), + contexts: vec![minimal_context], + clusters: vec![selected_cluster.clone()], + auth_infos: vec![selected_auth_info.clone()], + ..Kubeconfig::default() + } } fn get_file(path: &String) -> File { @@ -83,8 +107,10 @@ fn get_file(path: &String) -> File { f } -fn get_path(ctx: &NamedContext, dest: &str) -> String { - let path = Path::new(ctx.name.as_str()); +fn get_path(ctx: &str, namespace: &str, dest: &str) -> String { + let filename = ctx.to_owned() + "_" + &namespace.to_owned(); + + let path = Path::new(&filename); let parent = path.parent().unwrap(); let dirname = str::replace(&parent.display().to_string(), ":", "_"); @@ -96,63 +122,21 @@ fn get_path(ctx: &NamedContext, dest: &str) -> String { path.display().to_string() } -pub fn write(ctx: &NamedContext, namespace: Option<&str>, dest: &str) { - let path = get_path(ctx, dest); +pub fn write(ctx: &NamedContext, namespace: Option<&str>, dest: &str, config: &Kubeconfig) { + let minimal_config = build(ctx, namespace, config); + let selected_context = minimal_config.current_context.clone().unwrap_or_default(); + let selected_ns = minimal_config + .contexts + .first() + .and_then(|ctx| ctx.context.as_ref().and_then(|c| c.namespace.clone())) + .unwrap_or_else(|| "default".to_string()); - let strbuf = match fs::read_to_string(&path) { - Ok(file) => file, - Err(_error) => "".to_string(), - }; + let path = get_path(&selected_context, &selected_ns, dest); let options = get_file(&path); let writer = BufWriter::new(&options); - let config = build(ctx, namespace, &strbuf); - - serde_yaml::to_writer(writer, &config).unwrap(); -} -// pub fn get() -> KubeConfig { -// let mut configs = KubeConfig::default(); -// -// for s in KUBECONFIG.rsplit(':') { -// if s.contains("/kubesess/cache") { -// continue; -// } -// let config: KubeConfig = get_config(s); -// -// configs.current_context = config.current_context; -// configs.api_version = config.api_version; -// configs.kind = config.kind; -// configs.contexts.extend(config.contexts); -// } -// -// let dir = format!("{}/.kube", dirs::home_dir().unwrap().display()); -// for entry in fs::read_dir(dir).unwrap() { -// let path = entry.unwrap().path(); -// if let Some(extension) = path.extension() { -// if extension == "yaml" { -// let config: KubeConfig = get_config(path.to_str().unwrap()); -// -// configs.contexts.extend(config.contexts); -// } -// } -// } -// -// configs -// } - -fn get_config(path: &str) -> KubeConfig { - let f = File::open(path).unwrap(); - - let mut reader = BufReader::new(f); - let mut tmp = String::new(); - reader - .read_to_string(&mut tmp) - .expect("Unable to read file"); - - let config: KubeConfig = serde_yaml::from_str(tmp.trim()).unwrap(); - - config + serde_yaml::to_writer(writer, &minimal_config).unwrap(); } pub fn get_current_session() -> KubeConfig { From 10b7e32fc33b2b7944cd66fa70ebfd10e30e5f11 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 06:44:27 +0200 Subject: [PATCH 03/28] fix filepath name --- src/commands.rs | 10 +++++++--- src/config.rs | 15 ++++++++++----- src/modes.rs | 14 +++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 0e989c4..79bcfa7 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -87,10 +87,14 @@ pub fn selectable_list(input: Vec) -> Option { // config::write(choice.unwrap(), Some(selection), temp_dir) // } -pub fn set_context(ctx: &str, temp_dir: &str, config: &Kubeconfig) -> Result<(), SetContextError> { +pub fn set_context( + ctx: &str, + temp_dir: &str, + config: &Kubeconfig, +) -> Result { if let Some(choice) = config.contexts.iter().find(|x| x.name == ctx) { - config::write(choice, None, temp_dir, config); - Ok(()) + let filename = config::write(choice, None, temp_dir, config); + Ok(filename) } else { Err(SetContextError::KubeContextNotFound { ctx: ctx.to_owned(), diff --git a/src/config.rs b/src/config.rs index 95db66f..edb6548 100644 --- a/src/config.rs +++ b/src/config.rs @@ -107,9 +107,7 @@ fn get_file(path: &String) -> File { f } -fn get_path(ctx: &str, namespace: &str, dest: &str) -> String { - let filename = ctx.to_owned() + "_" + &namespace.to_owned(); - +fn get_path(filename: &str, dest: &str) -> String { let path = Path::new(&filename); let parent = path.parent().unwrap(); let dirname = str::replace(&parent.display().to_string(), ":", "_"); @@ -122,7 +120,12 @@ fn get_path(ctx: &str, namespace: &str, dest: &str) -> String { path.display().to_string() } -pub fn write(ctx: &NamedContext, namespace: Option<&str>, dest: &str, config: &Kubeconfig) { +pub fn write( + ctx: &NamedContext, + namespace: Option<&str>, + dest: &str, + config: &Kubeconfig, +) -> String { let minimal_config = build(ctx, namespace, config); let selected_context = minimal_config.current_context.clone().unwrap_or_default(); let selected_ns = minimal_config @@ -131,12 +134,14 @@ pub fn write(ctx: &NamedContext, namespace: Option<&str>, dest: &str, config: &K .and_then(|ctx| ctx.context.as_ref().and_then(|c| c.namespace.clone())) .unwrap_or_else(|| "default".to_string()); - let path = get_path(&selected_context, &selected_ns, dest); + let filename = selected_context.to_owned() + "_" + &selected_ns.to_owned(); + let path = get_path(&filename, dest); let options = get_file(&path); let writer = BufWriter::new(&options); serde_yaml::to_writer(writer, &minimal_config).unwrap(); + return filename; } pub fn get_current_session() -> KubeConfig { diff --git a/src/modes.rs b/src/modes.rs index 6473560..e1b42c7 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -38,11 +38,11 @@ use crate::{ // } pub fn context(args: Cli) -> Result<(), Error> { - if args.current { - let config = config::get_current_session(); - println!("{}", config.current_context); - return Ok(()); - } + // if args.current { + // let config = config::get_current_session(); + // println!("{}", config.current_context); + // return Ok(config); + // } let config = config::get(); let ctx = match args.value { @@ -64,12 +64,12 @@ pub fn context(args: Cli) -> Result<(), Error> { println!( "{}/{}:{}", &DEST.as_str(), - str::replace(&ctx, ":", "_"), + str::replace(&set_context_result.unwrap(), ":", "_"), *KUBECONFIG ); } - set_context_result + return Ok(()); } // pub fn namespace(args: Cli) -> Result<(), Error> { From b4e388cb365fe89588a7015b7ccfc2d2518b0568 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:15:19 +0200 Subject: [PATCH 04/28] current session fetch and namespace stuff --- src/commands.rs | 32 ++++++++------- src/config.rs | 2 +- src/main.rs | 4 +- src/modes.rs | 104 +++++++++++++++++++++++++++--------------------- 4 files changed, 78 insertions(+), 64 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 79bcfa7..33d178c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,5 +1,5 @@ use crate::config; -use crate::{error::SetContextError, model::KubeConfig}; +use crate::error::SetContextError; use std::{ io::Cursor, @@ -41,16 +41,16 @@ use skim::prelude::*; // .wait() // .unwrap(); // } -// -// pub fn get_namespaces() -> Vec { -// let output = Command::new("kubectl") -// .args(["get", "namespace", "-o=custom-columns=Name:.metadata.name"]) -// .output() -// .unwrap(); -// -// let string = String::from_utf8(output.stdout).unwrap(); -// string.lines().skip(1).map(ToOwned::to_owned).collect() -// } + +pub fn get_namespaces() -> Vec { + let output = Command::new("kubectl") + .args(["get", "namespace", "-o=custom-columns=Name:.metadata.name"]) + .output() + .unwrap(); + + let string = String::from_utf8(output.stdout).unwrap(); + string.lines().skip(1).map(ToOwned::to_owned).collect() +} // // pub fn get_current_context() -> String { // let output = Command::new("kubectl") @@ -82,10 +82,12 @@ pub fn selectable_list(input: Vec) -> Option { .map(|selected_items| selected_items[0].output().to_string()) } -// pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &KubeConfig) { -// let choice = config.contexts.iter().find(|x| x.name == ctx); -// config::write(choice.unwrap(), Some(selection), temp_dir) -// } +pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &Kubeconfig) -> String { + let choice = config.contexts.iter().find(|x| x.name == ctx); + let filename = config::write(choice.unwrap(), Some(selection), temp_dir, config); + + return filename; +} pub fn set_context( ctx: &str, diff --git a/src/config.rs b/src/config.rs index edb6548..cf580ed 100644 --- a/src/config.rs +++ b/src/config.rs @@ -144,7 +144,7 @@ pub fn write( return filename; } -pub fn get_current_session() -> KubeConfig { +pub fn get_current_session() -> Kubeconfig { let current = if KUBESESSCONFIG.is_empty() { KUBECONFIG.split(':').next().unwrap() } else { diff --git a/src/main.rs b/src/main.rs index aeebbb8..4e41bf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ pub struct Cli { #[derive(clap::ValueEnum, Clone)] enum Mode { - // Namespace, + Namespace, Context, // DefaultContext, // DefaultNamespace, @@ -74,7 +74,7 @@ impl Mode { fn invoke(&self) -> Result<(), Error> { let args = Cli::parse(); match self { - // Mode::Namespace => modes::namespace(args), + Mode::Namespace => modes::namespace(args), Mode::Context => modes::context(args), // Mode::DefaultContext => modes::default_context(args), // Mode::DefaultNamespace => modes::default_namespace(args), diff --git a/src/modes.rs b/src/modes.rs index e1b42c7..8c37750 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -38,11 +38,17 @@ use crate::{ // } pub fn context(args: Cli) -> Result<(), Error> { - // if args.current { - // let config = config::get_current_session(); - // println!("{}", config.current_context); - // return Ok(config); - // } + if args.current { + let config = config::get_current_session(); + println!( + "{}", + config + .current_context + .as_deref() + .unwrap_or("No current context set") + ); + return Ok(()); + } let config = config::get(); let ctx = match args.value { @@ -72,47 +78,53 @@ pub fn context(args: Cli) -> Result<(), Error> { return Ok(()); } -// pub fn namespace(args: Cli) -> Result<(), Error> { -// let config = config::get_current_session(); -// if args.current { -// let ctx = config -// .contexts -// .iter() -// .find(|x| x.name == config.current_context); -// -// match ctx { -// Some(x) => { -// if x.context.namespace.is_empty() { -// println!("default"); -// } else { -// println!("{}", x.context.namespace); -// } -// } -// None => println!("default"), -// } -// return Ok(()); -// } -// -// let ns = match args.value { -// None => { -// let namespaces: Vec = commands::get_namespaces(); -// commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { -// prompt: "namespace", -// })? -// } -// Some(x) => x.trim().to_string(), -// }; -// -// commands::set_namespace(&config.current_context, &ns, &DEST, &config); -// -// println!( -// "{}/{}:{}", -// &DEST.as_str(), -// str::replace(&config.current_context, ":", "_"), -// *KUBECONFIG -// ); -// Ok(()) -// } +pub fn namespace(args: Cli) -> Result<(), Error> { + let config = config::get_current_session(); + let current_ctx = &config + .current_context + .as_deref() + .unwrap_or("No current context set"); + if args.current { + if let Some(ctx) = config.contexts.iter().find(|x| { + x.name + == config + .current_context + .as_deref() + .unwrap_or("No current context set") + }) { + let namespace = ctx + .context + .as_ref() + .and_then(|c| c.namespace.as_deref()) + .unwrap_or("default"); + + println!("{}", namespace); + } else { + println!("default"); + } + return Ok(()); + } + + let ns = match args.value { + None => { + let namespaces: Vec = commands::get_namespaces(); + commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { + prompt: "namespace", + })? + } + Some(x) => x.trim().to_string(), + }; + + let result = commands::set_namespace(current_ctx, &ns, &DEST, &config); + + println!( + "{}/{}:{}", + &DEST.as_str(), + str::replace(&result, ":", "_"), + *KUBECONFIG + ); + Ok(()) +} // // pub fn default_namespace(args: Cli) -> Result<(), Error> { // let config = config::get(); From b7b89e5ef9a78a4de36737ac0383fea735d3223f Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:27:01 +0200 Subject: [PATCH 05/28] add completion support --- src/commands.rs | 2 +- src/main.rs | 20 +++++++++--------- src/modes.rs | 56 ++++++++++++++++++++++++++----------------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 33d178c..7b5acb9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -51,7 +51,7 @@ pub fn get_namespaces() -> Vec { let string = String::from_utf8(output.stdout).unwrap(); string.lines().skip(1).map(ToOwned::to_owned).collect() } -// + // pub fn get_current_context() -> String { // let output = Command::new("kubectl") // .args(["config", "current-context"]) diff --git a/src/main.rs b/src/main.rs index 4e41bf6..06d29af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,8 +66,8 @@ enum Mode { Context, // DefaultContext, // DefaultNamespace, - // CompletionContext, - // CompletionNamespace, + CompletionContext, + CompletionNamespace, } impl Mode { @@ -78,14 +78,14 @@ impl Mode { Mode::Context => modes::context(args), // Mode::DefaultContext => modes::default_context(args), // Mode::DefaultNamespace => modes::default_namespace(args), - // Mode::CompletionContext => { - // modes::completion_context(args); - // Ok(()) - // } - // Mode::CompletionNamespace => { - // modes::completion_namespace(args); - // Ok(()) - // } + Mode::CompletionContext => { + modes::completion_context(args); + Ok(()) + } + Mode::CompletionNamespace => { + modes::completion_namespace(args); + Ok(()) + } } } } diff --git a/src/modes.rs b/src/modes.rs index 8c37750..62ef981 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -164,29 +164,33 @@ pub fn namespace(args: Cli) -> Result<(), Error> { // commands::set_namespace(&ctx, &ns, &DEST, &config); // Ok(()) // } -// -// pub fn completion_context(args: Cli) { -// let config = config::get(); -// -// let mut options = Vec::new(); -// for context in &config.contexts { -// if context -// .name -// .starts_with(&args.value.as_ref().unwrap().to_string()) -// { -// options.push(context.name.to_string()); -// } -// } -// println!("{}", options.join(" ")); -// } -// -// pub fn completion_namespace(args: Cli) { -// let namespaces = commands::get_namespaces(); -// let mut options = Vec::new(); -// for ns in &namespaces { -// if ns.starts_with(&args.value.as_ref().unwrap().to_string()) { -// options.push(ns.to_string()); -// } -// } -// println!("{}", options.join(" ")); -// } + +pub fn completion_context(args: Cli) { + let config = config::get(); + + let search_value = args.value.as_deref().unwrap_or(""); + + let options: Vec = config + .contexts + .iter() + .filter(|context| context.name.starts_with(search_value)) + .map(|context| context.name.clone()) + .collect(); + + println!("{}", options.join(" ")); +} + +pub fn completion_namespace(args: Cli) { + let namespaces = commands::get_namespaces(); + let mut options = Vec::new(); + + let search_value = args.value.as_deref().unwrap_or(""); + + for ns in &namespaces { + if ns.starts_with(search_value) { + options.push(ns.to_string()); + } + } + + println!("{}", options.join(" ")); +} From e35021f0ddd0707de45de92ed6fb2919483b16e6 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:29:31 +0200 Subject: [PATCH 06/28] deleted our own model --- src/commands.rs | 5 +---- src/config.rs | 1 - src/main.rs | 1 - src/model.rs | 31 ------------------------------- 4 files changed, 1 insertion(+), 37 deletions(-) delete mode 100644 src/model.rs diff --git a/src/commands.rs b/src/commands.rs index 7b5acb9..d9b5a17 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,10 +1,7 @@ use crate::config; use crate::error::SetContextError; -use std::{ - io::Cursor, - process::{Command, Stdio}, -}; +use std::{io::Cursor, process::Command}; extern crate skim; use kube::config::Kubeconfig; use skim::prelude::*; diff --git a/src/config.rs b/src/config.rs index cf580ed..77a2f13 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,5 @@ use kube::config::NamedContext; -use crate::model::KubeConfig; use crate::{KUBECONFIG, KUBESESSCONFIG}; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; diff --git a/src/main.rs b/src/main.rs index 06d29af..ffeb3c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ mod commands; mod config; mod error; -mod model; mod modes; use crate::error::Error; diff --git a/src/model.rs b/src/model.rs deleted file mode 100644 index ed75048..0000000 --- a/src/model.rs +++ /dev/null @@ -1,31 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Default, PartialEq, Debug, Serialize, Deserialize)] -pub struct Contexts { - #[serde(default)] - pub context: Context, - #[serde(default)] - pub name: String, -} - -#[derive(Default, PartialEq, Debug, Serialize, Deserialize)] -pub struct Context { - #[serde(skip_serializing_if = "String::is_empty", default)] - pub namespace: String, - pub cluster: String, - pub user: String, -} - -#[derive(Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct KubeConfig { - #[serde(skip_serializing_if = "String::is_empty", default)] - pub kind: String, - #[serde(rename = "apiVersion")] - #[serde(skip_serializing_if = "String::is_empty", default)] - pub api_version: String, - #[serde(skip_serializing_if = "String::is_empty", default)] - #[serde(rename = "current-context")] - pub current_context: String, - #[serde(default)] - pub contexts: Vec, -} From 7434e9e7d477cd9d95e06e7196a76686d0c5ccfd Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:36:32 +0200 Subject: [PATCH 07/28] default namespace updated --- src/commands.rs | 61 ++++++++++++++++++++------------------ src/main.rs | 4 +-- src/modes.rs | 79 +++++++++++++++++++++++++------------------------ 3 files changed, 74 insertions(+), 70 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d9b5a17..bbc2375 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,27 +1,30 @@ use crate::config; use crate::error::SetContextError; -use std::{io::Cursor, process::Command}; +use std::{ + io::Cursor, + process::{Command, Stdio}, +}; extern crate skim; use kube::config::Kubeconfig; use skim::prelude::*; -// pub fn set_default_namespace(ns: &str, ctx: &str) { -// Command::new("kubectl") -// .arg("config") -// .arg(format!( -// "--kubeconfig={}/.kube/config", -// dirs::home_dir().unwrap().display() -// )) -// .arg("set-context") -// .arg(ctx) -// .arg(format!("--namespace={}", ns)) -// .stdout(Stdio::null()) -// .spawn() -// .unwrap() -// .wait() -// .unwrap(); -// } +pub fn set_default_namespace(ns: &str, ctx: &str) { + Command::new("kubectl") + .arg("config") + .arg(format!( + "--kubeconfig={}/.kube/config", + dirs::home_dir().unwrap().display() + )) + .arg("set-context") + .arg(ctx) + .arg(format!("--namespace={}", ns)) + .stdout(Stdio::null()) + .spawn() + .unwrap() + .wait() + .unwrap(); +} // // pub fn set_default_context(ctx: &str) { // Command::new("kubectl") @@ -49,18 +52,18 @@ pub fn get_namespaces() -> Vec { string.lines().skip(1).map(ToOwned::to_owned).collect() } -// pub fn get_current_context() -> String { -// let output = Command::new("kubectl") -// .args(["config", "current-context"]) -// .stdin(Stdio::piped()) -// .stdout(Stdio::piped()) -// .spawn() -// .unwrap() -// .wait_with_output() -// .unwrap(); -// -// String::from_utf8(output.stdout).unwrap().trim().to_owned() -// } +pub fn get_current_context() -> String { + let output = Command::new("kubectl") + .args(["config", "current-context"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + + String::from_utf8(output.stdout).unwrap().trim().to_owned() +} /// Prompts the user to select an item from a list. /// Returns the selected item or `None` if no item was selected diff --git a/src/main.rs b/src/main.rs index ffeb3c8..6bbd4cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ enum Mode { Namespace, Context, // DefaultContext, - // DefaultNamespace, + DefaultNamespace, CompletionContext, CompletionNamespace, } @@ -76,7 +76,7 @@ impl Mode { Mode::Namespace => modes::namespace(args), Mode::Context => modes::context(args), // Mode::DefaultContext => modes::default_context(args), - // Mode::DefaultNamespace => modes::default_namespace(args), + Mode::DefaultNamespace => modes::default_namespace(args), Mode::CompletionContext => { modes::completion_context(args); Ok(()) diff --git a/src/modes.rs b/src/modes.rs index 62ef981..982b7fc 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -125,45 +125,46 @@ pub fn namespace(args: Cli) -> Result<(), Error> { ); Ok(()) } -// -// pub fn default_namespace(args: Cli) -> Result<(), Error> { -// let config = config::get(); -// let ctx = commands::get_current_context(); -// -// if args.current { -// let ctx = config -// .contexts -// .iter() -// .find(|x| x.name == config.current_context); -// -// match ctx { -// Some(x) => { -// if x.context.namespace.is_empty() { -// println!("default"); -// } else { -// println!("{}", x.context.namespace); -// } -// } -// None => println!("default"), -// } -// -// return Ok(()); -// } -// -// let ns = match args.value { -// None => { -// let namespaces: Vec = commands::get_namespaces(); -// commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { -// prompt: "namespace", -// })? -// } -// Some(x) => x.trim().to_string(), -// }; -// -// commands::set_default_namespace(&ns, &ctx); -// commands::set_namespace(&ctx, &ns, &DEST, &config); -// Ok(()) -// } + +pub fn default_namespace(args: Cli) -> Result<(), Error> { + let config = config::get(); + let ctx = commands::get_current_context(); + + if args.current { + if let Some(ctx) = config.contexts.iter().find(|x| { + x.name + == config + .current_context + .as_deref() + .unwrap_or("No current context set") + }) { + let namespace = ctx + .context + .as_ref() + .and_then(|c| c.namespace.as_deref()) + .unwrap_or("default"); + + println!("{}", namespace); + } else { + println!("default"); + } + return Ok(()); + } + + let ns = match args.value { + None => { + let namespaces: Vec = commands::get_namespaces(); + commands::selectable_list(namespaces).ok_or(Error::NoItemSelected { + prompt: "namespace", + })? + } + Some(x) => x.trim().to_string(), + }; + + commands::set_default_namespace(&ns, &ctx); + commands::set_namespace(&ctx, &ns, &DEST, &config); + Ok(()) +} pub fn completion_context(args: Cli) { let config = config::get(); From f3f2ffe8d0c3962dc78e85d7c88c837bb2e2d359 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:42:21 +0200 Subject: [PATCH 08/28] default context --- src/commands.rs | 32 +++++++++++------------ src/main.rs | 4 +-- src/modes.rs | 68 +++++++++++++++++++++++++++---------------------- 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index bbc2375..5abf4b7 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -25,22 +25,22 @@ pub fn set_default_namespace(ns: &str, ctx: &str) { .wait() .unwrap(); } -// -// pub fn set_default_context(ctx: &str) { -// Command::new("kubectl") -// .arg("config") -// .arg(format!( -// "--kubeconfig={}/.kube/config", -// dirs::home_dir().unwrap().display() -// )) -// .arg("use-context") -// .arg(ctx) -// .stdout(Stdio::null()) -// .spawn() -// .unwrap() -// .wait() -// .unwrap(); -// } + +pub fn set_default_context(ctx: &str) { + Command::new("kubectl") + .arg("config") + .arg(format!( + "--kubeconfig={}/.kube/config", + dirs::home_dir().unwrap().display() + )) + .arg("use-context") + .arg(ctx) + .stdout(Stdio::null()) + .spawn() + .unwrap() + .wait() + .unwrap(); +} pub fn get_namespaces() -> Vec { let output = Command::new("kubectl") diff --git a/src/main.rs b/src/main.rs index 6bbd4cf..671ea92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ pub struct Cli { enum Mode { Namespace, Context, - // DefaultContext, + DefaultContext, DefaultNamespace, CompletionContext, CompletionNamespace, @@ -75,7 +75,7 @@ impl Mode { match self { Mode::Namespace => modes::namespace(args), Mode::Context => modes::context(args), - // Mode::DefaultContext => modes::default_context(args), + Mode::DefaultContext => modes::default_context(args), Mode::DefaultNamespace => modes::default_namespace(args), Mode::CompletionContext => { modes::completion_context(args); diff --git a/src/modes.rs b/src/modes.rs index 982b7fc..aed085a 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -5,37 +5,43 @@ use crate::{ Cli, DEST, KUBECONFIG, }; -// pub fn default_context(args: Cli) -> Result<(), Error> { -// let config = config::get(); -// -// if args.current { -// println!("{}", config.current_context); -// return Ok(()); -// } -// -// let ctx = match args.value { -// None => { -// let options: Vec = config -// .contexts -// .iter() -// .map(|context| context.name.to_string()) -// .collect(); -// -// commands::selectable_list(options).ok_or(Error::NoItemSelected { prompt: "context" })? -// } -// Some(x) => x.trim().to_string(), -// }; -// -// commands::set_default_context(&ctx); -// -// let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); -// -// if set_context_result.is_ok() { -// println!("{}", KUBECONFIG.as_str()); -// } -// -// set_context_result -// } +pub fn default_context(args: Cli) -> Result<(), Error> { + let config = config::get(); + + if args.current { + println!( + "{}", + config + .current_context + .as_deref() + .unwrap_or("No current context set") + ); + return Ok(()); + } + + let ctx = match args.value { + None => { + let options: Vec = config + .contexts + .iter() + .map(|context| context.name.to_string()) + .collect(); + + commands::selectable_list(options).ok_or(Error::NoItemSelected { prompt: "context" })? + } + Some(x) => x.trim().to_string(), + }; + + commands::set_default_context(&ctx); + + let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); + + if set_context_result.is_ok() { + println!("{}", KUBECONFIG.as_str()); + } + + Ok(()) +} pub fn context(args: Cli) -> Result<(), Error> { if args.current { From 7ad23f6722d89b9d2877abb7a226432410422649 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 07:56:18 +0200 Subject: [PATCH 09/28] removed error --- src/error.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index 53c430d..d55e69e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,15 +5,17 @@ pub enum Error { #[error("failed to set context: {0}")] SetContext(#[source] SetContextError), #[error("no item selected when prompted to select {prompt}")] - NoItemSelected { - prompt: &'static str - }, + NoItemSelected { prompt: &'static str }, } +// #[derive(Error, Debug)] +// pub enum SetNamespaceError { +// #[error("no namespace exists with the name {ns}")] +// KubeNamespaceNotFound { ns: String }, +// } + #[derive(Error, Debug)] pub enum SetContextError { #[error("no context exists with the name {ctx}")] - KubeContextNotFound { - ctx: String - }, + KubeContextNotFound { ctx: String }, } From 478abc449f1e401f4e53f0bb6a29faf251e12351 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 14:18:03 +0200 Subject: [PATCH 10/28] removed return statements --- src/commands.rs | 2 +- src/config.rs | 2 +- src/modes.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 5abf4b7..216ba39 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -86,7 +86,7 @@ pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &Kubeco let choice = config.contexts.iter().find(|x| x.name == ctx); let filename = config::write(choice.unwrap(), Some(selection), temp_dir, config); - return filename; + filename } pub fn set_context( diff --git a/src/config.rs b/src/config.rs index 77a2f13..659621e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -140,7 +140,7 @@ pub fn write( let writer = BufWriter::new(&options); serde_yaml::to_writer(writer, &minimal_config).unwrap(); - return filename; + filename } pub fn get_current_session() -> Kubeconfig { diff --git a/src/modes.rs b/src/modes.rs index aed085a..c4933cf 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -81,7 +81,7 @@ pub fn context(args: Cli) -> Result<(), Error> { ); } - return Ok(()); + Ok(()) } pub fn namespace(args: Cli) -> Result<(), Error> { From ccd17300dada739aff54734c1e95882918f0882a Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 14:20:45 +0200 Subject: [PATCH 11/28] removed unused import --- src/config.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 659621e..8e95945 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,8 @@ -use kube::config::NamedContext; - use crate::{KUBECONFIG, KUBESESSCONFIG}; +use kube::config::NamedContext; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; use std::path::Path; - -use dirs; use kube::config::Kubeconfig; pub fn get() -> Kubeconfig { From 1ceefbaa742935d748abfcd35ae07a8ce713cc8f Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 14:22:33 +0200 Subject: [PATCH 12/28] no need to save a variable --- src/commands.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 216ba39..9341e7c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -84,9 +84,7 @@ pub fn selectable_list(input: Vec) -> Option { pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &Kubeconfig) -> String { let choice = config.contexts.iter().find(|x| x.name == ctx); - let filename = config::write(choice.unwrap(), Some(selection), temp_dir, config); - - filename + config::write(choice.unwrap(), Some(selection), temp_dir, config) } pub fn set_context( From dd4325afe4e3a59d17872aefde98709e4dc246f8 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 14:54:42 +0200 Subject: [PATCH 13/28] fix clippy complaint --- src/config.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8e95945..7e18db7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,9 +1,9 @@ use crate::{KUBECONFIG, KUBESESSCONFIG}; +use kube::config::Kubeconfig; use kube::config::NamedContext; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; use std::path::Path; -use kube::config::Kubeconfig; pub fn get() -> Kubeconfig { let mut merged_config = Kubeconfig::default(); @@ -13,21 +13,19 @@ pub fn get() -> Kubeconfig { .expect("Failed to find home directory"); if let Ok(entries) = fs::read_dir(&kube_dir) { - for entry in entries { - if let Ok(entry) = entry { - let path = entry.path(); - - if path.is_file() { - match Kubeconfig::read_from(&path) { - Ok(kubeconfig) => { - println!("Loaded Kubeconfig from: {:?}", path); - merged_config.contexts.extend(kubeconfig.contexts); - merged_config.clusters.extend(kubeconfig.clusters); - merged_config.auth_infos.extend(kubeconfig.auth_infos); - } - Err(err) => { - println!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); - } + for entry in entries.flatten() { + let path = entry.path(); + + if path.is_file() { + match Kubeconfig::read_from(&path) { + Ok(kubeconfig) => { + println!("Loaded Kubeconfig from: {:?}", path); + merged_config.contexts.extend(kubeconfig.contexts); + merged_config.clusters.extend(kubeconfig.clusters); + merged_config.auth_infos.extend(kubeconfig.auth_infos); + } + Err(err) => { + println!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); } } } From 8661765f5fd3d3920e09f369f639654ec463e279 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 15:18:26 +0200 Subject: [PATCH 14/28] removed error and use eprint --- src/config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7e18db7..7998fb3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,13 +19,12 @@ pub fn get() -> Kubeconfig { if path.is_file() { match Kubeconfig::read_from(&path) { Ok(kubeconfig) => { - println!("Loaded Kubeconfig from: {:?}", path); merged_config.contexts.extend(kubeconfig.contexts); merged_config.clusters.extend(kubeconfig.clusters); merged_config.auth_infos.extend(kubeconfig.auth_infos); } Err(err) => { - println!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); + eprintln!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); } } } From fa607dede80c8bd558d9d1aa8b929a4701336bc7 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sat, 19 Oct 2024 15:50:19 +0200 Subject: [PATCH 15/28] handle output of default namespace change --- scripts/fish/functions/knd.fish | 3 ++- scripts/sh/kubesess.sh | 2 +- src/modes.rs | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/fish/functions/knd.fish b/scripts/fish/functions/knd.fish index d1094ad..975f380 100644 --- a/scripts/fish/functions/knd.fish +++ b/scripts/fish/functions/knd.fish @@ -3,5 +3,6 @@ function knd --argument-names context --description "Switch global kubernetes na if test -n "$argv" set -a cmd -v $context end - command $cmd + set -l config (command $cmd) || return $status + set -gx KUBECONFIG $config end diff --git a/scripts/sh/kubesess.sh b/scripts/sh/kubesess.sh index 333f9dd..894d89f 100644 --- a/scripts/sh/kubesess.sh +++ b/scripts/sh/kubesess.sh @@ -19,5 +19,5 @@ kn() { } knd() { - kubesess ${1:+"-v "$1} default-namespace; + __kubesess_export ${1:+"-v "$1} default-namespace } diff --git a/src/modes.rs b/src/modes.rs index c4933cf..99b2f22 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -133,8 +133,11 @@ pub fn namespace(args: Cli) -> Result<(), Error> { } pub fn default_namespace(args: Cli) -> Result<(), Error> { - let config = config::get(); - let ctx = commands::get_current_context(); + let config = config::get_current_session(); + let ctx = &config + .current_context + .as_deref() + .unwrap_or("No current context set"); if args.current { if let Some(ctx) = config.contexts.iter().find(|x| { @@ -168,7 +171,14 @@ pub fn default_namespace(args: Cli) -> Result<(), Error> { }; commands::set_default_namespace(&ns, &ctx); - commands::set_namespace(&ctx, &ns, &DEST, &config); + let result = commands::set_namespace(&ctx, &ns, &DEST, &config); + println!( + "{}/{}:{}", + &DEST.as_str(), + str::replace(&result, ":", "_"), + *KUBECONFIG + ); + Ok(()) } From 238e9d20941b2262cc4408b8ac6d56f0760fe601 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 18:32:22 +0200 Subject: [PATCH 16/28] include files by default --- src/commands.rs | 13 ------------- src/config.rs | 47 +++++++++++++++++++++++++---------------------- src/main.rs | 44 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 9341e7c..a87a8e0 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -52,19 +52,6 @@ pub fn get_namespaces() -> Vec { string.lines().skip(1).map(ToOwned::to_owned).collect() } -pub fn get_current_context() -> String { - let output = Command::new("kubectl") - .args(["config", "current-context"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap() - .wait_with_output() - .unwrap(); - - String::from_utf8(output.stdout).unwrap().trim().to_owned() -} - /// Prompts the user to select an item from a list. /// Returns the selected item or `None` if no item was selected pub fn selectable_list(input: Vec) -> Option { diff --git a/src/config.rs b/src/config.rs index 7998fb3..a86e2d2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,34 +4,37 @@ use kube::config::NamedContext; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; use std::path::Path; +use std::path::PathBuf; pub fn get() -> Kubeconfig { - let mut merged_config = Kubeconfig::default(); - - let kube_dir = dirs::home_dir() - .map(|home| home.join(".kube")) - .expect("Failed to find home directory"); - - if let Ok(entries) = fs::read_dir(&kube_dir) { - for entry in entries.flatten() { - let path = entry.path(); - - if path.is_file() { - match Kubeconfig::read_from(&path) { - Ok(kubeconfig) => { - merged_config.contexts.extend(kubeconfig.contexts); - merged_config.clusters.extend(kubeconfig.clusters); - merged_config.auth_infos.extend(kubeconfig.auth_infos); - } - Err(err) => { - eprintln!("Failed to parse file {:?} as a Kubeconfig: {:?}", path, err); - } - } + let config_paths = KUBECONFIG.clone(); + let config_map: Vec<(usize, String)> = config_paths + .split(':') + .enumerate() + .map(|(index, path)| (index, path.to_string())) + .collect(); + + let mut config = Kubeconfig::default(); + + for (_index, path_str) in config_map.iter() { + let path = PathBuf::from(path_str); + match Kubeconfig::read_from(&path) { + Ok(kubeconfig) => { + config.contexts.extend(kubeconfig.contexts); + config.clusters.extend(kubeconfig.clusters); + config.auth_infos.extend(kubeconfig.auth_infos); + } + Err(err) => { + eprintln!( + "Failed to load Kubeconfig from '{}': {}", + path.display(), + err + ); } } } - merged_config + config } pub fn build( diff --git a/src/main.rs b/src/main.rs index 671ea92..7ca8670 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,9 @@ mod modes; use crate::error::Error; use clap::Parser; +use std::collections::HashSet; use std::env; +use std::fs; use std::io; use std::process; @@ -14,19 +16,41 @@ extern crate lazy_static; lazy_static! { static ref KUBECONFIG: String = { - match env::var("KUBECONFIG") { - Ok(val) => { - let mut paths: String = String::new(); - for s in val.split_inclusive(':') { - if s.contains("/kubesess/cache") { - continue; + let mut paths_set: HashSet = HashSet::new(); + + // Get KUBECONFIG environment variable and add unique paths, ignoring kubesess/cache + if let Ok(val) = env::var("KUBECONFIG") { + val.split(':') + .filter(|s| !s.contains("/kubesess/cache")) + .for_each(|s| { + paths_set.insert(s.to_string()); + }); + } + + // Add all files under .kube directory + if let Some(home_dir) = dirs::home_dir() { + let kube_dir = home_dir.join(".kube"); + if let Ok(entries) = fs::read_dir(&kube_dir) { + entries.filter_map(Result::ok).for_each(|entry| { + let path = entry.path(); + if path.is_file() { + if let Some(path_str) = path.to_str() { + paths_set.insert(path_str.to_string()); + } } - paths.push_str(s); - } - paths + }); } - Err(_e) => format!("{}/.kube/config", dirs::home_dir().unwrap().display()), } + + // Collect all unique paths, sort them, and move .kube/config to the end if it exists + let mut paths_vec: Vec<_> = paths_set.into_iter().collect(); + paths_vec.sort(); + if let Some(pos) = paths_vec.iter().position(|p| p.ends_with(".kube/config")) { + let kube_config = paths_vec.remove(pos); + paths_vec.push(kube_config); + } + + paths_vec.join(":") }; static ref KUBESESSCONFIG: String = { match env::var("KUBECONFIG") { From cda6ea7667c802effa5cd9ad72f28710043e4e21 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 21:53:23 +0200 Subject: [PATCH 17/28] solved default issue --- src/commands.rs | 8 +++---- src/config.rs | 60 ++++++++++++++++++++++++++++++------------------- src/main.rs | 43 ++++++++++++++++------------------- src/modes.rs | 36 ++++++++++++++++++----------- 4 files changed, 82 insertions(+), 65 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index a87a8e0..eedde85 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,6 +3,7 @@ use crate::error::SetContextError; use std::{ io::Cursor, + path::PathBuf, process::{Command, Stdio}, }; extern crate skim; @@ -26,13 +27,10 @@ pub fn set_default_namespace(ns: &str, ctx: &str) { .unwrap(); } -pub fn set_default_context(ctx: &str) { +pub fn set_default_context(ctx: &str, target: &PathBuf) { Command::new("kubectl") .arg("config") - .arg(format!( - "--kubeconfig={}/.kube/config", - dirs::home_dir().unwrap().display() - )) + .arg(format!("--kubeconfig={}", target.to_string_lossy())) .arg("use-context") .arg(ctx) .stdout(Stdio::null()) diff --git a/src/config.rs b/src/config.rs index a86e2d2..200aea5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,27 +2,46 @@ use crate::{KUBECONFIG, KUBESESSCONFIG}; use kube::config::Kubeconfig; use kube::config::NamedContext; use std::fs::{self, File}; -use std::io::{BufReader, BufWriter, Read}; +use std::io::BufWriter; use std::path::Path; use std::path::PathBuf; -pub fn get() -> Kubeconfig { - let config_paths = KUBECONFIG.clone(); - let config_map: Vec<(usize, String)> = config_paths +pub struct KubeConfigs { + pub config: Kubeconfig, + pub configs: Vec<(Kubeconfig, PathBuf)>, +} + +pub fn get(current_session: Option<&str>) -> KubeConfigs { + use std::collections::HashSet; + use std::path::PathBuf; + + let config_paths_str = match current_session { + Some(path) if !path.is_empty() => format!("{}:{}", path, KUBECONFIG.clone()), + Some(_) | None => KUBECONFIG.clone(), + }; + + let mut paths_set = HashSet::new(); + let config_paths: Vec = config_paths_str .split(':') - .enumerate() - .map(|(index, path)| (index, path.to_string())) + .filter(|path| !path.is_empty() && paths_set.insert(path.to_string())) + .map(|path| PathBuf::from(path)) .collect(); - let mut config = Kubeconfig::default(); + let mut conifg = Kubeconfig::default(); + let mut configs = Vec::new(); - for (_index, path_str) in config_map.iter() { - let path = PathBuf::from(path_str); + for path in config_paths { match Kubeconfig::read_from(&path) { Ok(kubeconfig) => { - config.contexts.extend(kubeconfig.contexts); - config.clusters.extend(kubeconfig.clusters); - config.auth_infos.extend(kubeconfig.auth_infos); + configs.push((kubeconfig.clone(), path.clone())); + + conifg.contexts.extend(kubeconfig.contexts.into_iter()); + conifg.clusters.extend(kubeconfig.clusters.into_iter()); + conifg.auth_infos.extend(kubeconfig.auth_infos.into_iter()); + + if conifg.current_context.is_none() { + conifg.current_context = kubeconfig.current_context.clone(); + } } Err(err) => { eprintln!( @@ -34,7 +53,10 @@ pub fn get() -> Kubeconfig { } } - config + KubeConfigs { + config: conifg, + configs, + } } pub fn build( @@ -147,15 +169,7 @@ pub fn get_current_session() -> Kubeconfig { KUBESESSCONFIG.as_str() }; - let f = File::open(current).unwrap(); - - let mut reader = BufReader::new(f); - let mut tmp = String::new(); - reader - .read_to_string(&mut tmp) - .expect("Unable to read file"); - - let config = serde_yaml::from_str(tmp.trim()).unwrap(); + let configs = get(Some(current)); - config + configs.config } diff --git a/src/main.rs b/src/main.rs index 7ca8670..7bbe8e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::collections::HashSet; use std::env; use std::fs; use std::io; +use std::path; use std::process; #[macro_use] @@ -16,41 +17,35 @@ extern crate lazy_static; lazy_static! { static ref KUBECONFIG: String = { - let mut paths_set: HashSet = HashSet::new(); - // Get KUBECONFIG environment variable and add unique paths, ignoring kubesess/cache + let mut paths_set = HashSet::new(); + let mut all_paths = Vec::new(); + + // Get paths from KUBECONFIG environment variable, preserving order if let Ok(val) = env::var("KUBECONFIG") { - val.split(':') - .filter(|s| !s.contains("/kubesess/cache")) - .for_each(|s| { - paths_set.insert(s.to_string()); - }); + all_paths.extend(val.split(':').filter(|s| !s.contains("/kubesess/cache")).filter_map(|s| { + if paths_set.insert(s.to_string()) { + Some(s.to_string()) + } else { + None + } + })); } - // Add all files under .kube directory + // Collect paths from ~/.kube directory if let Some(home_dir) = dirs::home_dir() { let kube_dir = home_dir.join(".kube"); if let Ok(entries) = fs::read_dir(&kube_dir) { - entries.filter_map(Result::ok).for_each(|entry| { + let kube_paths: Vec<_> = entries.filter_map(Result::ok).filter_map(|entry| { let path = entry.path(); - if path.is_file() { - if let Some(path_str) = path.to_str() { - paths_set.insert(path_str.to_string()); - } - } - }); - } - } + path.to_str().map(|p| p.to_string()) + }).filter(|p| path::Path::new(p).is_file() && paths_set.insert(p.clone())).collect(); - // Collect all unique paths, sort them, and move .kube/config to the end if it exists - let mut paths_vec: Vec<_> = paths_set.into_iter().collect(); - paths_vec.sort(); - if let Some(pos) = paths_vec.iter().position(|p| p.ends_with(".kube/config")) { - let kube_config = paths_vec.remove(pos); - paths_vec.push(kube_config); + all_paths.extend(kube_paths); + } } - paths_vec.join(":") + all_paths.join(":") }; static ref KUBESESSCONFIG: String = { match env::var("KUBECONFIG") { diff --git a/src/modes.rs b/src/modes.rs index 99b2f22..e10ad35 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -1,17 +1,17 @@ use crate::{ - commands::{self}, - config, - error::Error, + commands, config, + error::{Error, SetContextError}, Cli, DEST, KUBECONFIG, }; pub fn default_context(args: Cli) -> Result<(), Error> { - let config = config::get(); + let config = config::get(None); if args.current { println!( "{}", config + .config .current_context .as_deref() .unwrap_or("No current context set") @@ -22,6 +22,7 @@ pub fn default_context(args: Cli) -> Result<(), Error> { let ctx = match args.value { None => { let options: Vec = config + .config .contexts .iter() .map(|context| context.name.to_string()) @@ -32,20 +33,29 @@ pub fn default_context(args: Cli) -> Result<(), Error> { Some(x) => x.trim().to_string(), }; - commands::set_default_context(&ctx); - - let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); - - if set_context_result.is_ok() { - println!("{}", KUBECONFIG.as_str()); + if let Some(target) = config + .configs + .iter() + .find(|(kubeconfig, _)| { + kubeconfig + .contexts + .iter() + .any(|context| context.name == ctx) + }) + .map(|(_, path)| path.clone()) + { + commands::set_default_context(&ctx, &target); + // TODO: We should move the target to the front of the line instead of inserting a + // duplicate + println!("{}:{}", target.to_string_lossy(), KUBECONFIG.as_str()); } Ok(()) } pub fn context(args: Cli) -> Result<(), Error> { + let config = config::get_current_session(); if args.current { - let config = config::get_current_session(); println!( "{}", config @@ -56,7 +66,6 @@ pub fn context(args: Cli) -> Result<(), Error> { return Ok(()); } - let config = config::get(); let ctx = match args.value { None => { let options: Vec = config @@ -183,11 +192,12 @@ pub fn default_namespace(args: Cli) -> Result<(), Error> { } pub fn completion_context(args: Cli) { - let config = config::get(); + let config = config::get(None); let search_value = args.value.as_deref().unwrap_or(""); let options: Vec = config + .config .contexts .iter() .filter(|context| context.name.starts_with(search_value)) From 2a2072e59e7f46e4cb926335b2458d10306b8dab Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 22:01:34 +0200 Subject: [PATCH 18/28] set default ns solved --- src/commands.rs | 7 ++----- src/modes.rs | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index eedde85..6985c2f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -10,13 +10,10 @@ extern crate skim; use kube::config::Kubeconfig; use skim::prelude::*; -pub fn set_default_namespace(ns: &str, ctx: &str) { +pub fn set_default_namespace(ns: &str, ctx: &str, target: &PathBuf) { Command::new("kubectl") .arg("config") - .arg(format!( - "--kubeconfig={}/.kube/config", - dirs::home_dir().unwrap().display() - )) + .arg(format!("--kubeconfig={}", target.to_string_lossy())) .arg("set-context") .arg(ctx) .arg(format!("--namespace={}", ns)) diff --git a/src/modes.rs b/src/modes.rs index e10ad35..0af0ebf 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -1,8 +1,4 @@ -use crate::{ - commands, config, - error::{Error, SetContextError}, - Cli, DEST, KUBECONFIG, -}; +use crate::{commands, config, error::Error, Cli, DEST, KUBECONFIG}; pub fn default_context(args: Cli) -> Result<(), Error> { let config = config::get(None); @@ -142,16 +138,17 @@ pub fn namespace(args: Cli) -> Result<(), Error> { } pub fn default_namespace(args: Cli) -> Result<(), Error> { - let config = config::get_current_session(); - let ctx = &config + let current_session = config::get_current_session(); + let config = config::get(None); + let ctx = ¤t_session .current_context .as_deref() .unwrap_or("No current context set"); if args.current { - if let Some(ctx) = config.contexts.iter().find(|x| { + if let Some(ctx) = current_session.contexts.iter().find(|x| { x.name - == config + == current_session .current_context .as_deref() .unwrap_or("No current context set") @@ -179,8 +176,21 @@ pub fn default_namespace(args: Cli) -> Result<(), Error> { Some(x) => x.trim().to_string(), }; - commands::set_default_namespace(&ns, &ctx); - let result = commands::set_namespace(&ctx, &ns, &DEST, &config); + if let Some(target) = config + .configs + .iter() + .find(|(kubeconfig, _)| { + kubeconfig + .contexts + .iter() + .any(|context| context.name == *ctx) + }) + .map(|(_, path)| path.clone()) + { + commands::set_default_namespace(&ns, &ctx, &target); + } + + let result = commands::set_namespace(&ctx, &ns, &DEST, ¤t_session); println!( "{}/{}:{}", &DEST.as_str(), From cd89ce133bdcd0d360304deac076213502595d90 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 22:04:48 +0200 Subject: [PATCH 19/28] fix clippy errors --- src/commands.rs | 6 +++--- src/config.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 6985c2f..d11af40 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,14 +3,14 @@ use crate::error::SetContextError; use std::{ io::Cursor, - path::PathBuf, + path::Path, process::{Command, Stdio}, }; extern crate skim; use kube::config::Kubeconfig; use skim::prelude::*; -pub fn set_default_namespace(ns: &str, ctx: &str, target: &PathBuf) { +pub fn set_default_namespace(ns: &str, ctx: &str, target: &Path) { Command::new("kubectl") .arg("config") .arg(format!("--kubeconfig={}", target.to_string_lossy())) @@ -24,7 +24,7 @@ pub fn set_default_namespace(ns: &str, ctx: &str, target: &PathBuf) { .unwrap(); } -pub fn set_default_context(ctx: &str, target: &PathBuf) { +pub fn set_default_context(ctx: &str, target: &Path) { Command::new("kubectl") .arg("config") .arg(format!("--kubeconfig={}", target.to_string_lossy())) diff --git a/src/config.rs b/src/config.rs index 200aea5..74b0007 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,7 +24,7 @@ pub fn get(current_session: Option<&str>) -> KubeConfigs { let config_paths: Vec = config_paths_str .split(':') .filter(|path| !path.is_empty() && paths_set.insert(path.to_string())) - .map(|path| PathBuf::from(path)) + .map(PathBuf::from) .collect(); let mut conifg = Kubeconfig::default(); From b7a9729ae37c850b87110376277f882c974a994c Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 22:07:58 +0200 Subject: [PATCH 20/28] fix clippy erros --- src/modes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modes.rs b/src/modes.rs index 0af0ebf..6996d92 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -187,10 +187,10 @@ pub fn default_namespace(args: Cli) -> Result<(), Error> { }) .map(|(_, path)| path.clone()) { - commands::set_default_namespace(&ns, &ctx, &target); + commands::set_default_namespace(&ns, ctx, &target); } - let result = commands::set_namespace(&ctx, &ns, &DEST, ¤t_session); + let result = commands::set_namespace(ctx, &ns, &DEST, ¤t_session); println!( "{}/{}:{}", &DEST.as_str(), From 5a7cb54b8da49fbc1a99fd3dd8a61a4046eb938a Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 22:21:14 +0200 Subject: [PATCH 21/28] removed tokioa --- Cargo.lock | 493 +--------------------------------------------------- Cargo.toml | 4 +- src/main.rs | 3 +- 3 files changed, 7 insertions(+), 493 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7aabf5..98c45be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,19 +17,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -39,12 +26,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -89,51 +70,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "async-broadcast" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" -dependencies = [ - "event-listener", - "event-listener-strategy", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - -[[package]] -name = "async-trait" -version = "0.1.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "atty" version = "0.2.14" @@ -151,17 +87,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "backoff" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" -dependencies = [ - "getrandom", - "instant", - "rand", -] - [[package]] name = "backtrace" version = "0.3.74" @@ -239,12 +164,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "bytes" version = "1.7.2" @@ -335,15 +254,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "concurrent-queue" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "const_fn" version = "0.4.10" @@ -447,18 +357,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "darling_core 0.10.2", - "darling_macro 0.10.2", -] - -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core 0.20.10", - "darling_macro 0.20.10", + "darling_core", + "darling_macro", ] [[package]] @@ -475,42 +375,17 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.11.1", - "syn 2.0.79", -] - [[package]] name = "darling_macro" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ - "darling_core 0.10.2", + "darling_core", "quote", "syn 1.0.109", ] -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core 0.20.10", - "quote", - "syn 2.0.79", -] - [[package]] name = "defer-drop" version = "1.3.0" @@ -527,7 +402,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" dependencies = [ - "darling 0.10.2", + "darling", "derive_builder_core", "proc-macro2", "quote", @@ -540,7 +415,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" dependencies = [ - "darling 0.10.2", + "darling", "proc-macro2", "quote", "syn 1.0.109", @@ -615,50 +490,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - -[[package]] -name = "educe" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" -dependencies = [ - "enum-ordinalize", - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "enum-ordinalize" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" -dependencies = [ - "enum-ordinalize-derive", -] - -[[package]] -name = "enum-ordinalize-derive" -version = "4.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "env_logger" version = "0.8.4" @@ -678,36 +515,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "event-listener" -version = "5.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "event-listener-strategy" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" -dependencies = [ - "event-listener", - "pin-project-lite", -] - -[[package]] -name = "fluent-uri" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c704e9dbe1ddd863da1e6ff3567795087b1eb201ce80d8fa81162e1516500d" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "fnv" version = "1.0.7" @@ -759,17 +566,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "futures-sink" version = "0.3.31" @@ -791,7 +587,6 @@ dependencies = [ "futures-channel", "futures-core", "futures-io", - "futures-macro", "futures-sink", "futures-task", "memchr", @@ -842,16 +637,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] - [[package]] name = "hashbrown" version = "0.15.0" @@ -1103,15 +888,6 @@ dependencies = [ "hashbrown 0.15.0", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "itertools" version = "0.10.3" @@ -1136,18 +912,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "json-patch" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b1fb8864823fad91877e6caea0baca82e49e8db50f8e5c9f9a453e27d3330fc" -dependencies = [ - "jsonptr", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "jsonpath-rust" version = "0.5.1" @@ -1163,17 +927,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "jsonptr" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c6e529149475ca0b2820835d3dce8fcc41c6b943ca608d32f35b449255e4627" -dependencies = [ - "fluent-uri", - "serde", - "serde_json", -] - [[package]] name = "k8s-openapi" version = "0.23.0" @@ -1196,8 +949,6 @@ dependencies = [ "k8s-openapi", "kube-client", "kube-core", - "kube-derive", - "kube-runtime", ] [[package]] @@ -1247,56 +998,13 @@ dependencies = [ "chrono", "form_urlencoded", "http", - "json-patch", "k8s-openapi", - "schemars", "serde", "serde-value", "serde_json", "thiserror", ] -[[package]] -name = "kube-derive" -version = "0.96.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9364e04cc5e0482136c6ee8b7fb7551812da25802249f35b3def7aaa31e82ad" -dependencies = [ - "darling 0.20.10", - "proc-macro2", - "quote", - "serde_json", - "syn 2.0.79", -] - -[[package]] -name = "kube-runtime" -version = "0.96.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fbf1f6ffa98e65f1d2a9a69338bb60605d46be7edf00237784b89e62c9bd44" -dependencies = [ - "ahash", - "async-broadcast", - "async-stream", - "async-trait", - "backoff", - "educe", - "futures", - "hashbrown 0.14.5", - "json-patch", - "jsonptr", - "k8s-openapi", - "kube-client", - "parking_lot", - "pin-project", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "kubesess" version = "1.2.11" @@ -1311,8 +1019,6 @@ dependencies = [ "serde_yaml", "skim", "thiserror", - "tokio", - "tokio-macros", ] [[package]] @@ -1337,16 +1043,6 @@ dependencies = [ "libc", ] -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.22" @@ -1464,35 +1160,6 @@ version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" -[[package]] -name = "parking" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pem" version = "3.0.4" @@ -1554,26 +1221,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "pin-project" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1586,15 +1233,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - [[package]] name = "predicates" version = "2.1.1" @@ -1670,36 +1308,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "rayon" version = "1.10.0" @@ -1720,15 +1328,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags 2.6.0", -] - [[package]] name = "redox_users" version = "0.4.6" @@ -1893,36 +1492,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "schemars" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 2.0.79", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "secrecy" version = "0.10.3" @@ -2000,17 +1569,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "serde_json" version = "1.0.131" @@ -2230,12 +1788,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[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" @@ -2398,25 +1950,12 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", - "tokio-macros", "windows-sys 0.52.0", ] -[[package]] -name = "tokio-macros" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -2438,7 +1977,6 @@ dependencies = [ "futures-core", "futures-sink", "pin-project-lite", - "slab", "tokio", ] @@ -2817,27 +2355,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/Cargo.toml b/Cargo.toml index 0cf903b..1278eb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,8 @@ serde = { version = "1.0.141", features = ["derive"] } lazy_static = "1.4.0" skim = "0.9.4" thiserror = "1.0.56" -kube = { version = "0.96.0", features = ["runtime", "client", "derive", "config"] } +kube = { version = "0.96.0", features = ["config"] } k8s-openapi = { version = "0.23.0", features = ["latest"] } -tokio = { version = "1.40.0", features = ["full"] } -tokio-macros = "=2.4.0" [dev-dependencies] assert_cmd = "2.0" diff --git a/src/main.rs b/src/main.rs index 7bbe8e5..06dc43b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,8 +108,7 @@ impl Mode { } } -#[tokio::main] -async fn main() -> Result<(), io::Error> { +fn main() -> Result<(), io::Error> { let args = Cli::parse(); if let Err(err) = Mode::invoke(&args.mode) { From bd3edd5dee5ad9710d700cb78844ac3e4504fef9 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 22:25:13 +0200 Subject: [PATCH 22/28] solved duplicates in context --- src/modes.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modes.rs b/src/modes.rs index 6996d92..dd7874f 100644 --- a/src/modes.rs +++ b/src/modes.rs @@ -50,11 +50,11 @@ pub fn default_context(args: Cli) -> Result<(), Error> { } pub fn context(args: Cli) -> Result<(), Error> { - let config = config::get_current_session(); + let current_session = config::get_current_session(); if args.current { println!( "{}", - config + current_session .current_context .as_deref() .unwrap_or("No current context set") @@ -62,9 +62,11 @@ pub fn context(args: Cli) -> Result<(), Error> { return Ok(()); } + let config = config::get(None); let ctx = match args.value { None => { let options: Vec = config + .config .contexts .iter() .map(|context| context.name.to_string()) @@ -75,7 +77,8 @@ pub fn context(args: Cli) -> Result<(), Error> { Some(x) => x.trim().to_string(), }; - let set_context_result = commands::set_context(&ctx, &DEST, &config).map_err(Error::SetContext); + let set_context_result = + commands::set_context(&ctx, &DEST, ¤t_session).map_err(Error::SetContext); if set_context_result.is_ok() { println!( From ef8b7a28061711fa364c4cd505d37f08158a23b4 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:22:13 +0200 Subject: [PATCH 23/28] fix tests --- Cargo.lock | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + tests/cli.rs | 92 +++++++++++++++++++++++++++++------- 3 files changed, 209 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98c45be..16324f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,6 +515,22 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "fnv" version = "1.0.7" @@ -888,6 +904,15 @@ dependencies = [ "hashbrown 0.15.0", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "itertools" version = "0.10.3" @@ -1017,7 +1042,9 @@ dependencies = [ "lazy_static", "serde", "serde_yaml", + "serial_test", "skim", + "tempfile", "thiserror", ] @@ -1043,6 +1070,22 @@ dependencies = [ "libc", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" @@ -1160,6 +1203,31 @@ version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pem" version = "3.0.4" @@ -1328,6 +1396,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.6" @@ -1404,6 +1481,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.23.15" @@ -1492,6 +1582,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "secrecy" version = "0.10.3" @@ -1594,6 +1690,28 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "serial_test" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" +dependencies = [ + "lazy_static", + "parking_lot", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "sha1" version = "0.6.1" @@ -1822,6 +1940,19 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "tempfile" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "term" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index 1278eb5..cd64350 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,6 @@ kube = { version = "0.96.0", features = ["config"] } k8s-openapi = { version = "0.23.0", features = ["latest"] } [dev-dependencies] +tempfile = "3.3" assert_cmd = "2.0" +serial_test = "0.5" diff --git a/tests/cli.rs b/tests/cli.rs index 98a95d0..0332b26 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,62 +1,122 @@ use assert_cmd::prelude::*; -use std::{env, process::Command}; +use serial_test::serial; +use std::{env, fs::File, io::Write, process::Command}; +use tempfile::TempDir; + +fn setup_environment() -> (TempDir, String, String) { + // Create a temporary directory + let temp_dir = TempDir::new().expect("Failed to create temp directory"); + + // Set the HOME environment variable + env::set_var("HOME", temp_dir.path()); + + // Create a file named `config` inside the temporary directory + let kubeconfig_path = temp_dir.path().join("config"); + let mut kubeconfig_file = + File::create(&kubeconfig_path).expect("Failed to create kubeconfig file"); + + // Write the Kubernetes configuration content to the file + let kubeconfig_content = r#" +apiVersion: v1 +clusters: +- cluster: + server: https://kubernetes.docker.internal:6443 + name: docker-desktop +contexts: +- context: + cluster: docker-desktop + namespace: default + user: docker-desktop + name: docker-desktop +current-context: docker-desktop +kind: Config +preferences: {} +users: +- name: docker-desktop +"#; + kubeconfig_file + .write_all(kubeconfig_content.as_bytes()) + .expect("Failed to write kubeconfig content"); + + // Set the KUBECONFIG environment variable to point to the new file + env::set_var("KUBECONFIG", kubeconfig_path.to_str().unwrap()); + + // Return the temporary directory and paths for use in tests + let home_dir = temp_dir.path().to_str().unwrap().to_owned(); + let kubeconfig = kubeconfig_path.to_str().unwrap().to_owned(); + + (temp_dir, home_dir, kubeconfig) +} + +fn reset_environment() { + env::remove_var("HOME"); + env::remove_var("KUBECONFIG"); +} #[test] +#[serial] fn set_context() -> Result<(), Box> { - let expected: String = format!( - "{}/.kube/kubesess/cache/docker-desktop:{}", - dirs::home_dir().unwrap().display(), - env::var("KUBECONFIG").unwrap() - ); + let (_temp_dir, _home_dir, kubeconfig) = setup_environment(); + + let expected: String = format!("{}", kubeconfig); let mut cmd = Command::cargo_bin("kubesess")?; let output = cmd.arg("-v docker-desktop").arg("context").unwrap(); let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned(); - assert_eq!(output_string, expected); + + assert!(output_string.contains(&expected)); + reset_environment(); Ok(()) } #[test] +#[serial] fn set_default_context() -> Result<(), Box> { - let expected: String = env::var("KUBECONFIG").unwrap(); + let (_temp_dir, _home_dir, kubeconfig) = setup_environment(); + + let expected: String = format!("{}", kubeconfig); let mut cmd = Command::cargo_bin("kubesess")?; let output = cmd.arg("-v docker-desktop").arg("default-context").unwrap(); let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned(); - assert_eq!(output_string, expected); + assert!(output_string.contains(&expected)); + reset_environment(); Ok(()) } #[test] +#[serial] fn set_namespace() -> Result<(), Box> { - let expected: String = format!( - "{}/.kube/kubesess/cache/docker-desktop:{}", - dirs::home_dir().unwrap().display(), - env::var("KUBECONFIG").unwrap() - ); + let (_temp_dir, _home_dir, kubeconfig) = setup_environment(); + let expected: String = format!("{}", kubeconfig); let mut cmd = Command::cargo_bin("kubesess")?; let output = cmd.arg("-v default").arg("namespace").unwrap(); let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned(); - assert_eq!(output_string, expected); + assert!(output_string.contains(&expected)); Ok(()) } #[test] +#[serial] fn set_default_namespace() -> Result<(), Box> { + reset_environment(); + let (_temp_dir, _home_dir, kubeconfig) = setup_environment(); + let expected: String = format!("{}", kubeconfig); + let mut cmd = Command::cargo_bin("kubesess")?; let output = cmd.arg("-v default").arg("default-namespace").unwrap(); let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned(); - assert_eq!(output_string, format!("")); + assert!(output_string.contains(&expected)); Ok(()) } From abb3e9a31d44f72c69135b7251db6e2a159de4d1 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:24:24 +0200 Subject: [PATCH 24/28] simplify test --- .github/workflows/run_tests.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 3b826a2..2309d72 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -14,12 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v2 - uses: tale/kubectl-action@v1 - with: - base64-kube-config: ${{ inputs.KUBECONFIG }} - name: Test run: | cargo check cargo test --all - env: - KUBECONFIG: "/home/runner/.kube/config" From c0b784b09667981be702d6e6d4ffa243eaa88cfb Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:24:39 +0200 Subject: [PATCH 25/28] simplify test --- .github/workflows/run_tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 2309d72..9cdbe58 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -13,7 +13,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - uses: tale/kubectl-action@v1 - name: Test run: | cargo check From c19873c494a04140cc3e9ecf6e52166a96e0b3be Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:29:27 +0200 Subject: [PATCH 26/28] cleanup code --- src/error.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index d55e69e..85f0714 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,12 +8,6 @@ pub enum Error { NoItemSelected { prompt: &'static str }, } -// #[derive(Error, Debug)] -// pub enum SetNamespaceError { -// #[error("no namespace exists with the name {ns}")] -// KubeNamespaceNotFound { ns: String }, -// } - #[derive(Error, Debug)] pub enum SetContextError { #[error("no context exists with the name {ctx}")] From c1e5c1f449837c70918a50235e32ca55aa774114 Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:36:01 +0200 Subject: [PATCH 27/28] update readme --- .github/README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/README.md b/.github/README.md index 5450a97..fe9f8ac 100755 --- a/.github/README.md +++ b/.github/README.md @@ -159,7 +159,7 @@ export KUBECONFIG=$HOME/.kube/config:$HOME/.kube/config-demo:$HOME/.kube/config- > :Note: **The order is important*: the first file will be the master config! -The second way is to let Kubesess handle it by adding one or more .yaml files under the $HOME/.kube folder and it will be automatically merged. +The second way is to let Kubesess handle it by adding one or more config files under the $HOME/.kube folder and it will be automatically merged. #### Add information to prompt (there are other good tools for this, kube-ps1 and p10k) ``` @@ -202,8 +202,8 @@ RPROMPT='$(prompt_context)' - [x] Add tab completion - https://github.com/clap-rs/clap/issues/1232 - [x] Add to brew - [x] Add support for multiple .kube/config files -- [ ] Add support for multiple namespace per session -- [ ] Add error handling +- [x] Add support for multiple namespace per session +- [x] Add error handling ## Troubleshooting @@ -224,14 +224,21 @@ This is how the ```$KUBECONFIG``` should look like (replace ```${USER}``` with y This is how the generated file should look like: ```yaml -kind: Config -apiVersion: v1 -current-context: docker-desktop +clusters: +- name: docker-desktop + cluster: + server: https://kubernetes.docker.internal:6443 + certificate-authority-data: REDACTED +users: +- name: docker-desktop + user: + client-certificate-data: REDACTED + client-key-data: REDACTED contexts: -- context: - namespace: default +- name: docker-desktop + context: cluster: docker-desktop user: docker-desktop - name: docker-desktop + namespace: default +current-context: docker-desktop ``` - From bf34d6af1a70323c463ac90000d1a058fac30b3f Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 20 Oct 2024 23:37:21 +0200 Subject: [PATCH 28/28] update version --- .github/README.md | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index fe9f8ac..5133d8d 100755 --- a/.github/README.md +++ b/.github/README.md @@ -96,7 +96,7 @@ Probably most of the speed gains are because I am bypassing kubectl and just edi #### Binary Download and extract the binary. ```zsh -KUBESESS_VERSION=1.2.11 && \ +KUBESESS_VERSION=2.0.0 && \ KUBESESS_OS=x86_64-unknown-linux-gnu && \ wget "https://github.com/Ramilito/kubesess/releases/download/${KUBESESS_VERSION}/kubesess_${KUBESESS_VERSION}_${KUBESESS_OS}.tar.gz" && \ mkdir -p $HOME/.kube/kubesess && tar zxpf kubesess_${KUBESESS_VERSION}_${KUBESESS_OS}.tar.gz -C $HOME/.kube/kubesess && \ diff --git a/Cargo.toml b/Cargo.toml index cd64350..5a26c26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kubesess" -version = "1.2.11" +version = "2.0.0" authors = ["https://github.com/ramilito"] edition = "2021"