Add redis connection to all models

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent 8890c048f0
commit f571f062fa
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1 +1,2 @@
POSTGRES_CONNECTION_URL = "postgres://flotte_userdb:flottedev@localhost/flotte_usersdb"
POSTGRES_CONNECTION_URL = "postgres://flotte_userdb:flottedev@localhost/flotte_usersdb"
REDIS_CONNECTION_URL = "redis://127.0.0.1/"

@ -13,14 +13,16 @@
</component>
<component name="ChangeListManager">
<list default="true" id="db10ba0c-1d72-449d-b24f-24b5a4951941" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/database/permissions.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/database/role_permissions.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/database/roles.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/database/user_roles.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/permissions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/permissions.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/role_permissions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/role_permissions.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/roles.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/roles.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/user_roles.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/user_roles.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/users.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/users.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -91,7 +93,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1599728150675</updated>
<workItem from="1599728152100" duration="4301000" />
<workItem from="1599728152100" duration="5535000" />
</task>
<servers />
</component>
@ -103,22 +105,22 @@
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state x="769" y="295" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732127954" />
<state width="1874" height="304" key="GridCell.Tab.0.bottom" timestamp="1599732449376">
<state width="1874" height="304" key="GridCell.Tab.0.bottom" timestamp="1599733668118">
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state width="1874" height="304" key="GridCell.Tab.0.bottom/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732449376" />
<state width="1874" height="304" key="GridCell.Tab.0.center" timestamp="1599732449376">
<state width="1874" height="304" key="GridCell.Tab.0.bottom/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599733668118" />
<state width="1874" height="304" key="GridCell.Tab.0.center" timestamp="1599733668118">
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state width="1874" height="304" key="GridCell.Tab.0.center/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732449376" />
<state width="1874" height="304" key="GridCell.Tab.0.left" timestamp="1599732449376">
<state width="1874" height="304" key="GridCell.Tab.0.center/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599733668118" />
<state width="1874" height="304" key="GridCell.Tab.0.left" timestamp="1599733668118">
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state width="1874" height="304" key="GridCell.Tab.0.left/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732449376" />
<state width="1874" height="304" key="GridCell.Tab.0.right" timestamp="1599732449376">
<state width="1874" height="304" key="GridCell.Tab.0.left/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599733668118" />
<state width="1874" height="304" key="GridCell.Tab.0.right" timestamp="1599733668118">
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state width="1874" height="304" key="GridCell.Tab.0.right/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732449376" />
<state width="1874" height="304" key="GridCell.Tab.0.right/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599733668118" />
<state x="457" y="211" key="SettingsEditor" timestamp="1599731723387">
<screen x="0" y="0" width="1920" height="1158" />
</state>
@ -131,9 +133,9 @@
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state x="620" y="265" key="run.anything.popup/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599731922994" />
<state x="623" y="256" width="672" height="678" key="search.everywhere.popup" timestamp="1599730769441">
<state x="623" y="256" width="672" height="678" key="search.everywhere.popup" timestamp="1599732839101">
<screen x="0" y="0" width="1920" height="1158" />
</state>
<state x="623" y="256" width="672" height="678" key="search.everywhere.popup/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599730769441" />
<state x="623" y="256" width="672" height="678" key="search.everywhere.popup/0.0.1920.1158/1920.0.1680.1050@0.0.1920.1158" timestamp="1599732839101" />
</component>
</project>

429
Cargo.lock generated

