diff --git a/Cargo.lock b/Cargo.lock index 1ee4ac3..ef734c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,15 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -64,32 +55,13 @@ checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" -dependencies = [ - "byteorder", - "safemem", -] - -[[package]] -name = "base64" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" -dependencies = [ - "byteorder", -] - [[package]] name = "base64" version = "0.21.5" @@ -110,53 +82,25 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" -version = "0.7.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "block-padding", - "byte-tools", - "byteorder", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", -] - [[package]] name = "bumpalo" version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder", - "iovec", -] - [[package]] name = "bytes" version = "1.5.0" @@ -172,12 +116,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -198,15 +136,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "core-foundation" version = "0.9.3" @@ -224,23 +153,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] -name = "crossbeam-utils" -version = "0.7.2" +name = "cpufeatures" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ - "autocfg 1.1.0", - "cfg-if 0.1.10", - "lazy_static", + "libc", ] [[package]] -name = "digest" -version = "0.8.1" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + +[[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]] @@ -249,7 +193,7 @@ version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -260,7 +204,7 @@ checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", - "log 0.4.20", + "log", "regex", "termcolor", ] @@ -275,34 +219,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", -] - -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fastrand" version = "2.0.1" @@ -336,37 +252,9 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ - "percent-encoding 2.3.0", -] - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags 1.3.2", - "fuchsia-zircon-sys", + "percent-encoding", ] -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures-channel" version = "0.3.29" @@ -417,11 +305,23 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.4" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +dependencies = [ + "cfg-if", + "libc", + "wasi", ] [[package]] @@ -436,7 +336,7 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ - "bytes 1.5.0", + "bytes", "fnv", "futures-core", "futures-sink", @@ -467,7 +367,7 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ - "bytes 1.5.0", + "bytes", "fnv", "itoa", ] @@ -478,7 +378,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes 1.5.0", + "bytes", "http", "pin-project-lite", ] @@ -501,32 +401,13 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.10.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" -dependencies = [ - "base64 0.9.3", - "httparse", - "language-tags", - "log 0.3.9", - "mime 0.2.6", - "num_cpus", - "time", - "traitobject", - "typeable", - "unicase", - "url 1.7.2", -] - [[package]] name = "hyper" version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ - "bytes 1.5.0", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -550,8 +431,8 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.5.0", - "hyper 0.14.27", + "bytes", + "hyper", "native-tls", "tokio", "tokio-native-tls", @@ -580,17 +461,6 @@ dependencies = [ "cc", ] -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -607,19 +477,10 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "ipnet" version = "2.9.0" @@ -652,22 +513,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -682,27 +527,9 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" - -[[package]] -name = "lock_api" -version = "0.3.4" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.20", -] +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "log" @@ -710,33 +537,12 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" -[[package]] -name = "mime" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -dependencies = [ - "log 0.3.9", -] - [[package]] name = "mime" version = "0.3.17" @@ -752,25 +558,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log 0.4.20", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.8.9" @@ -778,22 +565,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys", ] -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -802,7 +577,7 @@ checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", - "log 0.4.20", + "log", "openssl", "openssl-probe", "openssl-sys", @@ -812,24 +587,13 @@ dependencies = [ "tempfile", ] -[[package]] -name = "net2" -version = "0.2.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b13b648036a2339d06de780866fbdfda0dde886de7b3af2ddeba8b14f4ee34ac" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "num-traits" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -857,12 +621,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - [[package]] name = "openssl" version = "0.10.59" @@ -870,7 +628,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" dependencies = [ "bitflags 2.4.1", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -886,7 +644,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn", ] [[package]] @@ -907,38 +665,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking_lot" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" -dependencies = [ - "lock_api", - "parking_lot_core", - "rustc_version", -] - -[[package]] -name = "parking_lot_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66b810a62be75176a80873726630147a5ca780cd33921e0b5709033e66b0a" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi", - "libc", - "redox_syscall 0.1.57", - "rustc_version", - "smallvec", - "winapi 0.3.9", -] - -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" - [[package]] name = "percent-encoding" version = "2.3.0" @@ -963,145 +689,60 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.6.5" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "autocfg 0.1.8", "libc", "rand_chacha", - "rand_core 0.4.2", - "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", + "rand_core", ] [[package]] name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - -[[package]] -name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core", ] [[package]] name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.4.1" @@ -1146,23 +787,23 @@ version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64 0.21.5", - "bytes 1.5.0", + "base64", + "bytes", "encoding_rs", "futures-core", "futures-util", "h2", "http", "http-body", - "hyper 0.14.27", + "hyper", "hyper-tls", "ipnet", "js-sys", - "log 0.4.20", - "mime 0.3.17", + "log", + "mime", "native-tls", "once_cell", - "percent-encoding 2.3.0", + "percent-encoding", "pin-project-lite", "serde", "serde_json", @@ -1171,7 +812,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tower-service", - "url 2.4.1", + "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -1184,15 +825,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.21" @@ -1218,20 +850,14 @@ version = "1.0.0" dependencies = [ "chrono", "env_logger", - "failure", - "log 0.4.20", + "log", "reqwest", "serde", "serde_json", - "websocket", + "thiserror", + "tungstenite", ] -[[package]] -name = "safemem" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" - [[package]] name = "schannel" version = "0.1.22" @@ -1241,12 +867,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "security-framework" version = "2.9.2" @@ -1270,21 +890,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.192" @@ -1302,7 +907,7 @@ checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn", ] [[package]] @@ -1329,15 +934,14 @@ dependencies = [ ] [[package]] -name = "sha-1" -version = "0.8.2" +name = "sha1" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ - "block-buffer", + "cfg-if", + "cpufeatures", "digest", - "fake-simd", - "opaque-debug", ] [[package]] @@ -1346,16 +950,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ - "autocfg 1.1.0", -] - -[[package]] -name = "smallvec" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" -dependencies = [ - "maybe-uninit", + "autocfg", ] [[package]] @@ -1365,7 +960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1380,38 +975,15 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - [[package]] name = "system-configuration" version = "0.5.1" @@ -1439,9 +1011,9 @@ version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", - "redox_syscall 0.4.1", + "redox_syscall", "rustix", "windows-sys", ] @@ -1456,14 +1028,23 @@ dependencies = [ ] [[package]] -name = "time" -version = "0.1.45" +name = "thiserror" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1488,47 +1069,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ "backtrace", - "bytes 1.5.0", + "bytes", "libc", - "mio 0.8.9", + "mio", "num_cpus", "pin-project-lite", "socket2 0.5.5", "windows-sys", ] -[[package]] -name = "tokio-codec" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b2998660ba0e70d18684de5d06b70b70a3a747469af9dea7618cc59e75976b" -dependencies = [ - "bytes 0.4.12", - "futures", - "tokio-io", -] - -[[package]] -name = "tokio-executor" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" -dependencies = [ - "crossbeam-utils", - "futures", -] - -[[package]] -name = "tokio-io" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" -dependencies = [ - "bytes 0.4.12", - "futures", - "log 0.4.20", -] - [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -1539,67 +1088,13 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-reactor" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" -dependencies = [ - "crossbeam-utils", - "futures", - "lazy_static", - "log 0.4.20", - "mio 0.6.23", - "num_cpus", - "parking_lot", - "slab", - "tokio-executor", - "tokio-io", - "tokio-sync", -] - -[[package]] -name = "tokio-sync" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfe50152bc8164fcc456dab7891fa9bf8beaf01c5ee7e1dd43a397c3cf87dee" -dependencies = [ - "fnv", - "futures", -] - -[[package]] -name = "tokio-tcp" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" -dependencies = [ - "bytes 0.4.12", - "futures", - "iovec", - "mio 0.6.23", - "tokio-io", - "tokio-reactor", -] - -[[package]] -name = "tokio-tls" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" -dependencies = [ - "futures", - "native-tls", - "tokio-io", -] - [[package]] name = "tokio-util" version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ - "bytes 1.5.0", + "bytes", "futures-core", "futures-sink", "pin-project-lite", @@ -1632,12 +1127,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "traitobject" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" - [[package]] name = "try-lock" version = "0.2.4" @@ -1645,10 +1134,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] -name = "typeable" -version = "0.1.2" +name = "tungstenite" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" +checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "native-tls", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] [[package]] name = "typenum" @@ -1656,15 +1159,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "unicase" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.13" @@ -1686,23 +1180,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -dependencies = [ - "idna 0.1.5", - "matches", - "percent-encoding 1.0.1", -] - [[package]] name = "url" version = "2.4.1" @@ -1710,10 +1187,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", - "idna 0.4.0", - "percent-encoding 2.3.0", + "idna", + "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1722,9 +1205,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.1.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "want" @@ -1735,12 +1218,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1753,7 +1230,7 @@ version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -1764,11 +1241,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", - "log 0.4.20", + "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn", "wasm-bindgen-shared", ] @@ -1778,7 +1255,7 @@ version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -1802,7 +1279,7 @@ checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1823,53 +1300,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "websocket" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1aba896516545a4cea196a12c04074854ab85d53bbaf22f9b79eddadde75a2" -dependencies = [ - "bytes 0.4.12", - "futures", - "hyper 0.10.16", - "native-tls", - "rand", - "tokio-codec", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-tls", - "unicase", - "url 1.7.2", - "websocket-base", -] - -[[package]] -name = "websocket-base" -version = "0.26.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49aec794b07318993d1db16156d5a9c750120597a5ee40c6b928d416186cb138" -dependencies = [ - "base64 0.10.1", - "bitflags 1.3.2", - "byteorder", - "bytes 0.4.12", - "futures", - "native-tls", - "rand", - "sha-1", - "tokio-codec", - "tokio-io", - "tokio-tcp", - "tokio-tls", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -1880,12 +1310,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1898,7 +1322,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1988,16 +1412,6 @@ version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "windows-sys", ] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/Cargo.toml b/Cargo.toml index d01bb5b..826ad38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ repository = "https://github.com/fixstars/sacana" [dependencies] chrono = "0.4.31" env_logger = "0.10.0" -failure = "0.1.8" log = "0.4.20" reqwest = { version = "0.11.22", features = ["blocking", "json"] } serde = { version = "1.0.192", features = ["derive"] } serde_json = "1.0.108" -websocket = "0.27.0" +thiserror = "1.0.56" +tungstenite = { version = "0.20.1", features = ["native-tls"] } diff --git a/src/linux_user_manage.rs b/src/linux_user_manage.rs index aef5e79..789ebf7 100644 --- a/src/linux_user_manage.rs +++ b/src/linux_user_manage.rs @@ -1,6 +1,29 @@ use std::io::{BufRead, Write}; -use crate::runtime_error::{path_join, Result, RuntimeError}; +use crate::runtime_error::{path_join, Result}; +#[derive(thiserror::Error, Debug)] +pub enum LinuxError { + #[error("can't access {0}: {1}")] + HeadPublicKey(String, String), + #[error("get public key from {0} failed: {1}")] + GetPublicKey(String, String), + #[error("`{0}` failed. status code: {1}")] + Command(&'static str, i32), + #[error("`{0}` is killed by signal")] + CommandKilled(&'static str), + #[error("GID {0} already exists: {1}")] + GIDAlreadyExists(String, String), +} + +fn from_command_status(command: &'static str, es: std::process::ExitStatus) -> Result<()> { + if es.success() { + Ok(()) + } else if let Some(c) = es.code() { + Err(LinuxError::Command(command, c).into()) + } else { + Err(LinuxError::CommandKilled(command).into()) + } +} /// uri_format が指すuriに user_id のpublic keyが存在するかどうかを判定 fn public_keys_exist(uri_format: &str, user_id: &str) -> Result<()> { @@ -9,7 +32,7 @@ fn public_keys_exist(uri_format: &str, user_id: &str) -> Result<()> { if response.status().is_success() { Ok(()) } else { - Err(RuntimeError::new(format!("can't access {}: {}", uri, response.text()?)).into()) + Err(LinuxError::HeadPublicKey(uri, response.text()?).into()) } } @@ -20,12 +43,7 @@ fn get_public_keys(uri_format: &str, user_id: &str) -> Result { if response.status().is_success() { Ok(response.text()?) } else { - Err(RuntimeError::new(format!( - "get public key from {} failed: {}", - uri, - response.text()? - )) - .into()) + Err(LinuxError::GetPublicKey(uri, response.text()?).into()) } } @@ -43,13 +61,49 @@ fn etc_passwd(user_id: &str) -> Result> { Ok(None) } +/// 指定した gid を持つグループ名を /etc/group から探す +fn group_exist(gid: &str) -> Result> { + let file = std::fs::File::open("/etc/group")?; + for line in std::io::BufReader::new(&file).lines() { + let l = line?; + let fields = l.split(':').collect::>(); + if gid == fields[2] { + return Ok(Some(fields[0].to_owned())); + } + } + Ok(None) +} + +/// グループを作成 +fn groupadd(id: &str, name: &str) -> Result<()> { + let groupadd = std::process::Command::new("groupadd") + .arg("-g") + .arg(id) + .arg(name) + .output()?; + from_command_status("groupadd", groupadd.status) +} + +/// 引数で与えたgidを持つグループを新規に作成する +fn create_group(gid: &str, group_name: &str) -> Result<()> { + if let Some(group_name) = group_exist(gid)? { + return Err(LinuxError::GIDAlreadyExists(gid.to_owned(), group_name).into()); + } + groupadd(gid, group_name) +} + /// etc_passwdの結果からユーザーのホームディレクトリを取得 fn home_directory(passwd_line: String) -> String { passwd_line.split(':').nth(5).unwrap().to_string() } /// ユーザーを作成 -fn add_user(user_name: &str, local_host_name: &str) -> Result<()> { +fn add_user( + user_name: &str, + local_host_name: &str, + uid: Option<&str>, + gid: Option<&str>, +) -> Result<()> { if etc_passwd(user_name)?.is_some() { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, @@ -57,25 +111,21 @@ fn add_user(user_name: &str, local_host_name: &str) -> Result<()> { ) .into()); } - let useradd = std::process::Command::new("useradd") + let mut useradd = std::process::Command::new("useradd"); + useradd .arg("-m") .arg("-s") .arg("/bin/bash") .arg("-p") - .arg("") - .arg(user_name) - .output()?; - if !useradd.status.success() { - return Err(RuntimeError::new(format!( - "`useradd` failed. status code: {}", - useradd - .status - .code() - .ok_or_else(|| RuntimeError::new("`useradd` is killed by signal"))? - )) - .into()); + .arg(""); + if let Some(uid) = uid { + useradd.arg("-u").arg(uid); } - Ok(()) + if let Some(gid) = gid { + useradd.arg("-g").arg(gid); + } + let useradd = useradd.arg(user_name).output()?; + from_command_status("useradd", useradd.status) } /// user_name の $HOME に .ssh を作成し、そのパスを取得 @@ -107,32 +157,13 @@ fn set_owner_and_permission(ssh_dir: &str, user_name: &str) -> Result<()> { .arg("700") .arg(ssh_dir) .output()?; - if !chmod.status.success() { - return Err(RuntimeError::new(format!( - "`chmod` failed. status code: {}", - chmod - .status - .code() - .ok_or_else(|| RuntimeError::new("chmod is killed by signal"))? - )) - .into()); - } + from_command_status("chmod", chmod.status)?; let chown = std::process::Command::new("chown") .arg("-R") .arg(format!("{0}:{0}", user_name)) .arg(ssh_dir) .output()?; - if !chown.status.success() { - return Err(RuntimeError::new(format!( - "chown failed. status code: {}", - chown - .status - .code() - .ok_or_else(|| RuntimeError::new("chown is killed by signal"))? - )) - .into()); - } - Ok(()) + from_command_status("chown", chown.status) } /// ユーザーのauthorized_keysを更新 @@ -143,9 +174,22 @@ pub fn update_account(user_name: &str, local_host_name: &str, uri_format: &str) } /// アカウントを作成 -pub fn create_account(user_name: &str, local_host_name: &str, uri_format: &str) -> Result<()> { +pub fn create_account( + user_name: &str, + local_host_name: &str, + uri_format: &str, + uid: Option<&str>, + gid: Option<&str>, + default_group: &[String], +) -> Result<()> { public_keys_exist(uri_format, user_name)?; - add_user(user_name, local_host_name)?; + if let Some(gid) = gid { + create_group(gid, user_name)?; + } + add_user(user_name, local_host_name, uid, gid)?; + for group in default_group { + join_group(user_name, group, local_host_name)?; + } update_account(user_name, local_host_name, uri_format) } @@ -162,15 +206,5 @@ pub fn join_group(user_name: &str, group_name: &str, local_host_name: &str) -> R .arg(group_name) .arg(user_name) .output()?; - if !usermod.status.success() { - return Err(RuntimeError::new(format!( - "usermod failed. status code: {}", - usermod - .status - .code() - .ok_or_else(|| RuntimeError::new("usermod is killed by signal"))? - )) - .into()); - } - Ok(()) + from_command_status("usermod", usermod.status) } diff --git a/src/main.rs b/src/main.rs index 28fc660..c765987 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use std::io::Read; mod runtime_error; -use crate::runtime_error::{as_str, Result, RuntimeError}; +use crate::runtime_error::{as_str, Error, Result}; mod slack; use crate::slack::{ @@ -115,13 +115,10 @@ fn is_message_at_dm(mes_json: &serde_json::Value, api_token: &str, my_id: &str) } } +type WebSocket = + tungstenite::protocol::WebSocket>; /// RTMのセットアップ -fn rtm_setup( - api_token: &str, -) -> Result<( - String, - websocket::client::sync::Client>, -)> { +fn rtm_setup(api_token: &str) -> Result<(String, WebSocket)> { try_connect_to_slack_com()?; // RTM の URL を取得 let v = rtm_connect(api_token)?; @@ -133,7 +130,8 @@ fn rtm_setup( debug!("My ID is {}.", my_id); // 先ほど取得したURLでRTMのクライアントを起動 - let client = websocket::ClientBuilder::new(as_str(&v["url"])?)?.connect(None)?; + let (client, response) = tungstenite::client::connect(as_str(&v["url"])?)?; + debug!("{response:?}"); Ok((my_id, client)) } @@ -149,7 +147,7 @@ fn check_channels(api_token: &str, channel_names: &[String]) -> Result Result> { .collect() } +fn get_default_group(settings: &serde_json::Value) -> Vec { + let Some(v) = settings.get("default_group").and_then(|v| v.as_array()) else { + return Vec::new(); + }; + v.iter() + .filter_map(|v| v.as_str()) + .map(|s| s.to_owned()) + .collect() +} + const ATTRIBUTE_NUMS: usize = 6usize; fn make_hostname_field(what: &str) -> serde_json::Map { vec![ @@ -288,7 +296,7 @@ fn make_help_message( channels_names.clone() + if channels_names.is_empty() { "" } else { ", " } + &dm; make_attributes([ ( - &format!("*<@{}> create _HOSTNAME_*", my_id), + &format!("*<@{}> create _HOSTNAME_ [UID GID]*", my_id), &DescriptionOrList::Description("Creates you an account on _HOSTNAME_"), Some(&[ make_hostname_field("create your account"), @@ -336,6 +344,7 @@ struct CommandHandler { hosts: Vec, channels: Vec, users: HashMap, + default_group: Vec, my_id: String, uri_format: String, last_timestamp: Option, @@ -426,12 +435,27 @@ impl CommandHandler { ) } /// create - fn create(&self, user_id: &str, user_name: &str, channel: &str, timestamp: &str) -> Result<()> { + fn create( + &self, + user_id: &str, + user_name: &str, + channel: &str, + timestamp: &str, + uid: Option<&str>, + gid: Option<&str>, + ) -> Result<()> { self.handle_command_result( user_id, channel, timestamp, - create_account(user_name, &self.local_host_name, &self.uri_format), + create_account( + user_name, + &self.local_host_name, + &self.uri_format, + uid, + gid, + &self.default_group, + ), &format!("{} create account", user_name), "creating account is succeeded.", ) @@ -471,7 +495,7 @@ impl CommandHandler { user_id: &str, channel: &str, timestamp: &str, - hostname: Option<&&str>, + hostname: Option<&str>, ) -> Result { if self.pic_of_response { match hostname { @@ -497,7 +521,7 @@ impl CommandHandler { } } } - Ok(hostname.is_some() && hostname.unwrap() == &self.local_host_name) + Ok(hostname.is_some() && hostname.unwrap() == self.local_host_name) } fn dm(&self, mes_json: serde_json::Value) -> Result> { @@ -545,6 +569,7 @@ impl CommandHandler { let raw_message = as_str(&mes_json["text"])?; debug!("Raw message:\n{}", raw_message); let user_id = as_str(&mes_json["user"])?; + debug!("user_id = {user_id}"); let timestamp = as_str(&mes_json["ts"])?; let splitted_messages: Vec<&str> = raw_message.split_whitespace().skip(1).collect(); match (splitted_messages.first(), splitted_messages.len()) { @@ -560,17 +585,53 @@ impl CommandHandler { } (Some(&"ping"), 1) => self.ping(channel, timestamp)?, (Some(&"create"), 2) => { - if self.check_host_name(user_id, channel, timestamp, splitted_messages.last())? { - self.create(user_id, &self.users[user_id], channel, timestamp)? + if self.check_host_name( + user_id, + channel, + timestamp, + splitted_messages.last().copied(), + )? { + debug!("user_name = {}", self.users[user_id]); + self.create( + user_id, + &self.users[user_id], + channel, + timestamp, + None, + None, + )? + } + } + (Some(&"create"), 4) => { + if self.check_host_name(user_id, channel, timestamp, Some(splitted_messages[1]))? { + debug!("user_name = {}", self.users[user_id]); + self.create( + user_id, + &self.users[user_id], + channel, + timestamp, + Some(splitted_messages[2]), + Some(splitted_messages[3]), + )? } } (Some(&"update"), 2) => { - if self.check_host_name(user_id, channel, timestamp, splitted_messages.last())? { + if self.check_host_name( + user_id, + channel, + timestamp, + splitted_messages.last().copied(), + )? { self.update(user_id, &self.users[user_id], channel, timestamp)? } } (Some(&"join"), 3) => { - if self.check_host_name(user_id, channel, timestamp, splitted_messages.last())? { + if self.check_host_name( + user_id, + channel, + timestamp, + splitted_messages.last().copied(), + )? { self.join( user_id, &self.users[user_id], @@ -591,11 +652,7 @@ impl CommandHandler { match mes_type.trim_matches('"') { "message" => false, "hello" => true, - "goodbye" => { - return Err( - RuntimeError::new("goodbye event was caught. try to reconenct...").into(), - ) - } + "goodbye" => return Err(Error::CaughtGoodBye), "user_change" => { if let Some(x) = self.users.get_mut(as_str(&mes_json["user"]["id"])?) { *x = as_str(&mes_json["user"]["profile"]["display_name_normalized"])? @@ -622,7 +679,7 @@ impl CommandHandler { _ => false, } } else { - return Err(RuntimeError::new("receive non-event object on RTM").into()); + return Err(Error::NonEvent); }) } @@ -733,6 +790,7 @@ fn main() { hosts, channels: check_channels(&api_token, &channel_names).unwrap(), users: get_users(&api_token).unwrap(), + default_group: get_default_group(&settings), my_id, uri_format, last_timestamp: None, @@ -744,21 +802,22 @@ fn main() { loop { let _ = || -> Result<()> { loop { - let message = client.recv_message(); + let message = client.read(); let m = message?; trace!("Recv: {:?}", m); - use websocket::message::OwnedMessage::*; + use tungstenite::protocol::Message::*; match m { Text(s) => command_handler.on_text(s)?, Binary(_) => debug!("get binary"), Close(_) => debug!("get closure"), Ping(ping) => { debug!("Ping"); - let pong = websocket::OwnedMessage::Pong(ping); - client.send_message(&pong)?; + let pong = Pong(ping); debug!("Send {:?}", pong); + client.send(pong)?; } Pong(_) => debug!("Pong"), + Frame(x) => debug!("Frame({x:?})"), } } }() diff --git a/src/runtime_error.rs b/src/runtime_error.rs index fa1ae94..ec40e67 100644 --- a/src/runtime_error.rs +++ b/src/runtime_error.rs @@ -1,56 +1,52 @@ -pub type Result = std::result::Result; - -pub trait RuntimeErrorNewImpl { - fn new_impl(what: Self) -> RuntimeError; -} -#[derive(Debug)] -pub struct RuntimeError { - what: String, -} -impl RuntimeError { - pub fn new(what: T) -> RuntimeError { - T::new_impl(what) - } -} -impl std::error::Error for RuntimeError { - fn description(&self) -> &str { - &self.what - } -} -impl std::fmt::Display for RuntimeError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.what) - } -} -impl RuntimeErrorNewImpl for String { - fn new_impl(what: String) -> RuntimeError { - RuntimeError { what } - } -} -impl RuntimeErrorNewImpl for &str { - fn new_impl(what: &str) -> RuntimeError { - RuntimeError { - what: what.to_string(), - } - } -} - +#[derive(thiserror::Error, Debug)] +pub enum JsonError { + #[error("JSON value isn't string")] + AsStr, + #[error("JSON value isn't array")] + AsArray, +} +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Internal error: {0}")] + Json(#[from] JsonError), + #[error(transparent)] + Slack(#[from] crate::slack::SlackError), + #[error(transparent)] + Linux(#[from] crate::linux_user_manage::LinuxError), + #[error("Internal error: path -> str conversion failed")] + PathToStr, + #[error("there is no channel named {0}")] + NoChannel(String), + #[error(transparent)] + Io(#[from] std::io::Error), + #[error("Serde error: {0}")] + Serde(#[from] serde_json::Error), + #[error("Reqwest error: {0}")] + Reqwest(#[from] reqwest::Error), + #[error("chrono parse error: {0}")] + ChronoParse(#[from] chrono::ParseError), + #[error("WebSocket error: {0}")] + WebSocket(#[from] tungstenite::Error), + #[error("goodbye event was caught. try to reconenct...")] + CaughtGoodBye, + #[error("receive non-event object on RTM")] + NonEvent, +} +pub type Result = std::result::Result; /// JSON値を文字列として取得 pub fn as_str(v: &serde_json::Value) -> Result<&str> { - Ok(v.as_str() - .ok_or_else(|| RuntimeError::new("Internal error: JSON value isn't string"))?) + Ok(v.as_str().ok_or(JsonError::AsStr)?) } /// JSON値を配列として取得 pub fn as_array(v: &serde_json::Value) -> Result<&Vec> { - Ok(v.as_array() - .ok_or_else(|| RuntimeError::new("Internal error: JSON value isn't array"))?) + Ok(v.as_array().ok_or(JsonError::AsArray)?) } pub fn path_join(v: &[&str]) -> Result { Ok(v.iter() .collect::() .to_str() - .ok_or_else(|| RuntimeError::new("Internal error: path -> str conversion failed"))? + .ok_or_else(|| Error::PathToStr)? .to_string()) } diff --git a/src/slack.rs b/src/slack.rs index 4ce6abc..ebf80d8 100644 --- a/src/slack.rs +++ b/src/slack.rs @@ -2,7 +2,16 @@ use log::{debug, warn}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use crate::runtime_error::{as_array, Result, RuntimeError}; +use crate::runtime_error::{as_array, Result}; +#[derive(thiserror::Error, Debug)] +pub enum SlackError { + #[error("connecting to slack.com failed")] + ConnectFailed, + #[error("invalid conversation object")] + InvaliedConversation, + #[error("API error: users.conversations failed \"{0}\"")] + UsersConversations(String), +} fn post(api_token: &str, body: HashMap<&str, &str>, uri: &str) -> Result<()> { debug!("{:?}", body); @@ -88,7 +97,7 @@ pub fn try_connect_to_slack_com() -> Result<()> { std::thread::sleep(SLEEP_TIME); } } - Err(RuntimeError::new("connecting to slack.com failed").into()) + Err(SlackError::ConnectFailed.into()) } /// Real Time Messaging session を開始する @@ -140,7 +149,7 @@ pub fn channel_type(api_token: &str, channel: &str) -> Result { } else if let Some(true) = response["is_im"].as_bool() { ChannelType::DirectMessage } else { - return Err(RuntimeError::new("invalid conversation object").into()); + return Err(SlackError::InvaliedConversation.into()); }) } @@ -317,8 +326,7 @@ fn get_users_conversations( } UsersConversationsResponse::Err { ok, error } => { debug_assert!(!ok); - let m = format!("API error: users.conversations failed \"{error}\""); - Err(RuntimeError::new(m).into()) + Err(SlackError::UsersConversations(error).into()) } } }