diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2063ff3..85f7594 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,12 +1,11 @@ name: CI on: + workflow_dispatch: push: branches: - main pull_request: - branches: - - main jobs: test: diff --git a/Cargo.lock b/Cargo.lock index 242a2d4..764f9c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,9 +200,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", @@ -259,9 +259,9 @@ checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -303,9 +303,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.0" +version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" +checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" [[package]] name = "bytes" @@ -315,9 +315,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.99" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "eaff6f8ce506b9773fa786672d63fc7a191ffea1be33f72bbd4aeacefca9ffc8" [[package]] name = "cfg-if" @@ -334,7 +334,7 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -361,9 +361,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.7" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", "clap_derive", @@ -371,9 +371,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstream", "anstyle", @@ -383,9 +383,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck", "proc-macro2", @@ -545,9 +545,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "encoding_rs" @@ -879,9 +879,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -900,9 +900,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.29" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -1012,9 +1012,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" @@ -1046,9 +1046,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loom" @@ -1076,9 +1076,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1088,9 +1088,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -1162,9 +1162,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "memchr", ] @@ -1207,7 +1207,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1250,9 +1250,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", "thiserror", @@ -1261,9 +1261,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a" dependencies = [ "pest", "pest_generator", @@ -1271,9 +1271,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183" dependencies = [ "pest", "pest_meta", @@ -1284,9 +1284,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f" dependencies = [ "once_cell", "pest", @@ -1369,6 +1369,14 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "polyjuice" +version = "0.1.0" +source = "git+https://github.com/A2-ai/polyjuice#a41d8e3b40f7c3c18e53a2b5644f91662ad1ee6f" +dependencies = [ + "users", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1383,9 +1391,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1481,9 +1489,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ "bitflags", ] @@ -1645,9 +1653,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "8.4.0" +version = "8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19549741604902eb99a7ed0ee177a0663ee1eda51a29f71401f166e47e77806a" +checksum = "fa66af4a4fdd5e7ebc276f115e895611a34739a9c1c01028383d612d550953c0" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -1656,9 +1664,9 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "8.4.0" +version = "8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9f96e283ec64401f30d3df8ee2aaeb2561f34c824381efa24a35f79bf40ee4" +checksum = "6125dbc8867951125eec87294137f4e9c2c96566e61bf72c45095a7c77761478" dependencies = [ "proc-macro2", "quote", @@ -1669,9 +1677,9 @@ dependencies = [ [[package]] name = "rust-embed-utils" -version = "8.4.0" +version = "8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38c74a686185620830701348de757fd36bef4aa9680fd23c49fc539ddcc1af32" +checksum = "2e5347777e9aacb56039b0e1f28785929a8a3b709e87482e7442c72e7c12529d" dependencies = [ "sha2", "walkdir", @@ -1731,18 +1739,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -1751,9 +1759,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -1847,6 +1855,7 @@ dependencies = [ "colored", "futures", "getrandom", + "polyjuice", "serde", "strum_macros", "tempdir", @@ -1914,9 +1923,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "2.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" dependencies = [ "proc-macro2", "quote", @@ -2104,9 +2113,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.14" +version = "0.22.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" +checksum = "d59a3a72298453f564e2b111fa896f8d07fabb36f51f06d7e875fc5e0b5a3ef1" dependencies = [ "indexmap", "serde", @@ -2281,6 +2290,16 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "utf8parse" version = "0.2.2" @@ -2424,7 +2443,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -2442,7 +2461,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -2462,18 +2481,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2484,9 +2503,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -2496,9 +2515,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -2508,15 +2527,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -2526,9 +2545,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -2538,9 +2557,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -2550,9 +2569,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -2562,9 +2581,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/Cargo.toml b/Cargo.toml index 779967e..26aa5a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ async-process = "2.2.3" colored = "2.1.0" futures = "0.3.30" getrandom = { version = "0.2.15", features = ["js"] } +polyjuice = { git = "https://github.com/A2-ai/polyjuice" } serde = { version = "1.0.202", features = ["derive"] } strum_macros = "0.26.2" tempdir = "0.3.7" @@ -53,5 +54,8 @@ walkdir = "2.5.0" inherits = "release" lto = "thin" +[workspace.metadata.dist.dependencies.apt] +libpam0g-dev = "*" + [workspace.metadata.dist.github-custom-runners] aarch64-unknown-linux-gnu = "ubuntu-arm-22.04" diff --git a/cli/src/fill.rs b/cli/src/fill.rs index c9907ee..171693b 100644 --- a/cli/src/fill.rs +++ b/cli/src/fill.rs @@ -9,7 +9,6 @@ use spackle::{ }, util::copy, }; -use tera::Context; use crate::Cli; @@ -193,7 +192,7 @@ pub fn run( } } - match hook::run_hooks(&config.hooks, out, &slot_data, &hook_data) { + match hook::run_hooks(&config.hooks, out, &slot_data, &hook_data, None) { Ok(results) => { println!("🪝 Evaluated {} hooks", results.len()); diff --git a/src/core/hook.rs b/src/core/hook.rs index a787588..b27c338 100644 --- a/src/core/hook.rs +++ b/src/core/hook.rs @@ -78,6 +78,7 @@ pub fn run_hooks( dir: impl AsRef, slot_data: &HashMap, hook_data: &HashMap, + run_as_user: Option, ) -> Result, Error> { let mut skipped_hooks = Vec::new(); let mut queued_hooks = Vec::new(); @@ -140,7 +141,20 @@ pub fn run_hooks( continue; } - let output = Command::new(&hook.command[0]) + let mut cmd = match run_as_user { + Some(ref user) => match polyjuice::cmd_as_user(&hook.command[0], user.clone()) { + Ok(cmd) => cmd, + Err(e) => { + return Err(Error { + hook: hook.clone(), + error: ErrorKind::CommandFailed(e.to_string()), + }) + } + }, + None => Command::new(&hook.command[0]), + }; + + let output = cmd .args(&hook.command[1..]) .current_dir(dir.as_ref()) .stdout(Stdio::piped()) diff --git a/src/lib.rs b/src/lib.rs index 59af19a..9fa84cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,7 @@ pub fn generate( out_dir: &PathBuf, slot_data: &HashMap, hook_data: &HashMap, + run_as_user: Option, ) -> Result, Error> { if out_dir.exists() { return Err(Error::AlreadyExists(out_dir.clone())); @@ -77,7 +78,7 @@ pub fn generate( } // Run post-template hooks in the output directory - let results = hook::run_hooks(&config.hooks, out_dir, &slot_data, hook_data) + let results = hook::run_hooks(&config.hooks, out_dir, &slot_data, hook_data, run_as_user) .map_err(Error::HookFailed)?; Ok(results) diff --git a/tests/config.rs b/tests/config.rs index 501bb38..3f01d52 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -6,6 +6,7 @@ use tempdir::TempDir; #[test] fn load_empty() { let dir = TempDir::new("spackle").unwrap().into_path(); + fs::write(&dir.join("spackle.toml"), "").unwrap(); let result = config::load(&dir); diff --git a/tests/copy.rs b/tests/copy.rs index 86eb01f..e0583ba 100644 --- a/tests/copy.rs +++ b/tests/copy.rs @@ -2,7 +2,6 @@ use std::{collections::HashMap, fs}; use spackle::util::copy; use tempdir::TempDir; -use tera::Context; #[test] fn ignore_one() { diff --git a/tests/data/proj1-out/main.R b/tests/data/proj1-out/main.R deleted file mode 100644 index 4a59a65..0000000 --- a/tests/data/proj1-out/main.R +++ /dev/null @@ -1,24 +0,0 @@ -# This is a sample R script - -# Printing a vector -x <- c(1, 2, 3) -print(x) - -# Defining a function -my_function <- function(a, b) { - return(a + b) -} - -# Calling the function -result <- my_function(1, 2) -print(result) - -# Creating a data frame -my_data <- data.frame( - name = c("Alice", "Bob", "Charlie", "Joe Bloggs"), - age = c(25, 30, 35, 42) -) - -# Printing the data frame -print(my_data) - diff --git a/tests/data/proj1-out/spackle.toml b/tests/data/proj1-out/spackle.toml deleted file mode 100644 index 3258c25..0000000 --- a/tests/data/proj1-out/spackle.toml +++ /dev/null @@ -1,18 +0,0 @@ - -[[slots]] -key = "file_name" -type = "String" -name = "File name" -description = "The name of the R file (without the extension)" - -[[slots]] -key = "person_name" -type = "String" -name = "Person name" -description = "The name of the fourth person" - -[[slots]] -key = "person_age" -type = "Number" -name = "Person age" -description = "The age of the fourth person" diff --git a/tests/data/proj1-out/subdir/file.txt b/tests/data/proj1-out/subdir/file.txt deleted file mode 100644 index e69de29..0000000 diff --git a/tests/data/proj1-out/subdir/test.json b/tests/data/proj1-out/subdir/test.json deleted file mode 100644 index 63ee994..0000000 --- a/tests/data/proj1-out/subdir/test.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - Joe Bloggs -} \ No newline at end of file diff --git a/tests/data/proj1/bad.txt.j2 b/tests/data/proj1/bad.j2 similarity index 100% rename from tests/data/proj1/bad.txt.j2 rename to tests/data/proj1/bad.j2 diff --git a/tests/data/proj1/spackle.toml b/tests/data/proj1/spackle.toml index 7a46d12..353b322 100644 --- a/tests/data/proj1/spackle.toml +++ b/tests/data/proj1/spackle.toml @@ -1,22 +1,22 @@ [[slots]] -key = "file_name" +key = "slot_1" type = "String" -name = "File name" -description = "The name of the R file (without the extension)" [[slots]] -key = "person_name" +key = "slot_2" +type = "Number" [[slots]] -key = "person_age" -type = "Number" -description = "Person age" +key = "slot_3" +type = "Boolean" [[hooks]] key = "hook_1" -command = ["echo", "Hello, world!"] +command = ["echo", "hook_1 output"] +optional = { default = false } [[hooks]] key = "hook_2" -command = ["touch", "2"] -optional = { default = false } +command = ["echo", "hook_2 output"] +optional = { default = true } +if = "{{hook_ran_hook_1}}" diff --git a/tests/data/proj1/subdir/bad2.txt.j2 b/tests/data/proj1/subdir/bad.j2 similarity index 100% rename from tests/data/proj1/subdir/bad2.txt.j2 rename to tests/data/proj1/subdir/bad.j2 diff --git a/tests/data/proj1/subdir/file.txt b/tests/data/proj1/subdir/file similarity index 100% rename from tests/data/proj1/subdir/file.txt rename to tests/data/proj1/subdir/file diff --git a/tests/data/proj1/subdir/test.json.j2 b/tests/data/proj1/subdir/test.json.j2 deleted file mode 100644 index e105651..0000000 --- a/tests/data/proj1/subdir/test.json.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{ - {{ person_name }} -} \ No newline at end of file diff --git a/tests/data/proj1/subdir/{{slot_1}}.j2 b/tests/data/proj1/subdir/{{slot_1}}.j2 new file mode 100644 index 0000000..d9cfdad --- /dev/null +++ b/tests/data/proj1/subdir/{{slot_1}}.j2 @@ -0,0 +1,8 @@ +{{slot_1}} +{{slot_2}} +{{slot_3}} + +Eu anim consequat est labore tempor do magna aliqua aute consectetur. +Pariatur enim commodo cillum incididunt sit dolor Lorem commodo pariatur qui quis sint occaecat officia. +Ad mollit ullamco magna non sunt sunt ad aliquip veniam incididunt veniam. +Id cillum et fugiat esse reprehenderit elit voluptate et cupidatat minim eu excepteur qui consectetur. \ No newline at end of file diff --git a/tests/data/proj1/{{file_name}}.R.j2 b/tests/data/proj1/{{file_name}}.R.j2 deleted file mode 100644 index 7cecc33..0000000 --- a/tests/data/proj1/{{file_name}}.R.j2 +++ /dev/null @@ -1,24 +0,0 @@ -# This is a sample R script - -# Printing a vector -x <- c(1, 2, 3) -print(x) - -# Defining a function -my_function <- function(a, b) { - return(a + b) -} - -# Calling the function -result <- my_function(1, 2) -print(result) - -# Creating a data frame -my_data <- data.frame( - name = c("Alice", "Bob", "Charlie", "{{ person_name }}"), - age = c(25, 30, 35, {{ person_age }}) -) - -# Printing the data frame -print(my_data) - diff --git a/tests/data/proj1/{{project_name}} b/tests/data/proj1/{{project_name}} new file mode 100644 index 0000000..9c877fe --- /dev/null +++ b/tests/data/proj1/{{project_name}} @@ -0,0 +1 @@ +{{undefined_field}} diff --git a/tests/data/proj1/{{slot_1}}.j2 b/tests/data/proj1/{{slot_1}}.j2 new file mode 100644 index 0000000..d9cfdad --- /dev/null +++ b/tests/data/proj1/{{slot_1}}.j2 @@ -0,0 +1,8 @@ +{{slot_1}} +{{slot_2}} +{{slot_3}} + +Eu anim consequat est labore tempor do magna aliqua aute consectetur. +Pariatur enim commodo cillum incididunt sit dolor Lorem commodo pariatur qui quis sint occaecat officia. +Ad mollit ullamco magna non sunt sunt ad aliquip veniam incididunt veniam. +Id cillum et fugiat esse reprehenderit elit voluptate et cupidatat minim eu excepteur qui consectetur. \ No newline at end of file diff --git a/tests/data/proj1/{{slot_2}}.j2.j2 b/tests/data/proj1/{{slot_2}}.j2.j2 new file mode 100644 index 0000000..d9cfdad --- /dev/null +++ b/tests/data/proj1/{{slot_2}}.j2.j2 @@ -0,0 +1,8 @@ +{{slot_1}} +{{slot_2}} +{{slot_3}} + +Eu anim consequat est labore tempor do magna aliqua aute consectetur. +Pariatur enim commodo cillum incididunt sit dolor Lorem commodo pariatur qui quis sint occaecat officia. +Ad mollit ullamco magna non sunt sunt ad aliquip veniam incididunt veniam. +Id cillum et fugiat esse reprehenderit elit voluptate et cupidatat minim eu excepteur qui consectetur. \ No newline at end of file diff --git a/tests/hook.rs b/tests/hook.rs index 6ca5ef9..84554ef 100644 --- a/tests/hook.rs +++ b/tests/hook.rs @@ -15,7 +15,7 @@ fn basic() { description: None, }]; - assert!(hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new()).is_ok()); + assert!(hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new(), None).is_ok()); } #[test] @@ -39,7 +39,7 @@ fn command_fail() { }, ]; - let result = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new()) + let result = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new(), None) .expect_err("run_hooks succeeded, should have failed"); match result.error { @@ -69,7 +69,7 @@ fn error_executing() { }, ]; - let result = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new()) + let result = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new(), None) .expect_err("run_hooks succeeded, should have failed"); match result.error { @@ -115,7 +115,7 @@ fn conditional() { }, ]; - let results = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new()) + let results = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new(), None) .expect("run_hooks failed, should have succeeded"); let skipped_hooks: Vec<_> = results @@ -150,7 +150,8 @@ fn bad_conditional_template() { &hooks, ".", &HashMap::from([("good_var".to_string(), "true".to_string())]), - &HashMap::new() + &HashMap::new(), + None, ) .is_err()); } @@ -170,7 +171,8 @@ fn bad_conditional_value() { &hooks, ".", &HashMap::from([("".to_string(), "".to_string())]), - &HashMap::new() + &HashMap::new(), + None, ) .is_err()); } @@ -196,7 +198,7 @@ fn optional() { }, ]; - let results = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new()).unwrap(); + let results = hook::run_hooks(&hooks, ".", &HashMap::new(), &HashMap::new(), None).unwrap(); assert!( results @@ -254,6 +256,7 @@ fn templated_cmd() { ("field_2".to_string(), "out1".to_string()), ]), &HashMap::new(), + None, ) .expect("run_hooks failed, should have succeeded"); @@ -283,6 +286,7 @@ fn invalid_templated_cmd() { ".", &HashMap::from([("field_1".to_string(), "echo".to_string())]), &HashMap::new(), + None, ) .expect_err("run_hooks succeeded, should have failed"); diff --git a/tests/template.rs b/tests/template.rs index e766509..7ec7216 100644 --- a/tests/template.rs +++ b/tests/template.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fs::remove_dir_all, path::PathBuf}; +use std::{collections::HashMap, path::PathBuf}; use spackle::core::{ slot::{Slot, SlotType}, @@ -12,7 +12,7 @@ fn fill_proj1() { let result = template::fill( &PathBuf::from("tests/data/proj1"), - &dir, + &dir.join("proj1_filled"), &HashMap::from([ ("person_name".to_string(), "Joe Bloggs".to_string()), ("person_age".to_string(), "42".to_string()), @@ -23,8 +23,6 @@ fn fill_proj1() { println!("{:?}", result); assert!(result.is_ok()); - - remove_dir_all(&dir).unwrap(); } #[test]