@ -1,5 +1,91 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "async-channel"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21279cfaa4f47df10b1816007e738ca3747ef2ee53ffc51cdbf57a8bb266fee3"
dependencies = [
"concurrent-queue",
"event-listener",
"futures-core",
]
[[package]]
name = "async-executor"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90f47c78ea98277cb1f5e6f60ba4fc762f5eafe9f6511bc2f7dfd8b75c225650"
dependencies = [
"async-io",
"futures-lite",
"multitask",
"parking 1.0.6",
"scoped-tls",
"waker-fn",
]
[[package]]
name = "async-io"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae22a338d28c75b53702b66f77979062cb29675db376d99e451af4fa79dedb3"
dependencies = [
"cfg-if",
"concurrent-queue",
"futures-lite",
"libc",
"once_cell",
"parking 2.0.0",
"polling",
"socket2",
"vec-arena",
"wepoll-sys-stjepang",
"winapi 0.3.9",
]
[[package]]
name = "async-mutex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66941c2577c4fa351e4ce5fdde8f86c69b88d623f3b955be1bc7362a23434632"
dependencies = [
"event-listener",
]
[[package]]
name = "async-std"
version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46c8da367da62b8ff2313c406c9ac091c1b31d67a165becdd2de380d846260f7"
dependencies = [
"async-executor",
"async-io",
"async-mutex",
"async-task",
"blocking",
"crossbeam-utils",
"futures-channel",
"futures-core",
"futures-io",
"futures-lite",
"kv-log-macro",
"log",
"memchr",
"num_cpus",
"once_cell",
"pin-project-lite",
"pin-utils",
"slab",
"wasm-bindgen-futures",
]
[[package]]
name = "async-task"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3"
[[package]]
name = "async-trait"
version = "0.1.40"
@ -11,6 +97,12 @@ dependencies = [
"syn",
]
[[package]]
name = "atomic-waker"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
[[package]]
name = "autocfg"
version = "1.0.1"
@ -38,12 +130,31 @@ dependencies = [
"generic-array",
]
[[package]]
name = "blocking"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea5800d29218fea137b0880387e5948694a23c93fcdde157006966693a865c7c"
dependencies = [
"async-channel",
"atomic-waker",
"futures-lite",
"once_cell",
"waker-fn",
]
[[package]]
name = "build_const"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
[[package]]
name = "bumpalo"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "byteorder"
version = "1.3.4"
@ -56,6 +167,18 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "cache-padded"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba"
[[package]]
name = "cc"
version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381"
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -71,6 +194,28 @@ dependencies = [
"bitflags",
]
[[package]]
name = "combine"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2809f67365382d65fd2b6d9c22577231b954ed27400efeafbe687bda75abcc0b"
dependencies = [
"bytes",
"futures-util",
"memchr",
"pin-project-lite",
"tokio",
]
[[package]]
name = "concurrent-queue"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
dependencies = [
"cache-padded",
]
[[package]]
name = "cpuid-bool"
version = "0.1.2"
@ -122,12 +267,30 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "dtoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
[[package]]
name = "event-listener"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cd41440ae7e4734bbd42302f63eaba892afc93a3912dad84006247f0dedb0e"
[[package]]
name = "fallible-iterator"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "fastrand"
version = "1.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c85295147490b8fcf2ea3d104080a105a8b2c63f9c319e82c02d8e952388919"
[[package]]
name = "flotte-user-management"
version = "0.1.0"
@ -135,8 +298,15 @@ dependencies = [
"dotenv",
"msgrpc",
"postgres",
"redis",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
@ -201,6 +371,21 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
[[package]]
name = "futures-lite"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97999970129b808f0ccba93211201d431fcc12d7e1ffae03a61b5cedd1a7ced2"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"parking 2.0.0",
"pin-project-lite",
"waker-fn",
]
[[package]]
name = "futures-macro"
version = "0.3.5"
@ -269,6 +454,15 @@ dependencies = [
"wasi",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
[[package]]
name = "hmac"
version = "0.8.1"
@ -279,6 +473,17 @@ dependencies = [
"digest",
]
[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "instant"
version = "0.1.6"
@ -294,6 +499,21 @@ dependencies = [
"libc",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@ -304,6 +524,15 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "kv-log-macro"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f"
dependencies = [
"log",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -407,6 +636,17 @@ dependencies = [
"serde",
]
[[package]]
name = "multitask"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c09c35271e7dcdb5f709779111f2c8e8ab8e06c1b587c1c6a9e179d865aaa5b4"
dependencies = [
"async-task",
"concurrent-queue",
"fastrand",
]
[[package]]
name = "net2"
version = "0.2.35"
@ -427,6 +667,16 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "once_cell"
version = "1.4.1"
@ -439,6 +689,18 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "parking"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb300f271742d4a2a66c01b6b2fa0c83dfebd2e0bf11addb879a3547b4ed87c"
[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "parking_lot"
version = "0.11.0"
@ -521,6 +783,19 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "polling"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fffa183f6bd5f1a8a3e1f60ce2f8d5621e350eed84a62d6daaa5b9d1aaf6fbd"
dependencies = [
"cfg-if",
"libc",
"log",
"wepoll-sys-stjepang",
"winapi 0.3.9",
]
[[package]]
name = "postgres"
version = "0.17.5"
@ -641,6 +916,27 @@ dependencies = [
"rand_core",
]
[[package]]
name = "redis"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95357caf2640abc54651b93c98a8df4fe1ccbf44b8e601ccdf43d5c1451f29ac"
dependencies = [
"async-std",
"async-trait",
"bytes",
"combine",
"dtoa",
"futures-util",
"itoa",
"percent-encoding",
"pin-project-lite",
"sha1",
"tokio",
"tokio-util",
"url",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
@ -668,6 +964,12 @@ dependencies = [
"serde",
]
[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -680,6 +982,12 @@ version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
[[package]]
name = "sha1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "sha2"
version = "0.9.1"
@ -711,6 +1019,18 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
[[package]]
name = "socket2"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi 0.3.9",
]
[[package]]
name = "stringprep"
version = "0.1.2"
@ -751,6 +1071,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd"
dependencies = [
"bytes",
"fnv",
"futures-core",
"iovec",
"lazy_static",
@ -828,18 +1149,126 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "url"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
dependencies = [
"idna",
"matches",
"percent-encoding",
]
[[package]]
name = "vec-arena"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cb18268690309760d59ee1a9b21132c126ba384f374c59a94db4bc03adeb561"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "waker-fn"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
[[package]]
name = "web-sys"
version = "0.3.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "wepoll-sys-stjepang"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694"
dependencies = [
"cc",
]
[[package]]
name = "winapi"
version = "0.2.8"

@ -9,4 +9,5 @@ edition = "2018"
[dependencies]
msgrpc = {path = "./msg-rpc"}
postgres = "0.17.5"
dotenv = "0.15.0"
dotenv = "0.15.0"
redis = "0.17.0"

@ -4,7 +4,8 @@ use crate::database::roles::Roles;
use crate::database::user_roles::UserRoles;
use crate::database::users::Users;
use dotenv;
use postgres::{Client, Error, NoTls};
use postgres::{Client, NoTls};
use redis::{RedisError, RedisResult};
use std::sync::{Arc, Mutex};
pub mod permissions;
@ -14,16 +15,36 @@ pub mod user_roles;
pub mod users;
const DB_CONNECTION_URL: &str = "POSTGRES_CONNECTION_URL";
const DEFAULT_CONNECTION: &str = "postgres://postgres:postgres@localhost/postgrees";
const DEFAULT_CONNECTION: &str = "postgres://postgres:postgres@localhost/postgres";
const REDIS_CONNECTION_URL: &str = "REDIS_CONNECTION_URL";
const DEFAULT_REDIS_CONNECTION: &str = "redis:://127.0.0.1/";
pub type DatabaseClient = postgres::Client;
pub type RedisClient = redis::Client;
pub type RedisConnection = redis::Connection;
pub type PostgresError = postgres::Error;
pub trait Model {
fn new(connection: Arc<Mutex<Client>>) -> Self;
fn init(&self) -> Result<(), Error>;
fn new(
database_connection: Arc<Mutex<DatabaseClient>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self;
fn init(&self) -> DatabaseResult<()>;
}
#[derive(Debug)]
pub enum Error {
Redis(RedisError),
Postgres(PostgresError),
}
pub type DatabaseError = Error;
pub type DatabaseResult<T> = Result<T, Error>;
#[derive(Clone)]
pub struct Database {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
pub users: Users,
pub roles: Roles,
pub permissions: Permissions,
@ -31,23 +52,42 @@ pub struct Database {
user_roles: UserRoles,
}
type PostgresResult<T> = Result<T, Error>;
impl Database {
pub fn new() -> PostgresResult<Self> {
let connection = Arc::new(Mutex::new(get_connection()?));
pub fn new() -> DatabaseResult<Self> {
let database_connection = Arc::new(Mutex::new(
get_database_connection().map_err(|e| Error::Postgres(e))?,
));
let redis_connection = Arc::new(Mutex::new(
get_redis_connection().map_err(|e| Error::Redis(e))?,
));
Ok(Self {
users: Users::new(Arc::clone(&connection)),
roles: Roles::new(Arc::clone(&connection)),
permissions: Permissions::new(Arc::clone(&connection)),
user_roles: UserRoles::new(Arc::clone(&connection)),
role_permission: RolePermissions::new(Arc::clone(&connection)),
connection,
users: Users::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
roles: Roles::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
permissions: Permissions::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
user_roles: UserRoles::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
role_permission: RolePermissions::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
database_connection,
redis_connection,
})
}
/// Inits all database models
pub fn init(&self) -> PostgresResult<()> {
pub fn init(&self) -> DatabaseResult<()> {
self.users.init()?;
self.roles.init()?;
self.permissions.init()?;
@ -58,7 +98,14 @@ impl Database {
}
}
/// Returns a database connection
fn get_connection() -> Result<Client, Error> {
fn get_database_connection() -> Result<DatabaseClient, PostgresError> {
let conn_url = dotenv::var(DB_CONNECTION_URL).unwrap_or(DEFAULT_CONNECTION.to_string());
Client::connect(conn_url.as_str(), NoTls)
}
fn get_redis_connection() -> RedisResult<RedisConnection> {
let conn_url =
dotenv::var(REDIS_CONNECTION_URL).unwrap_or(DEFAULT_REDIS_CONNECTION.to_string());
let client = RedisClient::open(conn_url)?;
client.get_connection()
}

@ -1,24 +1,35 @@
use crate::database::Model;
use postgres::{Client, Error};
use crate::database::{DatabaseClient, DatabaseError, DatabaseResult, Model, RedisConnection};
use postgres::Client;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct Permissions {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<DatabaseClient>>,
redis_connection: Arc<Mutex<RedisConnection>>,
}
impl Model for Permissions {
fn new(connection: Arc<Mutex<Client>>) -> Self {
Self { connection }
fn new(
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
database_connection,
redis_connection,
}
}
fn init(&self) -> Result<(), Error> {
self.connection.lock().unwrap().batch_execute(
"CREATE TABLE IF NOT EXISTS permissions (
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"CREATE TABLE IF NOT EXISTS permissions (
id SERIAL PRIMARY KEY,
name VARCHAR(128) UNIQUE NOT NULL,
description VARCHAR(512)
);",
)
)
.map_err(|e| DatabaseError::Postgres(e))
}
}

@ -1,25 +1,36 @@
use crate::database::Model;
use crate::database::{DatabaseClient, DatabaseError, DatabaseResult, Model, RedisConnection};
use postgres::{Client, Error};
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct RolePermissions {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<DatabaseClient>>,
redis_connection: Arc<Mutex<RedisConnection>>,
}
impl Model for RolePermissions {
fn new(connection: Arc<Mutex<Client>>) -> Self {
Self { connection }
fn new(
database_connection: Arc<Mutex<DatabaseClient>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
database_connection,
redis_connection,
}
}
fn init(&self) -> Result<(), Error> {
self.connection.lock().unwrap().batch_execute(
"
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"
CREATE TABLE IF NOT EXISTS role_permissions (
role_id INT NOT NULL REFERENCES roles(id) ON DELETE CASCADE,
permission_id INT NOT NULL REFERENCES permissions(id) ON DELETE CASCADE,
PRIMARY KEY (role_id, permission_id)
);",
)
)
.map_err(|e| DatabaseError::Postgres(e))
}
}

@ -1,30 +1,42 @@
use crate::database::role_permissions::RolePermissions;
use crate::database::Model;
use crate::database::{DatabaseError, DatabaseResult, Model, RedisConnection};
use postgres::{Client, Error};
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct Roles {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
role_permission: RolePermissions,
}
impl Model for Roles {
fn new(connection: Arc<Mutex<Client>>) -> Self {
fn new(
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
role_permission: RolePermissions::new(Arc::clone(&connection)),
connection,
role_permission: RolePermissions::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
database_connection,
redis_connection,
}
}
fn init(&self) -> Result<(), Error> {
self.connection.lock().unwrap().batch_execute(
"
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"
CREATE TABLE IF NOT EXISTS roles (
id SERIAL PRIMARY KEY,
name VARCHAR(128) UNIQUE NOT NULL,
description VARCHAR(512)
);",
)
)
.map_err(|e| DatabaseError::Postgres(e))
}
}

@ -1,25 +1,36 @@
use crate::database::Model;
use crate::database::{DatabaseError, DatabaseResult, Model, RedisConnection};
use postgres::{Client, Error};
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct UserRoles {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
}
impl Model for UserRoles {
fn new(connection: Arc<Mutex<Client>>) -> Self {
Self { connection }
fn new(
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
database_connection,
redis_connection,
}
}
fn init(&self) -> Result<(), Error> {
self.connection.lock().unwrap().batch_execute(
"
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"
CREATE TABLE IF NOT EXISTS user_roles (
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
role_id INT NOT NULL REFERENCES roles(id) ON DELETE CASCADE,
PRIMARY KEY (user_id, role_id)
);",
)
)
.map_err(|e| DatabaseError::Postgres(e))
}
}

@ -1,31 +1,43 @@
use crate::database::user_roles::UserRoles;
use crate::database::Model;
use crate::database::{DatabaseError, DatabaseResult, Model, RedisConnection};
use postgres::{Client, Error};
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct Users {
connection: Arc<Mutex<Client>>,
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
user_roles: UserRoles,
}
impl Model for Users {
fn new(connection: Arc<Mutex<Client>>) -> Self {
fn new(
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
user_roles: UserRoles::new(Arc::clone(&connection)),
connection,
user_roles: UserRoles::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
database_connection,
redis_connection,
}
}
fn init(&self) -> Result<(), Error> {
self.connection.lock().unwrap().batch_execute(
"CREATE TABLE IF NOT EXISTS users (
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(32) NOT NULL,
salt VARCHAR(16) NOT NULL
);",
)
)
.map_err(|e| DatabaseError::Postgres(e))
}
}

Loading…
Cancel
Save