diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Cargo.lock | 1277 | ||||
| -rw-r--r-- | Cargo.toml | 19 | ||||
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | TODO.md | 10 | ||||
| -rw-r--r-- | rustfmt.toml | 1 | ||||
| -rw-r--r-- | src/custom_filters.rs | 21 | ||||
| -rw-r--r-- | src/handlers.rs | 122 | ||||
| -rw-r--r-- | src/main.rs | 26 | ||||
| -rw-r--r-- | src/routes.rs | 359 | ||||
| -rw-r--r-- | src/schema.rs | 223 | ||||
| -rw-r--r-- | src/validators.rs | 44 |
12 files changed, 2118 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| /target | |||
diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c531d87 --- /dev/null +++ b/Cargo.lock | |||
| @@ -0,0 +1,1277 @@ | |||
| 1 | # This file is automatically @generated by Cargo. | ||
| 2 | # It is not intended for manual editing. | ||
| 3 | [[package]] | ||
| 4 | name = "aho-corasick" | ||
| 5 | version = "0.7.15" | ||
| 6 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 7 | checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" | ||
| 8 | dependencies = [ | ||
| 9 | "memchr", | ||
| 10 | ] | ||
| 11 | |||
| 12 | [[package]] | ||
| 13 | name = "atty" | ||
| 14 | version = "0.2.14" | ||
| 15 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 16 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" | ||
| 17 | dependencies = [ | ||
| 18 | "hermit-abi", | ||
| 19 | "libc", | ||
| 20 | "winapi 0.3.9", | ||
| 21 | ] | ||
| 22 | |||
| 23 | [[package]] | ||
| 24 | name = "autocfg" | ||
| 25 | version = "1.0.1" | ||
| 26 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 27 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" | ||
| 28 | |||
| 29 | [[package]] | ||
| 30 | name = "base64" | ||
| 31 | version = "0.12.3" | ||
| 32 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 33 | checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" | ||
| 34 | |||
| 35 | [[package]] | ||
| 36 | name = "base64" | ||
| 37 | version = "0.13.0" | ||
| 38 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 39 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" | ||
| 40 | |||
| 41 | [[package]] | ||
| 42 | name = "bitflags" | ||
| 43 | version = "1.2.1" | ||
| 44 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 45 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" | ||
| 46 | |||
| 47 | [[package]] | ||
| 48 | name = "block-buffer" | ||
| 49 | version = "0.9.0" | ||
| 50 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 51 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" | ||
| 52 | dependencies = [ | ||
| 53 | "generic-array", | ||
| 54 | ] | ||
| 55 | |||
| 56 | [[package]] | ||
| 57 | name = "buf_redux" | ||
| 58 | version = "0.8.4" | ||
| 59 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 60 | checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" | ||
| 61 | dependencies = [ | ||
| 62 | "memchr", | ||
| 63 | "safemem", | ||
| 64 | ] | ||
| 65 | |||
| 66 | [[package]] | ||
| 67 | name = "byteorder" | ||
| 68 | version = "1.4.3" | ||
| 69 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 70 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" | ||
| 71 | |||
| 72 | [[package]] | ||
| 73 | name = "bytes" | ||
| 74 | version = "0.5.6" | ||
| 75 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 76 | checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" | ||
| 77 | |||
| 78 | [[package]] | ||
| 79 | name = "bytes" | ||
| 80 | version = "1.0.1" | ||
| 81 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 82 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" | ||
| 83 | |||
| 84 | [[package]] | ||
| 85 | name = "cfg-if" | ||
| 86 | version = "0.1.10" | ||
| 87 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 88 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" | ||
| 89 | |||
| 90 | [[package]] | ||
| 91 | name = "cfg-if" | ||
| 92 | version = "1.0.0" | ||
| 93 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 94 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||
| 95 | |||
| 96 | [[package]] | ||
| 97 | name = "chrono" | ||
| 98 | version = "0.4.19" | ||
| 99 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 100 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" | ||
| 101 | dependencies = [ | ||
| 102 | "libc", | ||
| 103 | "num-integer", | ||
| 104 | "num-traits", | ||
| 105 | "serde", | ||
| 106 | "time", | ||
| 107 | "winapi 0.3.9", | ||
| 108 | ] | ||
| 109 | |||
| 110 | [[package]] | ||
| 111 | name = "cpuid-bool" | ||
| 112 | version = "0.1.2" | ||
| 113 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 114 | checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" | ||
| 115 | |||
| 116 | [[package]] | ||
| 117 | name = "digest" | ||
| 118 | version = "0.9.0" | ||
| 119 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 120 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" | ||
| 121 | dependencies = [ | ||
| 122 | "generic-array", | ||
| 123 | ] | ||
| 124 | |||
| 125 | [[package]] | ||
| 126 | name = "dtoa" | ||
| 127 | version = "0.4.8" | ||
| 128 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 129 | checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" | ||
| 130 | |||
| 131 | [[package]] | ||
| 132 | name = "env_logger" | ||
| 133 | version = "0.6.2" | ||
| 134 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 135 | checksum = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" | ||
| 136 | dependencies = [ | ||
| 137 | "atty", | ||
| 138 | "humantime", | ||
| 139 | "log", | ||
| 140 | "regex", | ||
| 141 | "termcolor", | ||
| 142 | ] | ||
| 143 | |||
| 144 | [[package]] | ||
| 145 | name = "fnv" | ||
| 146 | version = "1.0.7" | ||
| 147 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 148 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" | ||
| 149 | |||
| 150 | [[package]] | ||
| 151 | name = "form_urlencoded" | ||
| 152 | version = "1.0.1" | ||
| 153 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 154 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" | ||
| 155 | dependencies = [ | ||
| 156 | "matches", | ||
| 157 | "percent-encoding", | ||
| 158 | ] | ||
| 159 | |||
| 160 | [[package]] | ||
| 161 | name = "fuchsia-zircon" | ||
| 162 | version = "0.3.3" | ||
| 163 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 164 | checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" | ||
| 165 | dependencies = [ | ||
| 166 | "bitflags", | ||
| 167 | "fuchsia-zircon-sys", | ||
| 168 | ] | ||
| 169 | |||
| 170 | [[package]] | ||
| 171 | name = "fuchsia-zircon-sys" | ||
| 172 | version = "0.3.3" | ||
| 173 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 174 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | ||
| 175 | |||
| 176 | [[package]] | ||
| 177 | name = "futures" | ||
| 178 | version = "0.3.13" | ||
| 179 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 180 | checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" | ||
| 181 | dependencies = [ | ||
| 182 | "futures-channel", | ||
| 183 | "futures-core", | ||
| 184 | "futures-io", | ||
| 185 | "futures-sink", | ||
| 186 | "futures-task", | ||
| 187 | "futures-util", | ||
| 188 | ] | ||
| 189 | |||
| 190 | [[package]] | ||
| 191 | name = "futures-channel" | ||
| 192 | version = "0.3.13" | ||
| 193 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 194 | checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" | ||
| 195 | dependencies = [ | ||
| 196 | "futures-core", | ||
| 197 | "futures-sink", | ||
| 198 | ] | ||
| 199 | |||
| 200 | [[package]] | ||
| 201 | name = "futures-core" | ||
| 202 | version = "0.3.13" | ||
| 203 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 204 | checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" | ||
| 205 | |||
| 206 | [[package]] | ||
| 207 | name = "futures-io" | ||
| 208 | version = "0.3.13" | ||
| 209 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 210 | checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" | ||
| 211 | |||
| 212 | [[package]] | ||
| 213 | name = "futures-sink" | ||
| 214 | version = "0.3.13" | ||
| 215 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 216 | checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" | ||
| 217 | |||
| 218 | [[package]] | ||
| 219 | name = "futures-task" | ||
| 220 | version = "0.3.13" | ||
| 221 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 222 | checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" | ||
| 223 | |||
| 224 | [[package]] | ||
| 225 | name = "futures-util" | ||
| 226 | version = "0.3.13" | ||
| 227 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 228 | checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" | ||
| 229 | dependencies = [ | ||
| 230 | "futures-core", | ||
| 231 | "futures-sink", | ||
| 232 | "futures-task", | ||
| 233 | "pin-project-lite 0.2.6", | ||
| 234 | "pin-utils", | ||
| 235 | "slab", | ||
| 236 | ] | ||
| 237 | |||
| 238 | [[package]] | ||
| 239 | name = "generic-array" | ||
| 240 | version = "0.14.4" | ||
| 241 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 242 | checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" | ||
| 243 | dependencies = [ | ||
| 244 | "typenum", | ||
| 245 | "version_check", | ||
| 246 | ] | ||
| 247 | |||
| 248 | [[package]] | ||
| 249 | name = "getrandom" | ||
| 250 | version = "0.1.16" | ||
| 251 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 252 | checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" | ||
| 253 | dependencies = [ | ||
| 254 | "cfg-if 1.0.0", | ||
| 255 | "libc", | ||
| 256 | "wasi 0.9.0+wasi-snapshot-preview1", | ||
| 257 | ] | ||
| 258 | |||
| 259 | [[package]] | ||
| 260 | name = "getrandom" | ||
| 261 | version = "0.2.2" | ||
| 262 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 263 | checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" | ||
| 264 | dependencies = [ | ||
| 265 | "cfg-if 1.0.0", | ||
| 266 | "libc", | ||
| 267 | "wasi 0.10.0+wasi-snapshot-preview1", | ||
| 268 | ] | ||
| 269 | |||
| 270 | [[package]] | ||
| 271 | name = "gradecoin" | ||
| 272 | version = "0.1.0" | ||
| 273 | dependencies = [ | ||
| 274 | "chrono", | ||
| 275 | "log", | ||
| 276 | "pretty_env_logger", | ||
| 277 | "serde", | ||
| 278 | "serde_json", | ||
| 279 | "serde_test", | ||
| 280 | "tokio", | ||
| 281 | "warp", | ||
| 282 | ] | ||
| 283 | |||
| 284 | [[package]] | ||
| 285 | name = "h2" | ||
| 286 | version = "0.2.7" | ||
| 287 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 288 | checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" | ||
| 289 | dependencies = [ | ||
| 290 | "bytes 0.5.6", | ||
| 291 | "fnv", | ||
| 292 | "futures-core", | ||
| 293 | "futures-sink", | ||
| 294 | "futures-util", | ||
| 295 | "http", | ||
| 296 | "indexmap", | ||
| 297 | "slab", | ||
| 298 | "tokio", | ||
| 299 | "tokio-util", | ||
| 300 | "tracing", | ||
| 301 | "tracing-futures", | ||
| 302 | ] | ||
| 303 | |||
| 304 | [[package]] | ||
| 305 | name = "hashbrown" | ||
| 306 | version = "0.9.1" | ||
| 307 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 308 | checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" | ||
| 309 | |||
| 310 | [[package]] | ||
| 311 | name = "headers" | ||
| 312 | version = "0.3.4" | ||
| 313 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 314 | checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" | ||
| 315 | dependencies = [ | ||
| 316 | "base64 0.13.0", | ||
| 317 | "bitflags", | ||
| 318 | "bytes 1.0.1", | ||
| 319 | "headers-core", | ||
| 320 | "http", | ||
| 321 | "mime", | ||
| 322 | "sha-1", | ||
| 323 | "time", | ||
| 324 | ] | ||
| 325 | |||
| 326 | [[package]] | ||
| 327 | name = "headers-core" | ||
| 328 | version = "0.2.0" | ||
| 329 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 330 | checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" | ||
| 331 | dependencies = [ | ||
| 332 | "http", | ||
| 333 | ] | ||
| 334 | |||
| 335 | [[package]] | ||
| 336 | name = "hermit-abi" | ||
| 337 | version = "0.1.18" | ||
| 338 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 339 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" | ||
| 340 | dependencies = [ | ||
| 341 | "libc", | ||
| 342 | ] | ||
| 343 | |||
| 344 | [[package]] | ||
| 345 | name = "http" | ||
| 346 | version = "0.2.3" | ||
| 347 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 348 | checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" | ||
| 349 | dependencies = [ | ||
| 350 | "bytes 1.0.1", | ||
| 351 | "fnv", | ||
| 352 | "itoa", | ||
| 353 | ] | ||
| 354 | |||
| 355 | [[package]] | ||
| 356 | name = "http-body" | ||
| 357 | version = "0.3.1" | ||
| 358 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 359 | checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" | ||
| 360 | dependencies = [ | ||
| 361 | "bytes 0.5.6", | ||
| 362 | "http", | ||
| 363 | ] | ||
| 364 | |||
| 365 | [[package]] | ||
| 366 | name = "httparse" | ||
| 367 | version = "1.3.5" | ||
| 368 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 369 | checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" | ||
| 370 | |||
| 371 | [[package]] | ||
| 372 | name = "httpdate" | ||
| 373 | version = "0.3.2" | ||
| 374 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 375 | checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" | ||
| 376 | |||
| 377 | [[package]] | ||
| 378 | name = "humantime" | ||
| 379 | version = "1.3.0" | ||
| 380 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 381 | checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" | ||
| 382 | dependencies = [ | ||
| 383 | "quick-error", | ||
| 384 | ] | ||
| 385 | |||
| 386 | [[package]] | ||
| 387 | name = "hyper" | ||
| 388 | version = "0.13.10" | ||
| 389 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 390 | checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" | ||
| 391 | dependencies = [ | ||
| 392 | "bytes 0.5.6", | ||
| 393 | "futures-channel", | ||
| 394 | "futures-core", | ||
| 395 | "futures-util", | ||
| 396 | "h2", | ||
| 397 | "http", | ||
| 398 | "http-body", | ||
| 399 | "httparse", | ||
| 400 | "httpdate", | ||
| 401 | "itoa", | ||
| 402 | "pin-project 1.0.6", | ||
| 403 | "socket2", | ||
| 404 | "tokio", | ||
| 405 | "tower-service", | ||
| 406 | "tracing", | ||
| 407 | "want", | ||
| 408 | ] | ||
| 409 | |||
| 410 | [[package]] | ||
| 411 | name = "idna" | ||
| 412 | version = "0.2.2" | ||
| 413 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 414 | checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" | ||
| 415 | dependencies = [ | ||
| 416 | "matches", | ||
| 417 | "unicode-bidi", | ||
| 418 | "unicode-normalization", | ||
| 419 | ] | ||
| 420 | |||
| 421 | [[package]] | ||
| 422 | name = "indexmap" | ||
| 423 | version = "1.6.2" | ||
| 424 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 425 | checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" | ||
| 426 | dependencies = [ | ||
| 427 | "autocfg", | ||
| 428 | "hashbrown", | ||
| 429 | ] | ||
| 430 | |||
| 431 | [[package]] | ||
| 432 | name = "input_buffer" | ||
| 433 | version = "0.3.1" | ||
| 434 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 435 | checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" | ||
| 436 | dependencies = [ | ||
| 437 | "bytes 0.5.6", | ||
| 438 | ] | ||
| 439 | |||
| 440 | [[package]] | ||
| 441 | name = "iovec" | ||
| 442 | version = "0.1.4" | ||
| 443 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 444 | checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" | ||
| 445 | dependencies = [ | ||
| 446 | "libc", | ||
| 447 | ] | ||
| 448 | |||
| 449 | [[package]] | ||
| 450 | name = "itoa" | ||
| 451 | version = "0.4.7" | ||
| 452 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 453 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" | ||
| 454 | |||
| 455 | [[package]] | ||
| 456 | name = "kernel32-sys" | ||
| 457 | version = "0.2.2" | ||
| 458 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 459 | checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" | ||
| 460 | dependencies = [ | ||
| 461 | "winapi 0.2.8", | ||
| 462 | "winapi-build", | ||
| 463 | ] | ||
| 464 | |||
| 465 | [[package]] | ||
| 466 | name = "lazy_static" | ||
| 467 | version = "1.4.0" | ||
| 468 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 469 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" | ||
| 470 | |||
| 471 | [[package]] | ||
| 472 | name = "libc" | ||
| 473 | version = "0.2.93" | ||
| 474 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 475 | checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" | ||
| 476 | |||
| 477 | [[package]] | ||
| 478 | name = "log" | ||
| 479 | version = "0.4.14" | ||
| 480 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 481 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" | ||
| 482 | dependencies = [ | ||
| 483 | "cfg-if 1.0.0", | ||
| 484 | ] | ||
| 485 | |||
| 486 | [[package]] | ||
| 487 | name = "matches" | ||
| 488 | version = "0.1.8" | ||
| 489 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 490 | checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" | ||
| 491 | |||
| 492 | [[package]] | ||
| 493 | name = "memchr" | ||
| 494 | version = "2.3.4" | ||
| 495 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 496 | checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" | ||
| 497 | |||
| 498 | [[package]] | ||
| 499 | name = "mime" | ||
| 500 | version = "0.3.16" | ||
| 501 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 502 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" | ||
| 503 | |||
| 504 | [[package]] | ||
| 505 | name = "mime_guess" | ||
| 506 | version = "2.0.3" | ||
| 507 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 508 | checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" | ||
| 509 | dependencies = [ | ||
| 510 | "mime", | ||
| 511 | "unicase", | ||
| 512 | ] | ||
| 513 | |||
| 514 | [[package]] | ||
| 515 | name = "mio" | ||
| 516 | version = "0.6.23" | ||
| 517 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 518 | checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" | ||
| 519 | dependencies = [ | ||
| 520 | "cfg-if 0.1.10", | ||
| 521 | "fuchsia-zircon", | ||
| 522 | "fuchsia-zircon-sys", | ||
| 523 | "iovec", | ||
| 524 | "kernel32-sys", | ||
| 525 | "libc", | ||
| 526 | "log", | ||
| 527 | "miow", | ||
| 528 | "net2", | ||
| 529 | "slab", | ||
| 530 | "winapi 0.2.8", | ||
| 531 | ] | ||
| 532 | |||
| 533 | [[package]] | ||
| 534 | name = "miow" | ||
| 535 | version = "0.2.2" | ||
| 536 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 537 | checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" | ||
| 538 | dependencies = [ | ||
| 539 | "kernel32-sys", | ||
| 540 | "net2", | ||
| 541 | "winapi 0.2.8", | ||
| 542 | "ws2_32-sys", | ||
| 543 | ] | ||
| 544 | |||
| 545 | [[package]] | ||
| 546 | name = "multipart" | ||
| 547 | version = "0.17.1" | ||
| 548 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 549 | checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" | ||
| 550 | dependencies = [ | ||
| 551 | "buf_redux", | ||
| 552 | "httparse", | ||
| 553 | "log", | ||
| 554 | "mime", | ||
| 555 | "mime_guess", | ||
| 556 | "quick-error", | ||
| 557 | "rand 0.7.3", | ||
| 558 | "safemem", | ||
| 559 | "tempfile", | ||
| 560 | "twoway", | ||
| 561 | ] | ||
| 562 | |||
| 563 | [[package]] | ||
| 564 | name = "net2" | ||
| 565 | version = "0.2.37" | ||
| 566 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 567 | checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" | ||
| 568 | dependencies = [ | ||
| 569 | "cfg-if 0.1.10", | ||
| 570 | "libc", | ||
| 571 | "winapi 0.3.9", | ||
| 572 | ] | ||
| 573 | |||
| 574 | [[package]] | ||
| 575 | name = "num-integer" | ||
| 576 | version = "0.1.44" | ||
| 577 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 578 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" | ||
| 579 | dependencies = [ | ||
| 580 | "autocfg", | ||
| 581 | "num-traits", | ||
| 582 | ] | ||
| 583 | |||
| 584 | [[package]] | ||
| 585 | name = "num-traits" | ||
| 586 | version = "0.2.14" | ||
| 587 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 588 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" | ||
| 589 | dependencies = [ | ||
| 590 | "autocfg", | ||
| 591 | ] | ||
| 592 | |||
| 593 | [[package]] | ||
| 594 | name = "opaque-debug" | ||
| 595 | version = "0.3.0" | ||
| 596 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 597 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" | ||
| 598 | |||
| 599 | [[package]] | ||
| 600 | name = "percent-encoding" | ||
| 601 | version = "2.1.0" | ||
| 602 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 603 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" | ||
| 604 | |||
| 605 | [[package]] | ||
| 606 | name = "pin-project" | ||
| 607 | version = "0.4.28" | ||
| 608 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 609 | checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f" | ||
| 610 | dependencies = [ | ||
| 611 | "pin-project-internal 0.4.28", | ||
| 612 | ] | ||
| 613 | |||
| 614 | [[package]] | ||
| 615 | name = "pin-project" | ||
| 616 | version = "1.0.6" | ||
| 617 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 618 | checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" | ||
| 619 | dependencies = [ | ||
| 620 | "pin-project-internal 1.0.6", | ||
| 621 | ] | ||
| 622 | |||
| 623 | [[package]] | ||
| 624 | name = "pin-project-internal" | ||
| 625 | version = "0.4.28" | ||
| 626 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 627 | checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e" | ||
| 628 | dependencies = [ | ||
| 629 | "proc-macro2", | ||
| 630 | "quote", | ||
| 631 | "syn", | ||
| 632 | ] | ||
| 633 | |||
| 634 | [[package]] | ||
| 635 | name = "pin-project-internal" | ||
| 636 | version = "1.0.6" | ||
| 637 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 638 | checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" | ||
| 639 | dependencies = [ | ||
| 640 | "proc-macro2", | ||
| 641 | "quote", | ||
| 642 | "syn", | ||
| 643 | ] | ||
| 644 | |||
| 645 | [[package]] | ||
| 646 | name = "pin-project-lite" | ||
| 647 | version = "0.1.12" | ||
| 648 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 649 | checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" | ||
| 650 | |||
| 651 | [[package]] | ||
| 652 | name = "pin-project-lite" | ||
| 653 | version = "0.2.6" | ||
| 654 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 655 | checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" | ||
| 656 | |||
| 657 | [[package]] | ||
| 658 | name = "pin-utils" | ||
| 659 | version = "0.1.0" | ||
| 660 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 661 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" | ||
| 662 | |||
| 663 | [[package]] | ||
| 664 | name = "ppv-lite86" | ||
| 665 | version = "0.2.10" | ||
| 666 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 667 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" | ||
| 668 | |||
| 669 | [[package]] | ||
| 670 | name = "pretty_env_logger" | ||
| 671 | version = "0.3.1" | ||
| 672 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 673 | checksum = "717ee476b1690853d222af4634056d830b5197ffd747726a9a1eee6da9f49074" | ||
| 674 | dependencies = [ | ||
| 675 | "chrono", | ||
| 676 | "env_logger", | ||
| 677 | "log", | ||
| 678 | ] | ||
| 679 | |||
| 680 | [[package]] | ||
| 681 | name = "proc-macro2" | ||
| 682 | version = "1.0.26" | ||
| 683 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 684 | checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" | ||
| 685 | dependencies = [ | ||
| 686 | "unicode-xid", | ||
| 687 | ] | ||
| 688 | |||
| 689 | [[package]] | ||
| 690 | name = "quick-error" | ||
| 691 | version = "1.2.3" | ||
| 692 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 693 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" | ||
| 694 | |||
| 695 | [[package]] | ||
| 696 | name = "quote" | ||
| 697 | version = "1.0.9" | ||
| 698 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 699 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" | ||
| 700 | dependencies = [ | ||
| 701 | "proc-macro2", | ||
| 702 | ] | ||
| 703 | |||
| 704 | [[package]] | ||
| 705 | name = "rand" | ||
| 706 | version = "0.7.3" | ||
| 707 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 708 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" | ||
| 709 | dependencies = [ | ||
| 710 | "getrandom 0.1.16", | ||
| 711 | "libc", | ||
| 712 | "rand_chacha 0.2.2", | ||
| 713 | "rand_core 0.5.1", | ||
| 714 | "rand_hc 0.2.0", | ||
| 715 | ] | ||
| 716 | |||
| 717 | [[package]] | ||
| 718 | name = "rand" | ||
| 719 | version = "0.8.3" | ||
| 720 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 721 | checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" | ||
| 722 | dependencies = [ | ||
| 723 | "libc", | ||
| 724 | "rand_chacha 0.3.0", | ||
| 725 | "rand_core 0.6.2", | ||
| 726 | "rand_hc 0.3.0", | ||
| 727 | ] | ||
| 728 | |||
| 729 | [[package]] | ||
| 730 | name = "rand_chacha" | ||
| 731 | version = "0.2.2" | ||
| 732 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 733 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" | ||
| 734 | dependencies = [ | ||
| 735 | "ppv-lite86", | ||
| 736 | "rand_core 0.5.1", | ||
| 737 | ] | ||
| 738 | |||
| 739 | [[package]] | ||
| 740 | name = "rand_chacha" | ||
| 741 | version = "0.3.0" | ||
| 742 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 743 | checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" | ||
| 744 | dependencies = [ | ||
| 745 | "ppv-lite86", | ||
| 746 | "rand_core 0.6.2", | ||
| 747 | ] | ||
| 748 | |||
| 749 | [[package]] | ||
| 750 | name = "rand_core" | ||
| 751 | version = "0.5.1" | ||
| 752 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 753 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" | ||
| 754 | dependencies = [ | ||
| 755 | "getrandom 0.1.16", | ||
| 756 | ] | ||
| 757 | |||
| 758 | [[package]] | ||
| 759 | name = "rand_core" | ||
| 760 | version = "0.6.2" | ||
| 761 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 762 | checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" | ||
| 763 | dependencies = [ | ||
| 764 | "getrandom 0.2.2", | ||
| 765 | ] | ||
| 766 | |||
| 767 | [[package]] | ||
| 768 | name = "rand_hc" | ||
| 769 | version = "0.2.0" | ||
| 770 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 771 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" | ||
| 772 | dependencies = [ | ||
| 773 | "rand_core 0.5.1", | ||
| 774 | ] | ||
| 775 | |||
| 776 | [[package]] | ||
| 777 | name = "rand_hc" | ||
| 778 | version = "0.3.0" | ||
| 779 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 780 | checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" | ||
| 781 | dependencies = [ | ||
| 782 | "rand_core 0.6.2", | ||
| 783 | ] | ||
| 784 | |||
| 785 | [[package]] | ||
| 786 | name = "redox_syscall" | ||
| 787 | version = "0.2.5" | ||
| 788 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 789 | checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" | ||
| 790 | dependencies = [ | ||
| 791 | "bitflags", | ||
| 792 | ] | ||
| 793 | |||
| 794 | [[package]] | ||
| 795 | name = "regex" | ||
| 796 | version = "1.4.5" | ||
| 797 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 798 | checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" | ||
| 799 | dependencies = [ | ||
| 800 | "aho-corasick", | ||
| 801 | "memchr", | ||
| 802 | "regex-syntax", | ||
| 803 | ] | ||
| 804 | |||
| 805 | [[package]] | ||
| 806 | name = "regex-syntax" | ||
| 807 | version = "0.6.23" | ||
| 808 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 809 | checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" | ||
| 810 | |||
| 811 | [[package]] | ||
| 812 | name = "remove_dir_all" | ||
| 813 | version = "0.5.3" | ||
| 814 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 815 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" | ||
| 816 | dependencies = [ | ||
| 817 | "winapi 0.3.9", | ||
| 818 | ] | ||
| 819 | |||
| 820 | [[package]] | ||
| 821 | name = "ryu" | ||
| 822 | version = "1.0.5" | ||
| 823 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 824 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" | ||
| 825 | |||
| 826 | [[package]] | ||
| 827 | name = "safemem" | ||
| 828 | version = "0.3.3" | ||
| 829 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 830 | checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" | ||
| 831 | |||
| 832 | [[package]] | ||
| 833 | name = "scoped-tls" | ||
| 834 | version = "1.0.0" | ||
| 835 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 836 | checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" | ||
| 837 | |||
| 838 | [[package]] | ||
| 839 | name = "serde" | ||
| 840 | version = "1.0.125" | ||
| 841 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 842 | checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" | ||
| 843 | dependencies = [ | ||
| 844 | "serde_derive", | ||
| 845 | ] | ||
| 846 | |||
| 847 | [[package]] | ||
| 848 | name = "serde_derive" | ||
| 849 | version = "1.0.125" | ||
| 850 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 851 | checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" | ||
| 852 | dependencies = [ | ||
| 853 | "proc-macro2", | ||
| 854 | "quote", | ||
| 855 | "syn", | ||
| 856 | ] | ||
| 857 | |||
| 858 | [[package]] | ||
| 859 | name = "serde_json" | ||
| 860 | version = "1.0.64" | ||
| 861 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 862 | checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" | ||
| 863 | dependencies = [ | ||
| 864 | "itoa", | ||
| 865 | "ryu", | ||
| 866 | "serde", | ||
| 867 | ] | ||
| 868 | |||
| 869 | [[package]] | ||
| 870 | name = "serde_test" | ||
| 871 | version = "1.0.125" | ||
| 872 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 873 | checksum = "b4bb5fef7eaf5a97917567183607ac4224c5b451c15023930f23b937cce879fe" | ||
| 874 | dependencies = [ | ||
| 875 | "serde", | ||
| 876 | ] | ||
| 877 | |||
| 878 | [[package]] | ||
| 879 | name = "serde_urlencoded" | ||
| 880 | version = "0.6.1" | ||
| 881 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 882 | checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" | ||
| 883 | dependencies = [ | ||
| 884 | "dtoa", | ||
| 885 | "itoa", | ||
| 886 | "serde", | ||
| 887 | "url", | ||
| 888 | ] | ||
| 889 | |||
| 890 | [[package]] | ||
| 891 | name = "sha-1" | ||
| 892 | version = "0.9.4" | ||
| 893 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 894 | checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" | ||
| 895 | dependencies = [ | ||
| 896 | "block-buffer", | ||
| 897 | "cfg-if 1.0.0", | ||
| 898 | "cpuid-bool", | ||
| 899 | "digest", | ||
| 900 | "opaque-debug", | ||
| 901 | ] | ||
| 902 | |||
| 903 | [[package]] | ||
| 904 | name = "slab" | ||
| 905 | version = "0.4.2" | ||
| 906 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 907 | checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" | ||
| 908 | |||
| 909 | [[package]] | ||
| 910 | name = "socket2" | ||
| 911 | version = "0.3.19" | ||
| 912 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 913 | checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" | ||
| 914 | dependencies = [ | ||
| 915 | "cfg-if 1.0.0", | ||
| 916 | "libc", | ||
| 917 | "winapi 0.3.9", | ||
| 918 | ] | ||
| 919 | |||
| 920 | [[package]] | ||
| 921 | name = "syn" | ||
| 922 | version = "1.0.68" | ||
| 923 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 924 | checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" | ||
| 925 | dependencies = [ | ||
| 926 | "proc-macro2", | ||
| 927 | "quote", | ||
| 928 | "unicode-xid", | ||
| 929 | ] | ||
| 930 | |||
| 931 | [[package]] | ||
| 932 | name = "tempfile" | ||
| 933 | version = "3.2.0" | ||
| 934 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 935 | checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" | ||
| 936 | dependencies = [ | ||
| 937 | "cfg-if 1.0.0", | ||
| 938 | "libc", | ||
| 939 | "rand 0.8.3", | ||
| 940 | "redox_syscall", | ||
| 941 | "remove_dir_all", | ||
| 942 | "winapi 0.3.9", | ||
| 943 | ] | ||
| 944 | |||
| 945 | [[package]] | ||
| 946 | name = "termcolor" | ||
| 947 | version = "1.1.2" | ||
| 948 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 949 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" | ||
| 950 | dependencies = [ | ||
| 951 | "winapi-util", | ||
| 952 | ] | ||
| 953 | |||
| 954 | [[package]] | ||
| 955 | name = "time" | ||
| 956 | version = "0.1.44" | ||
| 957 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 958 | checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" | ||
| 959 | dependencies = [ | ||
| 960 | "libc", | ||
| 961 | "wasi 0.10.0+wasi-snapshot-preview1", | ||
| 962 | "winapi 0.3.9", | ||
| 963 | ] | ||
| 964 | |||
| 965 | [[package]] | ||
| 966 | name = "tinyvec" | ||
| 967 | version = "1.2.0" | ||
| 968 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 969 | checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" | ||
| 970 | dependencies = [ | ||
| 971 | "tinyvec_macros", | ||
| 972 | ] | ||
| 973 | |||
| 974 | [[package]] | ||
| 975 | name = "tinyvec_macros" | ||
| 976 | version = "0.1.0" | ||
| 977 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 978 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" | ||
| 979 | |||
| 980 | [[package]] | ||
| 981 | name = "tokio" | ||
| 982 | version = "0.2.25" | ||
| 983 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 984 | checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" | ||
| 985 | dependencies = [ | ||
| 986 | "bytes 0.5.6", | ||
| 987 | "fnv", | ||
| 988 | "futures-core", | ||
| 989 | "iovec", | ||
| 990 | "lazy_static", | ||
| 991 | "memchr", | ||
| 992 | "mio", | ||
| 993 | "pin-project-lite 0.1.12", | ||
| 994 | "slab", | ||
| 995 | "tokio-macros", | ||
| 996 | ] | ||
| 997 | |||
| 998 | [[package]] | ||
| 999 | name = "tokio-macros" | ||
| 1000 | version = "0.2.6" | ||
| 1001 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1002 | checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" | ||
| 1003 | dependencies = [ | ||
| 1004 | "proc-macro2", | ||
| 1005 | "quote", | ||
| 1006 | "syn", | ||
| 1007 | ] | ||
| 1008 | |||
| 1009 | [[package]] | ||
| 1010 | name = "tokio-tungstenite" | ||
| 1011 | version = "0.11.0" | ||
| 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1013 | checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" | ||
| 1014 | dependencies = [ | ||
| 1015 | "futures-util", | ||
| 1016 | "log", | ||
| 1017 | "pin-project 0.4.28", | ||
| 1018 | "tokio", | ||
| 1019 | "tungstenite", | ||
| 1020 | ] | ||
| 1021 | |||
| 1022 | [[package]] | ||
| 1023 | name = "tokio-util" | ||
| 1024 | version = "0.3.1" | ||
| 1025 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1026 | checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" | ||
| 1027 | dependencies = [ | ||
| 1028 | "bytes 0.5.6", | ||
| 1029 | "futures-core", | ||
| 1030 | "futures-sink", | ||
| 1031 | "log", | ||
| 1032 | "pin-project-lite 0.1.12", | ||
| 1033 | "tokio", | ||
| 1034 | ] | ||
| 1035 | |||
| 1036 | [[package]] | ||
| 1037 | name = "tower-service" | ||
| 1038 | version = "0.3.1" | ||
| 1039 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1040 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" | ||
| 1041 | |||
| 1042 | [[package]] | ||
| 1043 | name = "tracing" | ||
| 1044 | version = "0.1.25" | ||
| 1045 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1046 | checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" | ||
| 1047 | dependencies = [ | ||
| 1048 | "cfg-if 1.0.0", | ||
| 1049 | "log", | ||
| 1050 | "pin-project-lite 0.2.6", | ||
| 1051 | "tracing-core", | ||
| 1052 | ] | ||
| 1053 | |||
| 1054 | [[package]] | ||
| 1055 | name = "tracing-core" | ||
| 1056 | version = "0.1.17" | ||
| 1057 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1058 | checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" | ||
| 1059 | dependencies = [ | ||
| 1060 | "lazy_static", | ||
| 1061 | ] | ||
| 1062 | |||
| 1063 | [[package]] | ||
| 1064 | name = "tracing-futures" | ||
| 1065 | version = "0.2.5" | ||
| 1066 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1067 | checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" | ||
| 1068 | dependencies = [ | ||
| 1069 | "pin-project 1.0.6", | ||
| 1070 | "tracing", | ||
| 1071 | ] | ||
| 1072 | |||
| 1073 | [[package]] | ||
| 1074 | name = "try-lock" | ||
| 1075 | version = "0.2.3" | ||
| 1076 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1077 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | ||
| 1078 | |||
| 1079 | [[package]] | ||
| 1080 | name = "tungstenite" | ||
| 1081 | version = "0.11.1" | ||
| 1082 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1083 | checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" | ||
| 1084 | dependencies = [ | ||
| 1085 | "base64 0.12.3", | ||
| 1086 | "byteorder", | ||
| 1087 | "bytes 0.5.6", | ||
| 1088 | "http", | ||
| 1089 | "httparse", | ||
| 1090 | "input_buffer", | ||
| 1091 | "log", | ||
| 1092 | "rand 0.7.3", | ||
| 1093 | "sha-1", | ||
| 1094 | "url", | ||
| 1095 | "utf-8", | ||
| 1096 | ] | ||
| 1097 | |||
| 1098 | [[package]] | ||
| 1099 | name = "twoway" | ||
| 1100 | version = "0.1.8" | ||
| 1101 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1102 | checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" | ||
| 1103 | dependencies = [ | ||
| 1104 | "memchr", | ||
| 1105 | ] | ||
| 1106 | |||
| 1107 | [[package]] | ||
| 1108 | name = "typenum" | ||
| 1109 | version = "1.13.0" | ||
| 1110 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1111 | checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" | ||
| 1112 | |||
| 1113 | [[package]] | ||
| 1114 | name = "unicase" | ||
| 1115 | version = "2.6.0" | ||
| 1116 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1117 | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" | ||
| 1118 | dependencies = [ | ||
| 1119 | "version_check", | ||
| 1120 | ] | ||
| 1121 | |||
| 1122 | [[package]] | ||
| 1123 | name = "unicode-bidi" | ||
| 1124 | version = "0.3.5" | ||
| 1125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1126 | checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" | ||
| 1127 | dependencies = [ | ||
| 1128 | "matches", | ||
| 1129 | ] | ||
| 1130 | |||
| 1131 | [[package]] | ||
| 1132 | name = "unicode-normalization" | ||
| 1133 | version = "0.1.17" | ||
| 1134 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1135 | checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" | ||
| 1136 | dependencies = [ | ||
| 1137 | "tinyvec", | ||
| 1138 | ] | ||
| 1139 | |||
| 1140 | [[package]] | ||
| 1141 | name = "unicode-xid" | ||
| 1142 | version = "0.2.1" | ||
| 1143 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1144 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" | ||
| 1145 | |||
| 1146 | [[package]] | ||
| 1147 | name = "url" | ||
| 1148 | version = "2.2.1" | ||
| 1149 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1150 | checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" | ||
| 1151 | dependencies = [ | ||
| 1152 | "form_urlencoded", | ||
| 1153 | "idna", | ||
| 1154 | "matches", | ||
| 1155 | "percent-encoding", | ||
| 1156 | ] | ||
| 1157 | |||
| 1158 | [[package]] | ||
| 1159 | name = "urlencoding" | ||
| 1160 | version = "1.1.1" | ||
| 1161 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1162 | checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593" | ||
| 1163 | |||
| 1164 | [[package]] | ||
| 1165 | name = "utf-8" | ||
| 1166 | version = "0.7.5" | ||
| 1167 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1168 | checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" | ||
| 1169 | |||
| 1170 | [[package]] | ||
| 1171 | name = "version_check" | ||
| 1172 | version = "0.9.3" | ||
| 1173 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1174 | checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" | ||
| 1175 | |||
| 1176 | [[package]] | ||
| 1177 | name = "want" | ||
| 1178 | version = "0.3.0" | ||
| 1179 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1180 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" | ||
| 1181 | dependencies = [ | ||
| 1182 | "log", | ||
| 1183 | "try-lock", | ||
| 1184 | ] | ||
| 1185 | |||
| 1186 | [[package]] | ||
| 1187 | name = "warp" | ||
| 1188 | version = "0.2.5" | ||
| 1189 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1190 | checksum = "f41be6df54c97904af01aa23e613d4521eed7ab23537cede692d4058f6449407" | ||
| 1191 | dependencies = [ | ||
| 1192 | "bytes 0.5.6", | ||
| 1193 | "futures", | ||
| 1194 | "headers", | ||
| 1195 | "http", | ||
| 1196 | "hyper", | ||
| 1197 | "log", | ||
| 1198 | "mime", | ||
| 1199 | "mime_guess", | ||
| 1200 | "multipart", | ||
| 1201 | "pin-project 0.4.28", | ||
| 1202 | "scoped-tls", | ||
| 1203 | "serde", | ||
| 1204 | "serde_json", | ||
| 1205 | "serde_urlencoded", | ||
| 1206 | "tokio", | ||
| 1207 | "tokio-tungstenite", | ||
| 1208 | "tower-service", | ||
| 1209 | "tracing", | ||
| 1210 | "tracing-futures", | ||
| 1211 | "urlencoding", | ||
| 1212 | ] | ||
| 1213 | |||
| 1214 | [[package]] | ||
| 1215 | name = "wasi" | ||
| 1216 | version = "0.9.0+wasi-snapshot-preview1" | ||
| 1217 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1218 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" | ||
| 1219 | |||
| 1220 | [[package]] | ||
| 1221 | name = "wasi" | ||
| 1222 | version = "0.10.0+wasi-snapshot-preview1" | ||
| 1223 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1224 | checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" | ||
| 1225 | |||
| 1226 | [[package]] | ||
| 1227 | name = "winapi" | ||
| 1228 | version = "0.2.8" | ||
| 1229 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1230 | checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" | ||
| 1231 | |||
| 1232 | [[package]] | ||
| 1233 | name = "winapi" | ||
| 1234 | version = "0.3.9" | ||
| 1235 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1236 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | ||
| 1237 | dependencies = [ | ||
| 1238 | "winapi-i686-pc-windows-gnu", | ||
| 1239 | "winapi-x86_64-pc-windows-gnu", | ||
| 1240 | ] | ||
| 1241 | |||
| 1242 | [[package]] | ||
| 1243 | name = "winapi-build" | ||
| 1244 | version = "0.1.1" | ||
| 1245 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1246 | checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" | ||
| 1247 | |||
| 1248 | [[package]] | ||
| 1249 | name = "winapi-i686-pc-windows-gnu" | ||
| 1250 | version = "0.4.0" | ||
| 1251 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1252 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
| 1253 | |||
| 1254 | [[package]] | ||
| 1255 | name = "winapi-util" | ||
| 1256 | version = "0.1.5" | ||
| 1257 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1258 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" | ||
| 1259 | dependencies = [ | ||
| 1260 | "winapi 0.3.9", | ||
| 1261 | ] | ||
| 1262 | |||
| 1263 | [[package]] | ||
| 1264 | name = "winapi-x86_64-pc-windows-gnu" | ||
| 1265 | version = "0.4.0" | ||
| 1266 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1267 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
| 1268 | |||
| 1269 | [[package]] | ||
| 1270 | name = "ws2_32-sys" | ||
| 1271 | version = "0.2.1" | ||
| 1272 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1273 | checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" | ||
| 1274 | dependencies = [ | ||
| 1275 | "winapi 0.2.8", | ||
| 1276 | "winapi-build", | ||
| 1277 | ] | ||
diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3f9c00d --- /dev/null +++ b/Cargo.toml | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | [package] | ||
| 2 | name = "gradecoin" | ||
| 3 | version = "0.1.0" | ||
| 4 | authors = ["Yigit Sever <yigit@ceng.metu.edu.tr>"] | ||
| 5 | edition = "2018" | ||
| 6 | |||
| 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| 8 | |||
| 9 | [dependencies] | ||
| 10 | warp = "0.2.0" | ||
| 11 | tokio = { version = "0.2.9", features = ["macros"] } | ||
| 12 | serde = { version = "1.0.104", features = ["derive"] } | ||
| 13 | chrono = { version = "0.4.10", features = ["serde"] } | ||
| 14 | log = "0.4.8" | ||
| 15 | pretty_env_logger = "0.3.1" | ||
| 16 | |||
| 17 | [dev-dependencies] | ||
| 18 | serde_json = "1.0.44" | ||
| 19 | serde_test = "1.0.104" | ||
diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcfda11 --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | # Gradecoin | ||
| 2 | |||
| 3 | This will sit behind nginx reverse proxy so running at 127.0.0.1:8080 is no problem, or https. | ||
| 4 | |||
| 5 | ``` | ||
| 6 | $ cargo run | ||
| 7 | |||
| 8 | $ curl --location --request POST 'localhost:8080/transaction' --header 'Content-Type: application/json' --data-raw '{ | ||
| 9 | "source": "Myself Truly", | ||
| 10 | "target": "Literally Anybody Else", | ||
| 11 | "amount": 12, | ||
| 12 | "timestamp": "2021-04-07T00:17:00" | ||
| 13 | }' | ||
| 14 | ``` | ||
| 15 | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # TODO | ||
| 2 | ## Proof-of-work | ||
| 3 | - [ ] pick a block proposal scheme (= pick hash function) [list of hash functions](https://en.bitcoinwiki.org/wiki/List_of_hash_functions) | ||
| 4 | - [ ] check the nonce for incoming blocks | ||
| 5 | |||
| 6 | ## Authentication | ||
| 7 | - [ ] pick a user authentication scheme | ||
| 8 | - [ ] implement it | ||
| 9 | |||
| 10 | - [ ] Switch to RwLock (parking_lot) | ||
diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..1a076d8 --- /dev/null +++ b/rustfmt.toml | |||
| @@ -0,0 +1 @@ | |||
| edition="2018" | |||
diff --git a/src/custom_filters.rs b/src/custom_filters.rs new file mode 100644 index 0000000..86a78d4 --- /dev/null +++ b/src/custom_filters.rs | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | // Common filters ment to be shared between many endpoints | ||
| 2 | |||
| 3 | use std::convert::Infallible; | ||
| 4 | use warp::{Filter, Rejection}; | ||
| 5 | |||
| 6 | use crate::schema::{Db, Transaction}; // `Block` coming later | ||
| 7 | |||
| 8 | // Database context for routes | ||
| 9 | pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone { | ||
| 10 | warp::any().map(move || db.clone()) | ||
| 11 | } | ||
| 12 | |||
| 13 | // Optional query params to allow pagination | ||
| 14 | // pub fn list_options() -> impl Filter<Extract = (ListOptions,), Error = Rejection> + Clone { | ||
| 15 | // warp::query::<ListOptions>() | ||
| 16 | // } | ||
| 17 | |||
| 18 | // Accept only JSON body and reject big payloads | ||
| 19 | pub fn json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone { | ||
| 20 | warp::body::content_length_limit(1024 * 32).and(warp::body::json()) | ||
| 21 | } | ||
diff --git a/src/handlers.rs b/src/handlers.rs new file mode 100644 index 0000000..51c7b63 --- /dev/null +++ b/src/handlers.rs | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | // API handlers, the ends of each filter chain | ||
| 2 | |||
| 3 | use log::debug; | ||
| 4 | use std::convert::Infallible; | ||
| 5 | use warp::{http::StatusCode, reply}; | ||
| 6 | |||
| 7 | use crate::schema::{Db, Transaction}; // `Block` coming later | ||
| 8 | |||
| 9 | // PROPOSE Transaction | ||
| 10 | // POST /transaction | ||
| 11 | pub async fn propose_transaction( | ||
| 12 | new_transaction: Transaction, | ||
| 13 | db: Db, | ||
| 14 | ) -> Result<impl warp::Reply, warp::Rejection> { | ||
| 15 | debug!("new transaction request {:?}", new_transaction); | ||
| 16 | |||
| 17 | let mut transactions = db.lock().await; | ||
| 18 | |||
| 19 | transactions.push(new_transaction); | ||
| 20 | |||
| 21 | Ok(StatusCode::CREATED) | ||
| 22 | } | ||
| 23 | |||
| 24 | // GET Transaction List | ||
| 25 | // GET /transaction | ||
| 26 | // Returns JSON array of transactions | ||
| 27 | // Cannot fail? | ||
| 28 | pub async fn list_transactions(db: Db) -> Result<impl warp::Reply, Infallible> { | ||
| 29 | debug!("list all transactions"); | ||
| 30 | |||
| 31 | let transactions = db.lock().await; | ||
| 32 | |||
| 33 | let transactions: Vec<Transaction> = transactions.clone().into_iter().collect(); | ||
| 34 | |||
| 35 | Ok(reply::with_status( | ||
| 36 | reply::json(&transactions), | ||
| 37 | StatusCode::OK, | ||
| 38 | )) | ||
| 39 | } | ||
| 40 | |||
| 41 | // PROPOSE Block | ||
| 42 | // POST /block | ||
| 43 | |||
| 44 | // `GET /games` | ||
| 45 | // Returns JSON array of todos | ||
| 46 | // Allows pagination, for example: `GET /games?offset=10&limit=5` | ||
| 47 | // pub async fn list_games(options: ListOptions, db: Db) -> Result<impl Reply, Infallible> { | ||
| 48 | // debug!("list all games"); | ||
| 49 | |||
| 50 | // let games = db.lock().await; | ||
| 51 | // let games: Vec<Game> = games | ||
| 52 | // .clone() | ||
| 53 | // .into_iter() | ||
| 54 | // .skip(options.offset.unwrap_or(0)) | ||
| 55 | // .take(options.limit.unwrap_or(std::usize::MAX)) | ||
| 56 | // .collect(); | ||
| 57 | |||
| 58 | // Ok(warp::reply::json(&games)) | ||
| 59 | // } | ||
| 60 | |||
| 61 | // `POST /games` | ||
| 62 | // Create new game entry with JSON body | ||
| 63 | // pub async fn create_game(new_game: Game, db: Db) -> Result<impl Reply, Infallible> { | ||
| 64 | // debug!("create new game: {:?}", new_game); | ||
| 65 | |||
| 66 | // let mut games = db.lock().await; | ||
| 67 | |||
| 68 | // match games.iter().find(|game| game.id == new_game.id) { | ||
| 69 | // Some(game) => { | ||
| 70 | // debug!("game of given id already exists: {}", game.id); | ||
| 71 | |||
| 72 | // Ok(StatusCode::BAD_REQUEST) | ||
| 73 | // } | ||
| 74 | // None => { | ||
| 75 | // games.push(new_game); | ||
| 76 | // Ok(StatusCode::CREATED) | ||
| 77 | // } | ||
| 78 | // } | ||
| 79 | // } | ||
| 80 | |||
| 81 | // `PUT /games/:id` | ||
| 82 | // pub async fn update_game(id: u64, updated_game: Game, db: Db) -> Result<impl Reply, Infallible> { | ||
| 83 | // debug!("update existing game: id={}, game={:?}", id, updated_game); | ||
| 84 | |||
| 85 | // let mut games = db.lock().await; | ||
| 86 | |||
| 87 | // match games.iter_mut().find(|game| game.id == id) { | ||
| 88 | // Some(game) => { | ||
| 89 | // *game = updated_game; | ||
| 90 | |||
| 91 | // Ok(StatusCode::OK) | ||
| 92 | // } | ||
| 93 | // None => { | ||
| 94 | // debug!("game of given id not found"); | ||
| 95 | |||
| 96 | // Ok(StatusCode::NOT_FOUND) | ||
| 97 | // } | ||
| 98 | // } | ||
| 99 | // } | ||
| 100 | |||
| 101 | // `DELETE /games/:id` | ||
| 102 | // pub async fn delete_game(id: u64, db: Db) -> Result<impl Reply, Infallible> { | ||
| 103 | // debug!("delete game: id={}", id); | ||
| 104 | |||
| 105 | // let mut games = db.lock().await; | ||
| 106 | |||
| 107 | // let len = games.len(); | ||
| 108 | |||
| 109 | // // Removes all games with given id | ||
| 110 | // games.retain(|game| game.id != id); | ||
| 111 | |||
| 112 | // // If games length was smaller that means specyfic game was found and removed | ||
| 113 | // let deleted = games.len() != len; | ||
| 114 | |||
| 115 | // if deleted { | ||
| 116 | // Ok(StatusCode::NO_CONTENT) | ||
| 117 | // } else { | ||
| 118 | // debug!("game of given id not found"); | ||
| 119 | |||
| 120 | // Ok(StatusCode::NOT_FOUND) | ||
| 121 | // } | ||
| 122 | // } | ||
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..bcd4173 --- /dev/null +++ b/src/main.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | use std::env; | ||
| 2 | use warp::Filter; | ||
| 3 | |||
| 4 | mod custom_filters; | ||
| 5 | mod handlers; | ||
| 6 | mod routes; | ||
| 7 | mod schema; | ||
| 8 | // mod validators; | ||
| 9 | |||
| 10 | #[tokio::main] | ||
| 11 | async fn main() { | ||
| 12 | // Show debug logs by default by setting `RUST_LOG=restful_rust=debug` | ||
| 13 | if env::var_os("RUST_LOG").is_none() { | ||
| 14 | env::set_var("RUST_LOG", "restful_rust=debug"); | ||
| 15 | } | ||
| 16 | pretty_env_logger::init(); | ||
| 17 | |||
| 18 | let db = schema::ledger(); // 1. we need this to return a _simple_ db | ||
| 19 | |||
| 20 | let api = routes::consensus_routes(db); | ||
| 21 | |||
| 22 | let routes = api.with(warp::log("restful_rust")); | ||
| 23 | |||
| 24 | // Start the server | ||
| 25 | warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; | ||
| 26 | } | ||
diff --git a/src/routes.rs b/src/routes.rs new file mode 100644 index 0000000..fc4426a --- /dev/null +++ b/src/routes.rs | |||
| @@ -0,0 +1,359 @@ | |||
| 1 | use warp::{Filter, Rejection, Reply}; | ||
| 2 | |||
| 3 | use crate::custom_filters; | ||
| 4 | use crate::handlers; | ||
| 5 | use crate::schema::Db; | ||
| 6 | |||
| 7 | // Root, all routes combined | ||
| 8 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 9 | transaction_list(db.clone()).or(transaction_propose(db.clone())) | ||
| 10 | } | ||
| 11 | |||
| 12 | // GET /transaction | ||
| 13 | pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 14 | warp::path!("transaction") | ||
| 15 | .and(warp::get()) | ||
| 16 | .and(custom_filters::with_db(db)) | ||
| 17 | .and_then(handlers::list_transactions) | ||
| 18 | } | ||
| 19 | |||
| 20 | // POST /transaction | ||
| 21 | pub fn transaction_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 22 | warp::path!("transaction") | ||
| 23 | .and(warp::post()) | ||
| 24 | .and(custom_filters::json_body()) | ||
| 25 | .and(custom_filters::with_db(db)) | ||
| 26 | .and_then(handlers::propose_transaction) | ||
| 27 | } | ||
| 28 | |||
| 29 | /////////////////////////// | ||
| 30 | // below are not mine. // | ||
| 31 | /////////////////////////// | ||
| 32 | |||
| 33 | // Root, all routes combined | ||
| 34 | //pub fn games_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 35 | // games_list(db.clone()) | ||
| 36 | // .or(games_create(db.clone())) | ||
| 37 | // .or(games_update(db.clone())) | ||
| 38 | // .or(games_delete(db)) | ||
| 39 | //} | ||
| 40 | |||
| 41 | //// `GET /games?offset=3&limit=5` | ||
| 42 | //pub fn games_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 43 | // warp::path!("games") | ||
| 44 | // .and(warp::get()) | ||
| 45 | // .and(custom_filters::list_options()) | ||
| 46 | // .and(custom_filters::with_db(db)) | ||
| 47 | // .and_then(handlers::list_games) | ||
| 48 | //} | ||
| 49 | |||
| 50 | //// `POST /games` | ||
| 51 | //pub fn games_create(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 52 | // warp::path!("games") | ||
| 53 | // .and(warp::post()) | ||
| 54 | // .and(custom_filters::json_body()) | ||
| 55 | // .and(custom_filters::with_db(db)) | ||
| 56 | // .and_then(handlers::create_game) | ||
| 57 | //} | ||
| 58 | |||
| 59 | //// `PUT /games/:id` | ||
| 60 | //pub fn games_update(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 61 | // warp::path!("games" / u64) | ||
| 62 | // .and(warp::put()) | ||
| 63 | // .and(custom_filters::json_body()) | ||
| 64 | // .and(custom_filters::with_db(db)) | ||
| 65 | // .and_then(handlers::update_game) | ||
| 66 | //} | ||
| 67 | |||
| 68 | //// `DELETE /games/:id` | ||
| 69 | //pub fn games_delete(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
| 70 | // warp::path!("games" / u64) | ||
| 71 | // .and(warp::delete()) | ||
| 72 | // .and(custom_filters::with_db(db)) | ||
| 73 | // .and_then(handlers::delete_game) | ||
| 74 | //} | ||
| 75 | |||
| 76 | //////////////////////////////// | ||
| 77 | //// tests below, it's fine // | ||
| 78 | //////////////////////////////// | ||
| 79 | |||
| 80 | ///////////////////////////////////// | ||
| 81 | // of course I'll write tests... // | ||
| 82 | ///////////////////////////////////// | ||
| 83 | |||
| 84 | // TODO: write tests <07-04-21, yigit> // | ||
| 85 | |||
| 86 | //#[cfg(test)] | ||
| 87 | //mod tests { | ||
| 88 | // use super::*; | ||
| 89 | |||
| 90 | // use chrono::prelude::*; | ||
| 91 | // use std::sync::Arc; | ||
| 92 | // use tokio::sync::Mutex; | ||
| 93 | // use warp::http::StatusCode; | ||
| 94 | |||
| 95 | // use crate::schema::{Game, Genre}; | ||
| 96 | |||
| 97 | // // Mocked dataset for each test | ||
| 98 | |||
| 99 | // fn mocked_db() -> Db { | ||
| 100 | // Arc::new(Mutex::new(vec![ | ||
| 101 | // Game { | ||
| 102 | // id: 1, | ||
| 103 | // title: String::from("Crappy title"), | ||
| 104 | // rating: 35, | ||
| 105 | // genre: Genre::RolePlaying, | ||
| 106 | // description: Some(String::from("Test description...")), | ||
| 107 | // release_date: NaiveDate::from_ymd(2011, 9, 22).and_hms(0, 0, 0), | ||
| 108 | // }, | ||
| 109 | // Game { | ||
| 110 | // id: 2, | ||
| 111 | // title: String::from("Decent game"), | ||
| 112 | // rating: 84, | ||
| 113 | // genre: Genre::Strategy, | ||
| 114 | // description: None, | ||
| 115 | // release_date: NaiveDate::from_ymd(2014, 3, 11).and_hms(0, 0, 0), | ||
| 116 | // }, | ||
| 117 | // ])) | ||
| 118 | // } | ||
| 119 | |||
| 120 | // fn mocked_game() -> Game { | ||
| 121 | // Game { | ||
| 122 | // id: 3, | ||
| 123 | // title: String::from("Another game"), | ||
| 124 | // rating: 65, | ||
| 125 | // description: None, | ||
| 126 | // genre: Genre::Strategy, | ||
| 127 | // release_date: NaiveDate::from_ymd(2016, 3, 11).and_hms(0, 0, 0), | ||
| 128 | // } | ||
| 129 | // } | ||
| 130 | |||
| 131 | // #[tokio::test] | ||
| 132 | // async fn get_list_of_games_200() { | ||
| 133 | // let db = mocked_db(); | ||
| 134 | // let filter = games_routes(db); | ||
| 135 | |||
| 136 | // let res = warp::test::request().method("GET").path("/games").reply(&filter).await; | ||
| 137 | |||
| 138 | // assert_eq!(res.status(), StatusCode::OK); | ||
| 139 | |||
| 140 | // let expected_json_body = r#"[{"id":1,"title":"Crappy title","rating":35,"genre":"ROLE_PLAYING","description":"Test description...","releaseDate":"2011-09-22T00:00:00"},{"id":2,"title":"Decent game","rating":84,"genre":"STRATEGY","description":null,"releaseDate":"2014-03-11T00:00:00"}]"#; | ||
| 141 | // assert_eq!(res.body(), expected_json_body); | ||
| 142 | // } | ||
| 143 | |||
| 144 | // #[tokio::test] | ||
| 145 | // async fn get_list_of_games_with_options_200() { | ||
| 146 | // let db = mocked_db(); | ||
| 147 | // let filter = games_routes(db); | ||
| 148 | |||
| 149 | // let res = warp::test::request() | ||
| 150 | // .method("GET") | ||
| 151 | // .path("/games?offset=1&limit=5") | ||
| 152 | // .reply(&filter) | ||
| 153 | // .await; | ||
| 154 | |||
| 155 | // assert_eq!(res.status(), StatusCode::OK); | ||
| 156 | |||
| 157 | // let expected_json_body = r#"[{"id":2,"title":"Decent game","rating":84,"genre":"STRATEGY","description":null,"releaseDate":"2014-03-11T00:00:00"}]"#; | ||
| 158 | // assert_eq!(res.body(), expected_json_body); | ||
| 159 | // } | ||
| 160 | |||
| 161 | // #[tokio::test] | ||
| 162 | // async fn get_empty_list_with_offset_overshot_200() { | ||
| 163 | // let db = mocked_db(); | ||
| 164 | // let filter = games_routes(db); | ||
| 165 | |||
| 166 | // let res = warp::test::request() | ||
| 167 | // .method("GET") | ||
| 168 | // .path("/games?offset=5&limit=5") | ||
| 169 | // .reply(&filter) | ||
| 170 | // .await; | ||
| 171 | |||
| 172 | // assert_eq!(res.status(), StatusCode::OK); | ||
| 173 | |||
| 174 | // let expected_json_body = r#"[]"#; | ||
| 175 | // assert_eq!(res.body(), expected_json_body); | ||
| 176 | // } | ||
| 177 | |||
| 178 | // #[tokio::test] | ||
| 179 | // async fn get_incorrect_options_400() { | ||
| 180 | // let db = mocked_db(); | ||
| 181 | // let filter = games_routes(db); | ||
| 182 | |||
| 183 | // let res = warp::test::request() | ||
| 184 | // .method("GET") | ||
| 185 | // .path("/games?offset=a&limit=b") | ||
| 186 | // .reply(&filter) | ||
| 187 | // .await; | ||
| 188 | |||
| 189 | // assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
| 190 | // } | ||
| 191 | |||
| 192 | // #[tokio::test] | ||
| 193 | // async fn get_wrong_path_405() { | ||
| 194 | // let db = mocked_db(); | ||
| 195 | // let filter = games_routes(db); | ||
| 196 | |||
| 197 | // let res = warp::test::request() | ||
| 198 | // .method("GET") | ||
| 199 | // .path("/games/42") | ||
| 200 | // .reply(&filter) | ||
| 201 | // .await; | ||
| 202 | |||
| 203 | // assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED); | ||
| 204 | // } | ||
| 205 | |||
| 206 | // #[tokio::test] | ||
| 207 | // async fn post_json_201() { | ||
| 208 | // let db = mocked_db(); | ||
| 209 | // let filter = games_routes(db.clone()); | ||
| 210 | |||
| 211 | // let res = warp::test::request() | ||
| 212 | // .method("POST") | ||
| 213 | // .json(&mocked_game()) | ||
| 214 | // .path("/games") | ||
| 215 | // .reply(&filter) | ||
| 216 | // .await; | ||
| 217 | |||
| 218 | // assert_eq!(res.status(), StatusCode::CREATED); | ||
| 219 | // assert_eq!(db.lock().await.len(), 3); | ||
| 220 | // } | ||
| 221 | |||
| 222 | // #[tokio::test] | ||
| 223 | // async fn post_too_long_content_413() { | ||
| 224 | // let db = mocked_db(); | ||
| 225 | // let filter = games_routes(db); | ||
| 226 | |||
| 227 | // let res = warp::test::request() | ||
| 228 | // .method("POST") | ||
| 229 | // .header("content-length", 1024 * 36) | ||
| 230 | // .path("/games") | ||
| 231 | // .reply(&filter) | ||
| 232 | // .await; | ||
| 233 | |||
| 234 | // assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE); | ||
| 235 | // } | ||
| 236 | |||
| 237 | // #[tokio::test] | ||
| 238 | // async fn post_wrong_payload_400() { | ||
| 239 | // let db = mocked_db(); | ||
| 240 | // let filter = games_routes(db); | ||
| 241 | |||
| 242 | // let res = warp::test::request() | ||
| 243 | // .method("POST") | ||
| 244 | // .body(&r#"{"id":4}"#) | ||
| 245 | // .path("/games") | ||
| 246 | // .reply(&filter) | ||
| 247 | // .await; | ||
| 248 | |||
| 249 | // assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
| 250 | // } | ||
| 251 | |||
| 252 | // #[tokio::test] | ||
| 253 | // async fn post_wrong_path_405() { | ||
| 254 | // let db = mocked_db(); | ||
| 255 | // let filter = games_routes(db); | ||
| 256 | |||
| 257 | // let res = warp::test::request() | ||
| 258 | // .method("POST") | ||
| 259 | // .path("/games/42") | ||
| 260 | // .reply(&filter) | ||
| 261 | // .await; | ||
| 262 | |||
| 263 | // assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED); | ||
| 264 | // } | ||
| 265 | |||
| 266 | // #[tokio::test] | ||
| 267 | // async fn put_json_200() { | ||
| 268 | // let db = mocked_db(); | ||
| 269 | // let filter = games_routes(db.clone()); | ||
| 270 | |||
| 271 | // let res = warp::test::request() | ||
| 272 | // .method("PUT") | ||
| 273 | // .json(&mocked_game()) | ||
| 274 | // .path("/games/2") | ||
| 275 | // .reply(&filter) | ||
| 276 | // .await; | ||
| 277 | |||
| 278 | // assert_eq!(res.status(), StatusCode::OK); | ||
| 279 | |||
| 280 | // let db = db.lock().await; | ||
| 281 | // let ref title = db[1].title; | ||
| 282 | // assert_eq!(title, "Another game"); | ||
| 283 | // } | ||
| 284 | |||
| 285 | // #[tokio::test] | ||
| 286 | // async fn put_wrong_id_404() { | ||
| 287 | // let db = mocked_db(); | ||
| 288 | // let filter = games_routes(db); | ||
| 289 | |||
| 290 | // let res = warp::test::request() | ||
| 291 | // .method("PUT") | ||
| 292 | // .json(&mocked_game()) | ||
| 293 | // .path("/games/42") | ||
| 294 | // .reply(&filter) | ||
| 295 | // .await; | ||
| 296 | |||
| 297 | // assert_eq!(res.status(), StatusCode::NOT_FOUND); | ||
| 298 | // } | ||
| 299 | |||
| 300 | // #[tokio::test] | ||
| 301 | // async fn put_wrong_payload_400() { | ||
| 302 | // let db = mocked_db(); | ||
| 303 | // let filter = games_routes(db); | ||
| 304 | |||
| 305 | // let res = warp::test::request() | ||
| 306 | // .method("PUT") | ||
| 307 | // .header("content-length", 1024 * 16) | ||
| 308 | // .body(&r#"{"id":2"#) | ||
| 309 | // .path("/games/2") | ||
| 310 | // .reply(&filter) | ||
| 311 | // .await; | ||
| 312 | |||
| 313 | // assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
| 314 | // } | ||
| 315 | |||
| 316 | // #[tokio::test] | ||
| 317 | // async fn put_too_long_content_413() { | ||
| 318 | // let db = mocked_db(); | ||
| 319 | // let filter = games_routes(db); | ||
| 320 | |||
| 321 | // let res = warp::test::request() | ||
| 322 | // .method("PUT") | ||
| 323 | // .header("content-length", 1024 * 36) | ||
| 324 | // .path("/games/2") | ||
| 325 | // .reply(&filter) | ||
| 326 | // .await; | ||
| 327 | |||
| 328 | // assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE); | ||
| 329 | // } | ||
| 330 | |||
| 331 | // #[tokio::test] | ||
| 332 | // async fn delete_wrong_id_404() { | ||
| 333 | // let db = mocked_db(); | ||
| 334 | // let filter = games_routes(db); | ||
| 335 | |||
| 336 | // let res = warp::test::request() | ||
| 337 | // .method("DELETE") | ||
| 338 | // .path("/games/42") | ||
| 339 | // .reply(&filter) | ||
| 340 | // .await; | ||
| 341 | |||
| 342 | // assert_eq!(res.status(), StatusCode::NOT_FOUND); | ||
| 343 | // } | ||
| 344 | |||
| 345 | // #[tokio::test] | ||
| 346 | // async fn delete_game_204() { | ||
| 347 | // let db = mocked_db(); | ||
| 348 | // let filter = games_routes(db.clone()); | ||
| 349 | |||
| 350 | // let res = warp::test::request() | ||
| 351 | // .method("DELETE") | ||
| 352 | // .path("/games/1") | ||
| 353 | // .reply(&filter) | ||
| 354 | // .await; | ||
| 355 | |||
| 356 | // assert_eq!(res.status(), StatusCode::NO_CONTENT); | ||
| 357 | // assert_eq!(db.lock().await.len(), 1); | ||
| 358 | // } | ||
| 359 | //} | ||
diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..ea36a70 --- /dev/null +++ b/src/schema.rs | |||
| @@ -0,0 +1,223 @@ | |||
| 1 | // Common types used across API | ||
| 2 | |||
| 3 | use chrono::{NaiveDate, NaiveDateTime}; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | use std::sync::Arc; | ||
| 6 | use tokio::sync::Mutex; | ||
| 7 | |||
| 8 | // use crate::validators; | ||
| 9 | |||
| 10 | pub fn ledger() -> Db { | ||
| 11 | // TODO: there was something simpler in one of the other tutorials? <07-04-21, yigit> // | ||
| 12 | |||
| 13 | Arc::new(Mutex::new(vec![ | ||
| 14 | Transaction { | ||
| 15 | source: String::from("Myself"), | ||
| 16 | target: String::from("Nobody"), | ||
| 17 | amount: 4, | ||
| 18 | timestamp: NaiveDate::from_ymd(2021, 4, 7).and_hms(00, 17, 00), | ||
| 19 | }, | ||
| 20 | ])) | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | // For presentation purposes keep mocked data in in-memory structure | ||
| 25 | // In real life scenario connection with regular database would be established | ||
| 26 | |||
| 27 | pub type Db = Arc<Mutex<Vec<Transaction>>>; | ||
| 28 | |||
| 29 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
| 30 | pub struct Transaction { | ||
| 31 | pub source: String, | ||
| 32 | pub target: String, | ||
| 33 | pub amount: i32, | ||
| 34 | pub timestamp: NaiveDateTime, | ||
| 35 | } | ||
| 36 | |||
| 37 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
| 38 | pub struct Block { | ||
| 39 | pub transaction_list: Vec<Transaction>, // [Transaction; N] | ||
| 40 | pub nonce: i32, | ||
| 41 | pub timestamp: NaiveDateTime, | ||
| 42 | pub hash: String, // future proof'd baby | ||
| 43 | } | ||
| 44 | |||
| 45 | // #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
| 46 | // #[serde(rename_all = "camelCase")] | ||
| 47 | // pub struct Game { | ||
| 48 | // pub id: u64, | ||
| 49 | // pub title: String, | ||
| 50 | // #[serde(with = "validators::validate_game_rating")] | ||
| 51 | // pub rating: u8, | ||
| 52 | // pub genre: Genre, | ||
| 53 | // pub description: Option<String>, | ||
| 54 | // pub release_date: NaiveDateTime, | ||
| 55 | // } | ||
| 56 | |||
| 57 | // #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
| 58 | // #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | ||
| 59 | // pub enum Genre { | ||
| 60 | // RolePlaying, | ||
| 61 | // Strategy, | ||
| 62 | // Shooter, | ||
| 63 | // } | ||
| 64 | |||
| 65 | // #[derive(Deserialize, Debug, PartialEq)] | ||
| 66 | // pub struct ListOptions { | ||
| 67 | // pub offset: Option<usize>, | ||
| 68 | // pub limit: Option<usize>, | ||
| 69 | // } | ||
| 70 | |||
| 71 | // pub fn example_db() -> Db { | ||
| 72 | // Arc::new(Mutex::new( | ||
| 73 | // vec![ | ||
| 74 | // Game { | ||
| 75 | // id: 1, | ||
| 76 | // title: String::from("Dark Souls"), | ||
| 77 | // rating: 91, | ||
| 78 | // genre: Genre::RolePlaying, | ||
| 79 | // description: Some(String::from("Takes place in the fictional kingdom of Lordran, where players assume the role of a cursed undead character who begins a pilgrimage to discover the fate of their kind.")), | ||
| 80 | // release_date: NaiveDate::from_ymd(2011, 9, 22).and_hms(0, 0, 0), | ||
| 81 | // }, | ||
| 82 | // Game { | ||
| 83 | // id: 2, | ||
| 84 | // title: String::from("Dark Souls 2"), | ||
| 85 | // rating: 87, | ||
| 86 | // genre: Genre::RolePlaying, | ||
| 87 | // description: None, | ||
| 88 | // release_date: NaiveDate::from_ymd(2014, 3, 11).and_hms(0, 0, 0), | ||
| 89 | // }, | ||
| 90 | // Game { | ||
| 91 | // id: 3, | ||
| 92 | // title: String::from("Dark Souls 3"), | ||
| 93 | // rating: 89, | ||
| 94 | // genre: Genre::RolePlaying, | ||
| 95 | // description: Some(String::from("The latest chapter in the series with its trademark sword and sorcery combat and rewarding action RPG gameplay.")), | ||
| 96 | // release_date: NaiveDate::from_ymd(2016, 3, 24).and_hms(0, 0, 0), | ||
| 97 | // }, | ||
| 98 | // ] | ||
| 99 | // )) | ||
| 100 | // } | ||
| 101 | |||
| 102 | // #[cfg(test)] | ||
| 103 | // mod tests { | ||
| 104 | // use super::*; | ||
| 105 | |||
| 106 | // use serde_json::error::Error; | ||
| 107 | // use serde_test::{assert_tokens, Token}; | ||
| 108 | |||
| 109 | // #[test] | ||
| 110 | // fn game_serialize_correctly() { | ||
| 111 | // let game = Game { | ||
| 112 | // id: 1, | ||
| 113 | // title: String::from("Test"), | ||
| 114 | // rating: 90, | ||
| 115 | // genre: Genre::Shooter, | ||
| 116 | // description: None, | ||
| 117 | // release_date: NaiveDate::from_ymd(2019, 11, 12).and_hms(0, 0, 0), | ||
| 118 | // }; | ||
| 119 | |||
| 120 | // assert_tokens( | ||
| 121 | // &game, | ||
| 122 | // &[ | ||
| 123 | // Token::Struct { | ||
| 124 | // name: "Game", | ||
| 125 | // len: 6, | ||
| 126 | // }, | ||
| 127 | // Token::String("id"), | ||
| 128 | // Token::U64(1), | ||
| 129 | // Token::String("title"), | ||
| 130 | // Token::String("Test"), | ||
| 131 | // Token::String("rating"), | ||
| 132 | // Token::U8(90), | ||
| 133 | // Token::String("genre"), | ||
| 134 | // Token::UnitVariant { | ||
| 135 | // name: "Genre", | ||
| 136 | // variant: "SHOOTER", | ||
| 137 | // }, | ||
| 138 | // Token::String("description"), | ||
| 139 | // Token::None, | ||
| 140 | // Token::String("releaseDate"), | ||
| 141 | // Token::String("2019-11-12T00:00:00"), | ||
| 142 | // Token::StructEnd, | ||
| 143 | // ], | ||
| 144 | // ); | ||
| 145 | // } | ||
| 146 | |||
| 147 | // #[test] | ||
| 148 | // fn game_deserialize_correctly() { | ||
| 149 | // let data = r#"{"id":3,"title":"Another game","rating":65,"genre":"STRATEGY","description":null,"releaseDate":"2016-03-11T00:00:00"}"#; | ||
| 150 | // let game: Game = serde_json::from_str(data).unwrap(); | ||
| 151 | // let expected_game = Game { | ||
| 152 | // id: 3, | ||
| 153 | // title: String::from("Another game"), | ||
| 154 | // rating: 65, | ||
| 155 | // genre: Genre::Strategy, | ||
| 156 | // description: None, | ||
| 157 | // release_date: NaiveDate::from_ymd(2016, 3, 11).and_hms(0, 0, 0), | ||
| 158 | // }; | ||
| 159 | |||
| 160 | // assert_eq!(game, expected_game); | ||
| 161 | // } | ||
| 162 | |||
| 163 | // #[test] | ||
| 164 | // fn game_error_when_wrong_rating_passed() { | ||
| 165 | // let data = r#"{"id":3,"title":"Another game","rating":120,"genre":"STRATEGY","description":null,"releaseDate":"2016-03-11T00:00:00"}"#; | ||
| 166 | // let err: Error = serde_json::from_str::<Game>(data).unwrap_err(); | ||
| 167 | |||
| 168 | // assert_eq!(err.is_data(), true); | ||
| 169 | // } | ||
| 170 | |||
| 171 | // #[test] | ||
| 172 | // fn genre_serialize_correctly() { | ||
| 173 | // let genre = Genre::Shooter; | ||
| 174 | // assert_tokens( | ||
| 175 | // &genre, | ||
| 176 | // &[Token::UnitVariant { | ||
| 177 | // name: "Genre", | ||
| 178 | // variant: "SHOOTER", | ||
| 179 | // }], | ||
| 180 | // ); | ||
| 181 | |||
| 182 | // let genre = Genre::RolePlaying; | ||
| 183 | // assert_tokens( | ||
| 184 | // &genre, | ||
| 185 | // &[Token::UnitVariant { | ||
| 186 | // name: "Genre", | ||
| 187 | // variant: "ROLE_PLAYING", | ||
| 188 | // }], | ||
| 189 | // ); | ||
| 190 | |||
| 191 | // let genre = Genre::Strategy; | ||
| 192 | // assert_tokens( | ||
| 193 | // &genre, | ||
| 194 | // &[Token::UnitVariant { | ||
| 195 | // name: "Genre", | ||
| 196 | // variant: "STRATEGY", | ||
| 197 | // }], | ||
| 198 | // ); | ||
| 199 | // } | ||
| 200 | |||
| 201 | // #[test] | ||
| 202 | // fn genre_deserialize_correctly() { | ||
| 203 | // let data = r#""SHOOTER""#; | ||
| 204 | // let genre: Genre = serde_json::from_str(data).unwrap(); | ||
| 205 | // let expected_genre = Genre::Shooter; | ||
| 206 | |||
| 207 | // assert_eq!(genre, expected_genre); | ||
| 208 | |||
| 209 | // let data = r#""ROLE_PLAYING""#; | ||
| 210 | // let genre: Genre = serde_json::from_str(data).unwrap(); | ||
| 211 | // let expected_genre = Genre::RolePlaying; | ||
| 212 | |||
| 213 | // assert_eq!(genre, expected_genre); | ||
| 214 | // } | ||
| 215 | |||
| 216 | // #[test] | ||
| 217 | // fn genre_error_when_wrong_rating_passed() { | ||
| 218 | // let data = r#""SPORT""#; | ||
| 219 | // let err: Error = serde_json::from_str::<Genre>(data).unwrap_err(); | ||
| 220 | |||
| 221 | // assert_eq!(err.is_data(), true); | ||
| 222 | // } | ||
| 223 | // } | ||
diff --git a/src/validators.rs b/src/validators.rs new file mode 100644 index 0000000..dbebee8 --- /dev/null +++ b/src/validators.rs | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Custom validators incoming data | ||
| 2 | |||
| 3 | use log::error; | ||
| 4 | use serde::de::{Deserializer, Error as DeserializerError, Unexpected}; | ||
| 5 | use serde::ser::{Error as SerializerError, Serializer}; | ||
| 6 | use serde::Deserialize; | ||
| 7 | |||
| 8 | pub mod validate_game_rating { | ||
| 9 | use super::*; | ||
| 10 | |||
| 11 | const ERROR_MESSAGE: &str = "rating must be a number between 0 and 100"; | ||
| 12 | |||
| 13 | pub fn deserialize<'de, D>(deserializer: D) -> Result<u8, D::Error> | ||
| 14 | where | ||
| 15 | D: Deserializer<'de>, | ||
| 16 | { | ||
| 17 | let value = u8::deserialize(deserializer)?; | ||
| 18 | |||
| 19 | if value > 100 { | ||
| 20 | error!("{}", ERROR_MESSAGE); | ||
| 21 | |||
| 22 | return Err(DeserializerError::invalid_value( | ||
| 23 | Unexpected::Unsigned(u64::from(value)), | ||
| 24 | &ERROR_MESSAGE, | ||
| 25 | )); | ||
| 26 | } | ||
| 27 | |||
| 28 | Ok(value) | ||
| 29 | } | ||
| 30 | |||
| 31 | #[allow(clippy::trivially_copy_pass_by_ref)] | ||
| 32 | pub fn serialize<S>(value: &u8, serializer: S) -> Result<S::Ok, S::Error> | ||
| 33 | where | ||
| 34 | S: Serializer, | ||
| 35 | { | ||
| 36 | if *value > 100 { | ||
| 37 | error!("{}", ERROR_MESSAGE); | ||
| 38 | |||
| 39 | return Err(SerializerError::custom(ERROR_MESSAGE)); | ||
| 40 | } | ||
| 41 | |||
| 42 | serializer.serialize_u8(*value) | ||
| 43 | } | ||
| 44 | } | ||
