Browse Source

Clean up, use new entity store

master
Puck Meerburg 9 months ago
parent
commit
04582319c7
9 changed files with 440 additions and 128 deletions
  1. 322
    1
      Cargo.lock
  2. 1
    1
      README.md
  3. 8
    10
      src/bin/kroeg-call.rs
  4. 5
    1
      src/delivery.rs
  5. 1
    1
      src/get.rs
  6. 74
    97
      src/lib.rs
  7. 6
    1
      src/router.rs
  8. 15
    8
      src/store.rs
  9. 8
    8
      src/webfinger.rs

+ 322
- 1
Cargo.lock View File

@@ -6,6 +6,11 @@ dependencies = [
"memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "antidote"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "arrayref"
version = "0.3.5"
@@ -47,11 +52,35 @@ dependencies = [
"byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "block-buffer"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-padding 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "block-padding"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "byte-tools"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "byte-tools"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "byteorder"
version = "1.2.7"
@@ -147,6 +176,59 @@ name = "crossbeam-utils"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "crypto-mac"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "darling"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"darling_core 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"darling_macro 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "darling_core"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ident_case 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "darling_macro"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"darling_core 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "derive_state_machine_future"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "diesel"
version = "1.2.2"
@@ -176,6 +258,14 @@ dependencies = [
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "digest"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "dotenv"
version = "0.9.0"
@@ -189,6 +279,16 @@ name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "fallible-iterator"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "fixedbitset"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "fnv"
version = "1.0.6"
@@ -260,6 +360,14 @@ dependencies = [
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "futures-state-stream"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "generic-array"
version = "0.9.0"
@@ -268,6 +376,14 @@ dependencies = [
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "generic-array"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "h2"
version = "0.1.13"
@@ -285,6 +401,28 @@ dependencies = [
"tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "heck"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "hex"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "hmac"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "http"
version = "0.1.13"
@@ -339,6 +477,11 @@ dependencies = [
"tokio-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "ident_case"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "idna"
version = "0.1.5"
@@ -393,13 +536,14 @@ dependencies = [
name = "kroeg-cellar"
version = "0.1.0"
dependencies = [
"diesel 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-state-stream 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonld 0.1.0",
"kroeg-tap 0.1.0",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-postgres 0.3.0 (git+https://github.com/sfackler/rust-postgres)",
]

[[package]]
@@ -449,6 +593,7 @@ dependencies = [
"kroeg-tap 0.1.0",
"openssl 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -496,6 +641,11 @@ name = "matches"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "md5"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "memchr"
version = "2.1.1"
@@ -600,6 +750,11 @@ dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "opaque-debug"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "openssl"
version = "0.9.24"
@@ -636,6 +791,11 @@ dependencies = [
"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "ordermap"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "owning_ref"
version = "0.2.4"
@@ -696,11 +856,65 @@ name = "percent-encoding"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "petgraph"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "phf"
version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "phf_shared"
version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "pkg-config"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "postgres-protocol"
version = "0.3.2"
source = "git+https://github.com/sfackler/rust-postgres#04bd98e7edb238511661b311c725a176012bca6a"
dependencies = [
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"fallible-iterator 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"md5 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "postgres-shared"
version = "0.4.1"
source = "git+https://github.com/sfackler/rust-postgres#04bd98e7edb238511661b311c725a176012bca6a"
dependencies = [
"fallible-iterator 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"postgres-protocol 0.3.2 (git+https://github.com/sfackler/rust-postgres)",
]

[[package]]
name = "pq-sys"
version = "0.4.6"
@@ -809,6 +1023,11 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rent_to_own"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "rustc_version"
version = "0.2.3"
@@ -915,6 +1134,22 @@ dependencies = [
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "sha2"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "siphasher"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "slab"
version = "0.4.1"
@@ -933,11 +1168,35 @@ name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "state_machine_future"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"derive_state_machine_future 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"rent_to_own 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "string"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "stringprep"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "subtle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "syn"
version = "0.12.15"
@@ -1091,6 +1350,29 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-postgres"
version = "0.3.0"
source = "git+https://github.com/sfackler/rust-postgres#04bd98e7edb238511661b311c725a176012bca6a"
dependencies = [
"antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"fallible-iterator 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"postgres-protocol 0.3.2 (git+https://github.com/sfackler/rust-postgres)",
"postgres-shared 0.4.1 (git+https://github.com/sfackler/rust-postgres)",
"state_machine_future 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-uds 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-reactor"
version = "0.1.6"
@@ -1223,6 +1505,11 @@ name = "unicode-normalization"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unicode-segmentation"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unicode-xid"
version = "0.1.0"
@@ -1316,13 +1603,17 @@ dependencies = [

[metadata]
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
"checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d"
"checksum block-padding 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc4358306e344bf9775d0197fd00d2603e5afb0771bb353538630f022068ea3"
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
"checksum byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "980479e6fde23246dfb54d47580d66b4e99202e7579c5eaa9fe10ecb5ebd2182"
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
"checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
@@ -1335,11 +1626,19 @@ dependencies = [
"checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1"
"checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9"
"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
"checksum darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f000e7b03a0083a30e1f10b1428a530849c21e72b338fa76869b5dbc4b045bf"
"checksum darling_core 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "86bc5ce438f4b703755d12f59bbf0a16c642766d4534e922db47569dbdd0b998"
"checksum darling_macro 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9973050ba46be2a2935a7b316147f41a808ac604b8f0fef6eba77fd47a89daeb"
"checksum derive_state_machine_future 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "32c4adac64fe9b4807a7a51e126eadf3c2a10a3c3d1abe600454f0fa42dbe3e5"
"checksum diesel 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24815a0c2094f2c8dafe74ab3b9e975892f44acbb94b4d4b4898025a7615efa4"
"checksum diesel_derives 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6471a2b637b414d3ee1504cf230409a550381c79204282f8fe06c527e4ae56be"
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
"checksum dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "400b347fe65ccfbd8f545c9d9a75d04b0caf23fec49aaa838a9a05398f94c019"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum fallible-iterator 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea79295a7a3e0d77f19e763cf1fe7189cd95fc2b36735ea0ea6b711a7380f509"
"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
@@ -1350,12 +1649,18 @@ dependencies = [
"checksum futures-await-async-macro 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fdd257a06a5fd1f31adcbddb8068678b2ae534fb6eb282df010ae41db59ddf84"
"checksum futures-await-await-macro 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3b8bd34e4f4d1bf0e3fe3f22ad22475429f594221472216e34b942f912ec4a4"
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
"checksum futures-state-stream 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad71c9a91e8d07baf5610ce3a33f9d8b202af7f4e48dcd73b692d8d15dde8e67"
"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592"
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
"checksum h2 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7dd33bafe2e6370e6c8eb0cf1b8c5f93390b90acde7e9b03723f166b28b648ed"
"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
"checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771"
"checksum http 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "24f58e8c2d8e886055c3ead7b28793e1455270b5fb39650984c224bc538ba581"
"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
"checksum hyper 0.12.13 (registry+https://github.com/rust-lang/crates.io-index)" = "95ffee0d1d30de4313fdaaa485891ce924991d45bbc18adfc8ac5b1639e62fbb"
"checksum hyper-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d5787cee312507c4d005405e75da2b3357b58c47e3f14cddfa5f05c98edf6f29"
"checksum ident_case 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9826188e666f2ed92071d2dadef6edc430b11b158b5b2b3f4babbcc891eaaa"
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
@@ -1368,6 +1673,7 @@ dependencies = [
"checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum md5 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c1ad8b18d0b6ae54e03c9fe1f7dea2ee5f8e0115a87611316794be1bc51537f7"
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
@@ -1379,9 +1685,11 @@ dependencies = [
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51ecbcb821e1bd256d456fe858aaa7f380b63863eab2eb86eee1bd9f33dd6682"
"checksum openssl 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "5e1309181cdcbdb51bc3b6bedb33dfac2a83b3d585033d3f6d9e22e8c1928613"
"checksum openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "a3605c298474a3aa69de92d21139fb5e2a81688d308262359d85cdd0d12a7985"
"checksum openssl-sys 0.9.39 (registry+https://github.com/rust-lang/crates.io-index)" = "278c1ad40a89aa1e741a1eed089a2f60b18fab8089c3139b542140fc7d674106"
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
"checksum owning_ref 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d52571ddcb42e9c900c901a18d8d67e393df723fcd51dd59c5b1a85d0acb6cc"
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
"checksum parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fa12d706797d42551663426a45e2db2e0364bd1dbf6aeada87e89c5f981f43e9"
@@ -1389,7 +1697,12 @@ dependencies = [
"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
"checksum phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "7d37a244c75a9748e049225155f56dbcb98fe71b192fd25fd23cb914b5ad62f2"
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum postgres-protocol 0.3.2 (git+https://github.com/sfackler/rust-postgres)" = "<none>"
"checksum postgres-shared 0.4.1 (git+https://github.com/sfackler/rust-postgres)" = "<none>"
"checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
@@ -1403,6 +1716,7 @@ dependencies = [
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rent_to_own 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05a51ad2b1c5c710fa89e6b1631068dab84ed687bc6a5fe061ad65da3d0c25b2"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
@@ -1417,10 +1731,15 @@ dependencies = [
"checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c"
"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0"
"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
"checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d"
"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum state_machine_future 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4365457c6ec580f8dee3b2c951f69fb50e510906f6cf5739845f9aa3430eb918"
"checksum string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00caf261d6f90f588f8450b8e1230fa0d5be49ee6140fdfbcb55335aff350970"
"checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1"
"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
"checksum syn 0.12.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c97c05b8ebc34ddd6b967994d5c6e9852fa92f8b82b3858c39451f97346dcce5"
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
"checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
@@ -1435,6 +1754,7 @@ dependencies = [
"checksum tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c117b6cf86bb730aab4834f10df96e4dd586eff2c3c27d3781348da49e255bde"
"checksum tokio-fs 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "60ae25f6b17d25116d2cba342083abe5255d3c2c79cb21ea11aa049c53bf7c75"
"checksum tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "7392fe0a70d5ce0c882c4778116c519bd5dbaa8a7c3ae3d04578b3afafdcda21"
"checksum tokio-postgres 0.3.0 (git+https://github.com/sfackler/rust-postgres)" = "<none>"
"checksum tokio-reactor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4b26fd37f1125738b2170c80b551f69ff6fecb277e6e5ca885e53eec2b005018"
"checksum tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ad235e9dadd126b2d47f6736f65aa1fdcd6420e66ca63f44177bc78df89f912"
"checksum tokio-threadpool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3929aee321c9220ed838ed6c3928be7f9b69986b0e3c22c972a66dbf8a298c68"
@@ -1448,6 +1768,7 @@ dependencies = [
"checksum ucd-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0f8bfa9ff0cadcd210129ad9d2c5f145c13e9ced3d3e5d948a6213487d52444"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6"

+ 1
- 1
README.md View File

@@ -13,7 +13,7 @@ anyways, if you still want to try it:
- Install the latest Rust nightly, or close to it
- Create a folder
- clone https://github.com/kroeg/jsonld-rs, https://git.puckipedia.com/kroeg/tap, https://git.puckipedia.com/kroeg/cellar, and https://git.puckipedia.com/kroeg/server into this folder
- Go to cellar, run `diesel migration run --database-url postgres://whatever`
- Go to cellar, put the `.sql` file into your database.
- Copy `server.toml.example` to `server.toml`, set it up as required.
- Create root users with `cargo run --bin kroeg-call create https://example.com/~exampleUser exampleUser "Example User"`
- Gain an authorization key by running `cargo run --bin kroeg-call auth https://example.com/~exampleUser`

+ 8
- 10
src/bin/kroeg-call.rs View File

@@ -2,7 +2,6 @@

extern crate base64;
extern crate chashmap;
extern crate diesel;
extern crate dotenv;
extern crate futures_await as futures;
extern crate hyper;
@@ -22,7 +21,6 @@ extern crate serde_json;
#[path = "../config.rs"]
mod config;

use diesel::prelude::*;
use futures::prelude::{await, *};
use jsonld::nodemap::{Pointer, Value};
use kroeg_cellar::QuadClient;
@@ -88,20 +86,20 @@ fn create_auth<T: EntityStore + 'static>(store: T, id: String) -> Result<(), (T:
"{}.{}",
base64::encode_config(
json!({
"typ": "JWT",
"alg": "RS256",
"kid": keyid
})
"typ": "JWT",
"alg": "RS256",
"kid": keyid
})
.to_string()
.as_bytes(),
base64::URL_SAFE_NO_PAD
),
base64::encode_config(
json!({
"iss": "kroeg-call",
"sub": person.id(),
"exp": 0xFFFFFFFFu32
})
"iss": "kroeg-call",
"sub": person.id(),
"exp": 0xFFFFFFFFu32
})
.to_string()
.as_bytes(),
base64::URL_SAFE_NO_PAD

+ 5
- 1
src/delivery.rs View File

@@ -170,7 +170,11 @@ pub fn deliver_one<T: EntityStore, R: QueueStore>(
};

let (store, context, data) = if is_local {
(store, context, json!({ "@id": sdata.id(), "@type": [kroeg!(DeliveryObject)] }))
(
store,
context,
json!({ "@id": sdata.id(), "@type": [kroeg!(DeliveryObject)] }),
)
} else {
let (_, store, _, data) = await!(assemble(
sdata.clone(),

+ 1
- 1
src/get.rs View File

@@ -137,7 +137,7 @@ pub fn get<T: EntityStore, R: QueueStore>(
let response = response
.status(404)
.body(json!({
"@type": "https://puckipedia.com/kroeg/ns#NotFound",
"@type": "https://puckipedia.com/kroeg/ns#NotFound",
as2!(content): "Not found"
}))
.unwrap();

+ 74
- 97
src/lib.rs View File

@@ -11,7 +11,6 @@ extern crate kroeg_tap;

extern crate base64;
extern crate chashmap;
extern crate diesel;
extern crate dotenv;
extern crate futures_await as futures;
extern crate http;
@@ -38,7 +37,6 @@ pub mod router;
mod store;
pub mod webfinger;

use diesel::prelude::*;
use futures::{prelude::*, stream, Stream};

use authentication::user_from_request;
@@ -46,7 +44,7 @@ use futures::future;
use hyper::service::{NewService, Service};
use hyper::{Body, Request, Response, StatusCode};
use jsonld::error::{CompactionError, ExpansionError};
use kroeg_cellar::QuadClient;
use kroeg_cellar::CellarEntityStore;
use kroeg_tap::{Context, EntityStore, QueueStore};
use router::Route;
use serde_json::Value;
@@ -104,7 +102,7 @@ impl<T: EntityStore> error::Error for ServerError<T> {
#[derive(Clone)]
pub struct KroegService {
config: config::Config,
routes: Vec<Route<RetrievingEntityStore<QuadClient>, QuadClient>>,
routes: Vec<Route<RetrievingEntityStore<CellarEntityStore>, CellarEntityStore>>,
}

/// Helper function, that allows the router to fall back to 404 easily.
@@ -125,30 +123,20 @@ fn not_found<T: EntityStore, R: QueueStore>(
pub fn launch_delivery(config: config::Config) -> impl Future<Item = (), Error = ()> + Send {
stream::repeat(config)
.fold(0, |iteration, config| {
let (store, queue) = match (
PgConnection::establish(&config.database),
PgConnection::establish(&config.database),
) {
(Ok(store_db), Ok(queue_db)) => (
RetrievingEntityStore::new(
QuadClient::new(store_db),
config.server.base_uri.to_owned(),
),
QuadClient::new(queue_db),
),

(Err(e), _) | (_, Err(e)) => {
panic!("Database connection failed: {}", e);
}
};

let context = Context {
server_base: config.server.base_uri.to_owned(),
instance_id: config.server.instance_id,
user: authentication::anonymous(),
};

delivery::loop_deliver(context, store, queue, iteration).map(move |_| iteration + 1)
CellarEntityStore::new(&config.database)
.map_err(|e| panic!(e))
.and_then(move |store| {
let queue = ();

let context = Context {
server_base: config.server.base_uri.to_owned(),
instance_id: config.server.instance_id,
user: authentication::anonymous(),
};

delivery::loop_deliver(context, store, queue, iteration)
.map(move |_| iteration + 1)
})
})
.map(|_| ())
}
@@ -157,79 +145,68 @@ impl Service for KroegService {
type ReqBody = Body;
type ResBody = Body;

type Error = ServerError<RetrievingEntityStore<QuadClient>>;
type Error = ServerError<RetrievingEntityStore<CellarEntityStore>>;
type Future = Box<Future<Item = Response<Body>, Error = Self::Error> + Send>;

fn call(&mut self, req: Request<Body>) -> Self::Future {
let base = self.config.server.base_uri.to_owned();
let config = self.config.clone();
let routes = self.routes.clone();
let db = self.config.database.clone();
// When an incoming request gets handled, the first thing needed is connections to the database.
// For legacy design reasons, for now, we'll open two connections. One for the quad store, one for the queue.
let (store, queue) = match (
PgConnection::establish(&self.config.database),
PgConnection::establish(&self.config.database),
) {
(Ok(store_db), Ok(queue_db)) => (
RetrievingEntityStore::new(
QuadClient::new(store_db),
self.config.server.base_uri.to_owned(),
),
QuadClient::new(queue_db),
),

(Err(e), _) | (_, Err(e)) => {
eprintln!("Database connection failed: {}", e);

return Box::new(future::ok(
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("Database connection failed."))
.unwrap(),
));
}
};

let routes = self.routes.clone();
let (parts, body) = req.into_parts();

Box::new(
user_from_request(self.config.clone(), parts, store)
.then(move |result| match result {
Ok((config, parts, store, user)) => {
let request = Request::from_parts(parts, body);

let context = Context {
server_base: config.server.base_uri.to_owned(),
instance_id: config.server.instance_id,
user: user,
};

let route = routes
.iter()
.rev()
.find(|f| f.can_handle(&request))
.map(|f| f.handler.clone())
.unwrap_or_else(|| Arc::new(Box::new(not_found)));

route(context, store, queue, request)
}

Err((e, store)) => Box::new(future::err((ServerError::StoreError(e), store))),
})
// Handlers return a tuple (EntityStore, QueueStore, Response) but we need to return a Response<Body>.
// so, we drop the EntityStore and QueueStore. (note to self: bring transactions back)
.then(|result| {
match result {
Ok((.., response)) => Ok(response),
Err((err, _)) => {
eprintln!("Error handling request: {}", err);

// If the Service returns an error, the connection with the client will just drop.
// This doesn't seem like the best way to go, so return a 500 instead.
Ok(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from(format!("error: {}", err)))
.unwrap())
}
}
CellarEntityStore::new(&self.config.database)
.and_then(move |store| CellarEntityStore::new(&db).map(move |s| (store, s)))
.map_err(|e| {
println!("{:?}", e);
panic!(e)
}) //ServerError::HandlerError(e.into()))
.and_then(move |(store, queue)| {
let store = RetrievingEntityStore::new(store, base);
let (parts, body) = req.into_parts();
user_from_request(config, parts, store)
.then(move |result| match result {
Ok((config, parts, store, user)) => {
let request = Request::from_parts(parts, body);

let context = Context {
server_base: config.server.base_uri.to_owned(),
instance_id: config.server.instance_id,
user: user,
};

let route = routes
.iter()
.rev()
.find(|f| f.can_handle(&request))
.map(|f| f.handler.clone())
.unwrap_or_else(|| Arc::new(Box::new(not_found)));

route(context, store, queue, request)
}

Err((e, store)) => {
Box::new(future::err((ServerError::StoreError(e), store)))
}
})
// Handlers return a tuple (EntityStore, QueueStore, Response) but we need to return a Response<Body>.
// so, we drop the EntityStore and QueueStore. (note to self: bring transactions back)
.then(|result| {
match result {
Ok((.., response)) => Ok(response),
Err((err, _)) => {
eprintln!("Error handling request: {}", err);

// If the Service returns an error, the connection with the client will just drop.
// This doesn't seem like the best way to go, so return a 500 instead.
Ok(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from(format!("error: {}", err)))
.unwrap())
}
}
})
}),
)
}
@@ -237,13 +214,13 @@ impl Service for KroegService {

pub struct KroegServiceBuilder {
pub config: config::Config,
pub routes: Vec<Route<RetrievingEntityStore<QuadClient>, QuadClient>>,
pub routes: Vec<Route<RetrievingEntityStore<CellarEntityStore>, CellarEntityStore>>,
}

impl NewService for KroegServiceBuilder {
type ReqBody = Body;
type ResBody = Body;
type Error = ServerError<RetrievingEntityStore<QuadClient>>;
type Error = ServerError<RetrievingEntityStore<CellarEntityStore>>;
type Service = KroegService;
type Future = future::FutureResult<KroegService, Self::Error>;
type InitError = Self::Error;

+ 6
- 1
src/router.rs View File

@@ -8,7 +8,12 @@ use super::ServerError;

/// An alias for the function type of the request handler that is expected to be implemented.
pub type RequestHandler<T, R> = Box<
Fn(Context, T, R, Request<Body>)
Fn(
Context,
T,
R,
Request<Body>,
)
-> Box<Future<Item = (T, R, Response<Body>), Error = (ServerError<T>, T)> + Send + 'static>
+ Send
+ Sync,

+ 15
- 8
src/store.rs View File

@@ -124,8 +124,9 @@ fn retrieve_and_store<T: EntityStore>(

fn make_retrieving<T, Q, E: EntityStore>(
base: String,
) -> impl FnOnce(Result<(T, E), (Q, E)>)
-> Result<(T, RetrievingEntityStore<E>), (Q, RetrievingEntityStore<E>)> {
) -> impl FnOnce(
Result<(T, E), (Q, E)>,
) -> Result<(T, RetrievingEntityStore<E>), (Q, RetrievingEntityStore<E>)> {
move |f| match f {
Ok((item, store)) => Ok((item, RetrievingEntityStore(store, base))),
Err((item, store)) => Err((item, RetrievingEntityStore(store, base))),
@@ -150,8 +151,14 @@ impl<T: EntityStore> EntityStore for RetrievingEntityStore<T> {
Box<Future<Item = (StoreItem, Self), Error = (Self::Error, Self)> + 'static + Send>;
type ReadCollectionFuture =
Box<Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)> + 'static + Send>;
type FindCollectionFuture =
Box<Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)> + 'static + Send>;
type ReadCollectionInverseFuture =
Box<Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)> + 'static + Send>;
type WriteCollectionFuture =
Box<Future<Item = Self, Error = (Self::Error, Self)> + 'static + Send>;
type RemoveCollectionFuture =
Box<Future<Item = Self, Error = (Self::Error, Self)> + 'static + Send>;
type QueryFuture =
Box<Future<Item = (Vec<Vec<String>>, Self), Error = (Self::Error, Self)> + 'static + Send>;

@@ -181,9 +188,9 @@ impl<T: EntityStore> EntityStore for RetrievingEntityStore<T> {
StoreItem::parse(
as2!(Public),
json!({
"@id": as2!(Public),
"@type": [as2!(Collection)]
}),
"@id": as2!(Public),
"@type": [as2!(Collection)]
}),
)
.ok(),
store,
@@ -236,7 +243,7 @@ impl<T: EntityStore> EntityStore for RetrievingEntityStore<T> {
)
}

fn read_collection_inverse(self, item: String) -> Self::ReadCollectionFuture {
fn read_collection_inverse(self, item: String) -> Self::ReadCollectionInverseFuture {
Box::new(
self.0
.read_collection_inverse(item)
@@ -245,7 +252,7 @@ impl<T: EntityStore> EntityStore for RetrievingEntityStore<T> {
)
}

fn find_collection(self, path: String, item: String) -> Self::ReadCollectionFuture {
fn find_collection(self, path: String, item: String) -> Self::FindCollectionFuture {
Box::new(
self.0
.find_collection(path, item)
@@ -263,7 +270,7 @@ impl<T: EntityStore> EntityStore for RetrievingEntityStore<T> {
)
}

fn remove_collection(self, path: String, item: String) -> Self::WriteCollectionFuture {
fn remove_collection(self, path: String, item: String) -> Self::RemoveCollectionFuture {
Box::new(
self.0
.remove_collection(path, item)

+ 8
- 8
src/webfinger.rs View File

@@ -79,14 +79,14 @@ fn handle_webfinger<T: EntityStore, R: QueueStore>(
let uri: Uri = user.id().parse().unwrap();

let response = json!({
"subject": format!("acct:{}@{}", username, uri.authority_part().unwrap()),
"aliases": [user.id()],
"links": [{
"rel": "self",
"type": "application/activity+json",
"href": user.id()
}]
});
"subject": format!("acct:{}@{}", username, uri.authority_part().unwrap()),
"aliases": [user.id()],
"links": [{
"rel": "self",
"type": "application/activity+json",
"href": user.id()
}]
});

Response::builder()
.status(200)

Loading…
Cancel
Save