From 3926969188d062b8897539410a3eaf198021a8b4 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 4 Nov 2020 10:24:26 -0500 Subject: [PATCH] add twitter support --- backend/Cargo.lock | 588 ++++++++++--------------------------- backend/Cargo.toml | 2 +- backend/src/api/mod.rs | 10 +- backend/src/main.rs | 6 +- backend/src/web/mod.rs | 1 + backend/src/web/twitter.rs | 54 ++++ 6 files changed, 220 insertions(+), 441 deletions(-) create mode 100644 backend/src/web/twitter.rs diff --git a/backend/Cargo.lock b/backend/Cargo.lock index df5d986..28eb022 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -27,7 +27,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cf01b9b56e767bb57b94ebf91a58b338002963785cdd7013e21c0d4679471e4" dependencies = [ - "generic-array 0.12.3", + "generic-array", ] [[package]] @@ -62,8 +62,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" dependencies = [ "block-cipher-trait", - "byteorder", - "opaque-debug 0.2.3", + "byteorder 1.3.4", + "opaque-debug", ] [[package]] @@ -73,7 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" dependencies = [ "block-cipher-trait", - "opaque-debug 0.2.3", + "opaque-debug", ] [[package]] @@ -152,7 +152,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" dependencies = [ - "byteorder", + "byteorder 1.3.4", "safemem", ] @@ -162,7 +162,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" dependencies = [ - "byteorder", + "byteorder 1.3.4", ] [[package]] @@ -197,17 +197,8 @@ checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ "block-padding", "byte-tools", - "byteorder", - "generic-array 0.12.3", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array 0.14.4", + "byteorder 1.3.4", + "generic-array", ] [[package]] @@ -216,7 +207,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" dependencies = [ - "generic-array 0.12.3", + "generic-array", ] [[package]] @@ -240,12 +231,27 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "bytebuffer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e822a21389d388828152aeae8bb43049196b09076e2a138f53351d8cf6576cf3" +dependencies = [ + "byteorder 0.3.13", +] + [[package]] name = "bytecount" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b92204551573580e078dc80017f36a213eb77a0450e4ddd8cfa0f3f2d1f0178f" +[[package]] +name = "byteorder" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29b2aa490a8f546381308d68fc79e6bd753cd3ad839f7a7172897f1feedfa175" + [[package]] name = "byteorder" version = "1.3.4" @@ -258,7 +264,7 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" dependencies = [ - "byteorder", + "byteorder 1.3.4", "either", "iovec", ] @@ -371,7 +377,7 @@ dependencies = [ "aes-gcm", "base64 0.12.3", "hkdf", - "hmac 0.7.1", + "hmac", "percent-encoding 2.1.0", "rand 0.7.3", "sha2", @@ -449,12 +455,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" -[[package]] -name = "cpuid-bool" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" - [[package]] name = "crc32fast" version = "1.2.0" @@ -518,37 +518,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" dependencies = [ - "generic-array 0.12.3", + "generic-array", "subtle 1.0.0", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array 0.14.4", - "subtle 2.3.0", -] - [[package]] name = "data-encoding" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4d0e2d24e5ee3b23a01de38eefdcd978907890701f08ffffd4cb457ca4ee8d6" -[[package]] -name = "derive_more" -version = "0.99.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dcfabdab475c16a93d669dddfc393027803e347d09663f524447f642fbb84ba" -dependencies = [ - "proc-macro2 1.0.21", - "quote 1.0.7", - "syn 1.0.40", -] - [[package]] name = "devise" version = "0.2.0" @@ -587,7 +566,7 @@ version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2de9deab977a153492a1468d1b1c0662c1cf39e5ea87d0c060ecd59ef18d8c" dependencies = [ - "byteorder", + "byteorder 1.3.4", "chrono", "diesel_derives", "libsqlite3-sys", @@ -612,16 +591,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array 0.12.3", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.4", + "generic-array", ] [[package]] @@ -642,33 +612,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" -[[package]] -name = "egg-mode" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f877bc908325f50163ff1670a4733eabf87942511ccfd907fbef4e239c3f8aa" -dependencies = [ - "base64 0.12.3", - "chrono", - "derive_more", - "futures 0.3.5", - "hmac 0.8.1", - "hyper 0.13.7", - "hyper-tls 0.4.3", - "lazy_static", - "mime 0.3.16", - "native-tls", - "percent-encoding 2.1.0", - "rand 0.7.3", - "regex", - "serde", - "serde_json", - "sha-1 0.9.1", - "thiserror", - "tokio 0.2.22", - "url 2.1.1", -] - [[package]] name = "either" version = "1.6.0" @@ -865,6 +808,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +dependencies = [ + "matches", + "percent-encoding 2.1.0", +] + [[package]] name = "fsevent" version = "0.4.0" @@ -912,58 +865,16 @@ version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" -[[package]] -name = "futures" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" - [[package]] name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" dependencies = [ - "futures 0.1.29", + "futures", "num_cpus", ] -[[package]] -name = "futures-executor" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.5" @@ -971,51 +882,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] -name = "futures-macro" -version = "0.3.5" +name = "gcc" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" -dependencies = [ - "proc-macro-hack", - "proc-macro2 1.0.21", - "quote 1.0.7", - "syn 1.0.40", -] - -[[package]] -name = "futures-sink" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" - -[[package]] -name = "futures-task" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" -dependencies = [ - "once_cell", -] - -[[package]] -name = "futures-util" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "generic-array" @@ -1026,16 +896,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "generic-array" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" -dependencies = [ - "typenum", - "version_check 0.9.2", -] - [[package]] name = "getrandom" version = "0.1.15" @@ -1080,10 +940,10 @@ version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" dependencies = [ - "byteorder", + "byteorder 1.3.4", "bytes 0.4.12", "fnv", - "futures 0.1.29", + "futures", "http 0.1.21", "indexmap", "log 0.4.11", @@ -1092,25 +952,6 @@ dependencies = [ "tokio-io", ] -[[package]] -name = "h2" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.1", - "indexmap", - "slab", - "tokio 0.2.22", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.9.0" @@ -1138,8 +979,8 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" dependencies = [ - "digest 0.8.1", - "hmac 0.7.1", + "digest", + "hmac", ] [[package]] @@ -1148,18 +989,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" dependencies = [ - "crypto-mac 0.7.0", - "digest 0.8.1", -] - -[[package]] -name = "hmac" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" -dependencies = [ - "crypto-mac 0.8.0", - "digest 0.9.0", + "crypto-mac", + "digest", ] [[package]] @@ -1191,21 +1022,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "http 0.1.21", "tokio-buf", ] -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes 0.5.6", - "http 0.2.1", -] - [[package]] name = "httparse" version = "1.3.4" @@ -1238,11 +1059,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "futures-cpupool", - "h2 0.1.26", + "h2", "http 0.1.21", - "http-body 0.1.0", + "http-body", "httparse", "iovec", "itoa", @@ -1250,7 +1071,7 @@ dependencies = [ "net2", "rustc_version", "time 0.1.44", - "tokio 0.1.22", + "tokio", "tokio-buf", "tokio-executor", "tokio-io", @@ -1258,31 +1079,7 @@ dependencies = [ "tokio-tcp", "tokio-threadpool", "tokio-timer", - "want 0.2.0", -] - -[[package]] -name = "hyper" -version = "0.13.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" -dependencies = [ - "bytes 0.5.6", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.2.6", - "http 0.2.1", - "http-body 0.3.1", - "httparse", - "itoa", - "pin-project", - "socket2", - "time 0.1.44", - "tokio 0.2.22", - "tower-service", - "tracing", - "want 0.3.0", + "want", ] [[package]] @@ -1309,25 +1106,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "hyper 0.12.35", "native-tls", "tokio-io", ] -[[package]] -name = "hyper-tls" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" -dependencies = [ - "bytes 0.5.6", - "hyper 0.13.7", - "native-tls", - "tokio 0.2.22", - "tokio-tls", -] - [[package]] name = "idna" version = "0.1.5" @@ -1605,7 +1389,6 @@ dependencies = [ "chrono", "color-eyre", "diesel", - "egg-mode", "elefren", "futures-io", "hex", @@ -1627,6 +1410,7 @@ dependencies = [ "tracing", "tracing-log", "tracing-subscriber", + "twapi-ureq", "ureq", "uuid", ] @@ -1802,12 +1586,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.30" @@ -1987,38 +1765,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" -dependencies = [ - "proc-macro2 1.0.21", - "quote 1.0.7", - "syn 1.0.40", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.18" @@ -2047,12 +1793,6 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" -[[package]] -name = "proc-macro-nested" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" - [[package]] name = "proc-macro2" version = "0.4.30" @@ -2078,7 +1818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a336c8310f4955f343935b9c11a30254d1ad8fad98ec257a4407a061a6fd49" dependencies = [ "bitflags", - "byteorder", + "byteorder 1.3.4", "hex", "lazy_static", "libc", @@ -2161,6 +1901,16 @@ dependencies = [ "scheduled-thread-pool", ] +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + [[package]] name = "rand" version = "0.4.6" @@ -2354,7 +2104,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ - "byteorder", + "byteorder 1.3.4", "regex-syntax", ] @@ -2385,10 +2135,10 @@ dependencies = [ "cookie_store 0.7.0", "encoding_rs", "flate2", - "futures 0.1.29", + "futures", "http 0.1.21", "hyper 0.12.35", - "hyper-tls 0.3.2", + "hyper-tls", "log 0.4.11", "mime 0.3.16", "mime_guess", @@ -2397,7 +2147,7 @@ dependencies = [ "serde_json", "serde_urlencoded 0.5.5", "time 0.1.44", - "tokio 0.1.22", + "tokio", "tokio-executor", "tokio-io", "tokio-threadpool", @@ -2521,12 +2271,31 @@ dependencies = [ "rocket", ] +[[package]] +name = "rust-crypto" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +dependencies = [ + "gcc", + "libc", + "rand 0.3.23", + "rustc-serialize", + "time 0.1.44", +] + [[package]] name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + [[package]] name = "rustc_version" version = "0.2.3" @@ -2723,29 +2492,28 @@ dependencies = [ "url 2.1.1", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha-1" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", + "block-buffer", + "digest", "fake-simd", - "opaque-debug 0.2.3", -] - -[[package]] -name = "sha-1" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpuid-bool", - "digest 0.9.0", - "opaque-debug 0.3.0", + "opaque-debug", ] [[package]] @@ -2760,10 +2528,10 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", + "block-buffer", + "digest", "fake-simd", - "opaque-debug 0.2.3", + "opaque-debug", ] [[package]] @@ -2818,18 +2586,6 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" -[[package]] -name = "socket2" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi 0.3.9", -] - [[package]] name = "sodiumoxide" version = "0.2.6" @@ -3087,7 +2843,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "mio", "num_cpus", "tokio-current-thread", @@ -3099,24 +2855,6 @@ dependencies = [ "tokio-timer", ] -[[package]] -name = "tokio" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio", - "pin-project-lite", - "slab", - "tokio-macros", -] - [[package]] name = "tokio-buf" version = "0.1.1" @@ -3125,7 +2863,7 @@ checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" dependencies = [ "bytes 0.4.12", "either", - "futures 0.1.29", + "futures", ] [[package]] @@ -3134,7 +2872,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1de0e32a83f131e002238d7ccde18211c0a5397f60cbfffcb112868c2e0e20e" dependencies = [ - "futures 0.1.29", + "futures", "tokio-executor", ] @@ -3145,7 +2883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" dependencies = [ "crossbeam-utils", - "futures 0.1.29", + "futures", ] [[package]] @@ -3155,21 +2893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "log 0.4.11", ] -[[package]] -name = "tokio-macros" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" -dependencies = [ - "proc-macro2 1.0.21", - "quote 1.0.7", - "syn 1.0.40", -] - [[package]] name = "tokio-reactor" version = "0.1.12" @@ -3177,7 +2904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" dependencies = [ "crossbeam-utils", - "futures 0.1.29", + "futures", "lazy_static", "log 0.4.11", "mio", @@ -3196,7 +2923,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edfe50152bc8164fcc456dab7891fa9bf8beaf01c5ee7e1dd43a397c3cf87dee" dependencies = [ "fnv", - "futures 0.1.29", + "futures", ] [[package]] @@ -3206,7 +2933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" dependencies = [ "bytes 0.4.12", - "futures 0.1.29", + "futures", "iovec", "mio", "tokio-io", @@ -3222,7 +2949,7 @@ dependencies = [ "crossbeam-deque", "crossbeam-queue", "crossbeam-utils", - "futures 0.1.29", + "futures", "lazy_static", "log 0.4.11", "num_cpus", @@ -3237,35 +2964,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" dependencies = [ "crossbeam-utils", - "futures 0.1.29", + "futures", "slab", "tokio-executor", ] -[[package]] -name = "tokio-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" -dependencies = [ - "native-tls", - "tokio 0.2.22", -] - -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log 0.4.11", - "pin-project-lite", - "tokio 0.2.22", -] - [[package]] name = "toml" version = "0.4.10" @@ -3275,12 +2978,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tower-service" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" - [[package]] name = "tracing" version = "0.1.19" @@ -3288,7 +2985,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" dependencies = [ "cfg-if", - "log 0.4.11", "tracing-attributes", "tracing-core", ] @@ -3393,7 +3089,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfea31758bf674f990918962e8e5f07071a3161bd7c4138ed23e416e1ac4264e" dependencies = [ "base64 0.11.0", - "byteorder", + "byteorder 1.3.4", "bytes 0.5.6", "http 0.2.1", "httparse", @@ -3401,11 +3097,39 @@ dependencies = [ "log 0.4.11", "native-tls", "rand 0.7.3", - "sha-1 0.8.2", + "sha-1", "url 2.1.1", "utf-8", ] +[[package]] +name = "twapi-oauth" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8627ce44446108a6b78b02583900a443bf8e1bd3065fb2cc4faeee42e8cde3e" +dependencies = [ + "base64 0.13.0", + "chrono", + "rand 0.7.3", + "rust-crypto", + "url 2.1.1", +] + +[[package]] +name = "twapi-ureq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d9e875009b48ca15e60c667075456e9e9345c9b74161152d3db2249cf33b2ec" +dependencies = [ + "base64 0.13.0", + "bytebuffer", + "rand 0.7.3", + "serde_json", + "serde_urlencoded 0.7.0", + "twapi-oauth", + "ureq", +] + [[package]] name = "typeable" version = "0.1.2" @@ -3472,7 +3196,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df0c900f2f9b4116803415878ff48b63da9edb268668e08cf9292d7503114a01" dependencies = [ - "generic-array 0.12.3", + "generic-array", "subtle 2.3.0", ] @@ -3577,17 +3301,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" dependencies = [ - "futures 0.1.29", - "log 0.4.11", - "try-lock", -] - -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ + "futures", "log 0.4.11", "try-lock", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index d9105df..5378ceb 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] chrono = { version = "0.4", features = ["serde"] } color-eyre = "0.5" -egg-mode = "0.15" +twapi-ureq = "0.1.5" elefren = "0.22" kankyo = "0.3" log = "0.4" diff --git a/backend/src/api/mod.rs b/backend/src/api/mod.rs index 6319ccd..50f224d 100644 --- a/backend/src/api/mod.rs +++ b/backend/src/api/mod.rs @@ -7,7 +7,7 @@ use rocket::{ response::Responder, Data, Outcome::*, - Response, + Response, State, }; use rocket_contrib::json::Json; use std::io::Read; @@ -30,6 +30,14 @@ pub fn token_info(tok: paseto::Token) -> Json { Json(tok) } +#[post("/tweet", data = "")] +#[instrument(skip(tw), err)] +pub fn tweet(body: StringBody, tw: State, tok: paseto::Token) -> Result { + tw.tweet(body.unwrap())?; + + Ok(()) +} + #[derive(Debug)] pub struct StringBody(String); diff --git a/backend/src/main.rs b/backend/src/main.rs index 95cebc9..0ca789d 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -43,9 +43,10 @@ fn main() -> Result<()> { .attach(MainDatabase::fairing()) .attach(SpaceHelmet::default()) .attach(paseto::ed25519_keypair()) + .attach(web::discord_webhook::Client::fairing()) .attach(web::pluralkit::Client::fairing()) .attach(web::switchcounter::Client::fairing()) - .attach(web::discord_webhook::Client::fairing()) + .attach(web::twitter::Client::fairing()) .mount("/metrics", prometheus) .mount("/", routes![botinfo]) .mount( @@ -56,7 +57,8 @@ fn main() -> Result<()> { api::switch::list, api::switch::switch, api::get_members, - api::token_info + api::token_info, + api::tweet, ], ) .launch(); diff --git a/backend/src/web/mod.rs b/backend/src/web/mod.rs index 38d6112..a386d2d 100644 --- a/backend/src/web/mod.rs +++ b/backend/src/web/mod.rs @@ -1,6 +1,7 @@ pub mod discord_webhook; pub mod pluralkit; pub mod switchcounter; +pub mod twitter; pub type Result = std::result::Result; diff --git a/backend/src/web/twitter.rs b/backend/src/web/twitter.rs new file mode 100644 index 0000000..4d09ae6 --- /dev/null +++ b/backend/src/web/twitter.rs @@ -0,0 +1,54 @@ +use super::{Error, Result}; +use rocket::fairing::AdHoc; +use twapi_ureq::*; + +pub struct Client { + consumer_token: String, + consumer_secret: String, + api_key: String, + api_secret: String, +} + +impl Client { + pub fn fairing() -> AdHoc { + AdHoc::on_attach("Twitter client", |rocket| { + let cfg = rocket.config(); + let table = cfg.get_table("twitter").unwrap(); + let consumer_token = table["consumer_token"].as_str().unwrap().to_string(); + let consumer_secret = table["consumer_secret"].as_str().unwrap().to_string(); + let api_key = table["api_key"].as_str().unwrap().to_string(); + let api_secret = table["api_secret"].as_str().unwrap().to_string(); + + Ok(rocket.manage(Client { + consumer_token: consumer_token, + consumer_secret: consumer_secret, + api_key: api_key, + api_secret: api_secret, + })) + }) + } + + pub fn tweet(&self, body: String) -> Result<()> { + let url = "https://api.twitter.com/1.1/statuses/update.json"; + let form_options = vec![("status", body.as_str())]; + + let resp = v1::post( + url, + &vec![], + &form_options, + &self.consumer_token, + &self.consumer_secret, + &self.api_key, + &self.api_secret, + ); + + if resp.ok() { + Ok(()) + } else { + Err(match resp.synthetic_error() { + Some(why) => Error::UReq(why.to_string()), + None => Error::HttpStatus(resp.status()), + }) + } + } +}