diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-05-21 17:37:40 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-05-21 17:37:40 -0400 |
commit | d2da324c4c15db3b137fbeaebf0568f65eb2ad67 (patch) | |
tree | 343c82fe672a0ae94675ab2d0bf223af6b764350 | |
parent | bba5bbcf7729b5fbdf45473921d517b93a97b95d (diff) |
rip powerdns out of this shit
-rw-r--r-- | Cargo.lock | 455 | ||||
-rw-r--r-- | Cargo.toml | 21 | ||||
-rw-r--r-- | migrations/2022-04-09-create-schema.sql | 23 | ||||
-rw-r--r-- | src/db/mod.rs | 1 | ||||
-rw-r--r-- | src/db/models.rs | 8 | ||||
-rw-r--r-- | src/db/strings.rs | 11 | ||||
-rw-r--r-- | src/db/zones.rs | 38 | ||||
-rw-r--r-- | src/extractors.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 29 | ||||
-rw-r--r-- | src/routes/v1/mod.rs | 1 | ||||
-rw-r--r-- | src/routes/v1/users.rs | 16 | ||||
-rw-r--r-- | src/routes/v1/zones.rs | 45 |
12 files changed, 197 insertions, 456 deletions
@@ -3,16 +3,6 @@ version = 3 [[package]] -name = "addr" -version = "0.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4299322d87d6ae73d3bd74918983e712acc3a1b73c880258eb5a0b45895e7b85" -dependencies = [ - "psl", - "psl-types", -] - -[[package]] name = "ahash" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -34,9 +24,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" [[package]] name = "async-trait" @@ -66,9 +56,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.1" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47594e438a243791dba58124b6669561f5baa14cb12046641d8008bf035e5a25" +checksum = "ab2504b827a8bef941ba3dd64bdffe9cf56ca182908a147edd6189c95fbcae7d" dependencies = [ "async-trait", "axum-core", @@ -97,9 +87,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a671c9ae99531afdd5d3ee8340b8da547779430689947144c140fc74a740244" +checksum = "da31c0ed7b4690e2c78fe4b880d21cd7db04a346ebc658b4270251b695437f17" dependencies = [ "async-trait", "bytes", @@ -123,9 +113,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bcrypt" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe4fef31efb0f76133ae8e3576a88e58edb7cfc5584c81c758c349ba46b43fc" +checksum = "a7e7c93a3fb23b2fdde989b2c9ec4dd153063ec81f408507f84c090cd91c6641" dependencies = [ "base64", "blowfish", @@ -213,20 +203,10 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" +name = "constant_time_eq" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "0e31aa570361918e61453e3b5377976b23e4599e8bb5b840380ecd3a20e691d2" [[package]] name = "cpufeatures" @@ -283,41 +263,6 @@ dependencies = [ ] [[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core", - "quote", - "syn", -] - -[[package]] name = "digest" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -370,30 +315,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if", -] - -[[package]] name = "event-listener" version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" [[package]] -name = "fastrand" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] - -[[package]] name = "fdns-api" version = "0.1.0" dependencies = [ @@ -407,7 +334,6 @@ dependencies = [ "lazy_static", "log", "mime", - "powerdns", "rand", "serde", "serde_json", @@ -428,21 +354,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] name = "form_urlencoded" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -526,25 +437,6 @@ dependencies = [ ] [[package]] -name = "h2" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -606,9 +498,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ "bytes", "fnv", @@ -654,7 +546,6 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", "http", "http-body", "httparse", @@ -669,25 +560,6 @@ dependencies = [ ] [[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] name = "idna" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -727,12 +599,6 @@ dependencies = [ ] [[package]] -name = "ipnet" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" - -[[package]] name = "itertools" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -795,9 +661,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -865,24 +731,6 @@ dependencies = [ ] [[package]] -name = "native-tls" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] name = "nom" version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -937,39 +785,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] -name = "openssl" -version = "0.10.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] name = "parking_lot" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1062,23 +877,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - -[[package]] -name = "powerdns" -version = "0.1.1" -dependencies = [ - "addr", - "reqwest", - "serde", - "serde_json", - "serde_with", -] - -[[package]] name = "ppv-lite86" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1094,21 +892,6 @@ dependencies = [ ] [[package]] -name = "psl" -version = "2.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225f78819a91cd34ee8f6c21e2b70c82fa72995408bbbf3414827a920c338ea2" -dependencies = [ - "psl-types", -] - -[[package]] -name = "psl-types" -version = "2.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" - -[[package]] name = "quote" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1168,51 +951,6 @@ dependencies = [ ] [[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - -[[package]] -name = "reqwest" -version = "0.11.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "native-tls", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - -[[package]] name = "ring" version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1241,28 +979,12 @@ dependencies = [ ] [[package]] -name = "rustversion" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" - -[[package]] name = "ryu" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi", -] - -[[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1279,42 +1001,19 @@ dependencies = [ ] [[package]] -name = "security-framework" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -1323,9 +1022,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa", "ryu", @@ -1345,29 +1044,6 @@ dependencies = [ ] [[package]] -name = "serde_with" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "946fa04a8ac43ff78a1f4b811990afb9ddbdf5890b46d6dda0ba1998230138b7" -dependencies = [ - "rustversion", - "serde", - "serde_with_macros", -] - -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] name = "sha-1" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1408,12 +1084,6 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" - -[[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1551,12 +1221,6 @@ dependencies = [ ] [[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] name = "subtle" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1580,20 +1244,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" [[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", -] - -[[package]] name = "thiserror" version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1649,9 +1299,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.17.0" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ "bytes", "libc", @@ -1679,16 +1329,6 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] name = "tokio-rustls" version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1721,16 +1361,16 @@ dependencies = [ "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "totp-rs" -version = "0.7.4" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09dc5fcc745500594f90020fdbcbbff029d1ca1f08f2940617f7ab697c17729" +checksum = "665c8ac1c4280d5e2deb982cf2ee8b90df0e86cf5234acaaef5b785cb1150040" dependencies = [ "base32", + "constant_time_eq", "hmac", "sha-1", "sha2", @@ -1755,9 +1395,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.2.5" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aba3f3efabf7fb41fae8534fc20a817013dd1c12cb45441efb6c82e6556b4cd8" +checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" dependencies = [ "bitflags", "bytes", @@ -1794,22 +1434,10 @@ dependencies = [ "cfg-if", "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] [[package]] -name = "tracing-attributes" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] name = "tracing-core" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1924,12 +1552,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1983,18 +1605,6 @@ dependencies = [ ] [[package]] -name = "wasm-bindgen-futures" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] name = "wasm-bindgen-macro" version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2128,15 +1738,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - -[[package]] name = "zeroize" version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -6,28 +6,27 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0.56" -axum = "0.5.1" -bcrypt = "0.12.1" +anyhow = "1.0.57" +axum = "0.5.6" +bcrypt = "0.13.0" chrono = { version = "0.4.19", features = ["serde"] } dotenvy = "0.15.1" hmac = "0.12.1" jwt = "0.16.0" lazy_static = "1.4.0" -log = "0.4.16" +log = "0.4.17" mime = "0.3.16" -#powerdns = "0.1.1" -powerdns = { path = "../powerdns/" } rand = "0.8.5" -serde = { version = "1.0.136", features = ["derive"] } -serde_json = "1.0.79" +serde = { version = "1.0.137", features = ["derive"] } +serde_json = "1.0.81" sha2 = "0.10.2" sqlx = { version = "0.5.13", features = ["postgres", "runtime-tokio-rustls", "chrono", "uuid"] } -tokio = { version = "1.17.0", features = ["full"] } -totp-rs = "0.7.4" +tokio = { version = "1.18.2", features = ["full"] } +totp-rs = "1.4.0" tower = "0.4.12" -tower-http = { version = "0.2.5", features = ["cors", "trace"] } +tower-http = { version = "0.3.3", features = ["cors", "trace"] } tracing-subscriber = "0.3.11" +# uuid v1.0.0 is out, but it breaks sqlx... we just have to wait for sqlx to release v0.6 uuid = { version = "0.8.2", features = ["serde", "v4"] } [features] diff --git a/migrations/2022-04-09-create-schema.sql b/migrations/2022-04-09-create-schema.sql index 720f3fa..786710d 100644 --- a/migrations/2022-04-09-create-schema.sql +++ b/migrations/2022-04-09-create-schema.sql @@ -1,6 +1,6 @@ CREATE extension IF NOT EXISTS "uuid-ossp"; -CREATE TABLE users ( +CREATE TABLE IF NOT EXISTS users ( id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), email varchar(255) NOT NULL UNIQUE, password varchar(255) NOT NULL, @@ -9,10 +9,11 @@ CREATE TABLE users ( modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), admin boolean NOT NULL DEFAULT false, enabled boolean NOT NULL DEFAULT true, - totp_secret varchar(255) + totp_secret varchar(255), + totp_confirmed boolean NOT NULL default false ); -CREATE TABLE zones ( +CREATE TABLE IF NOT EXISTS zones ( id varchar(255) NOT NULL UNIQUE PRIMARY KEY, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), @@ -20,6 +21,17 @@ CREATE TABLE zones ( constraint owner_uuid_fk foreign key (owner_uuid) references users (id) ); +CREATE TABLE IF NOT EXISTS records ( + id SERIAL PRIMARY KEY, + zone_id varchar(255) NOT NULL, + type varchar(16) NOT NULL, + content TEXT NOT NULL, + ttl INTEGER NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + constraint zone_id_fk foreign key (zone_id) references zones (id) +); + CREATE OR REPLACE FUNCTION update_modified_column() RETURNS TRIGGER AS $$ BEGIN @@ -28,5 +40,6 @@ BEGIN END; $$ language 'plpgsql'; -CREATE TRIGGER update_user_modtime BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); -CREATE TRIGGER update_zone_modtime BEFORE UPDATE ON zones FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); +CREATE OR REPLACE TRIGGER update_user_modtime BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); +CREATE OR REPLACE TRIGGER update_zone_modtime BEFORE UPDATE ON zones FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); +CREATE OR REPLACE TRIGGER update_record_modtime BEFORE UPDATE ON records FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); diff --git a/src/db/mod.rs b/src/db/mod.rs index 70e4a23..fc37f5e 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1,4 +1,5 @@ pub mod users; +pub mod zones; mod models; mod strings; diff --git a/src/db/models.rs b/src/db/models.rs index eec5a41..0d52768 100644 --- a/src/db/models.rs +++ b/src/db/models.rs @@ -17,3 +17,11 @@ pub struct User { #[serde(skip_serializing)] pub totp_secret: Option<String>, } + +#[derive(Serialize, Deserialize, FromRow, Debug)] +pub struct Zone { + pub id: String, + pub owner_uuid: Uuid, + pub created_at: DateTime<Utc>, + pub modified_at: DateTime<Utc>, +} diff --git a/src/db/strings.rs b/src/db/strings.rs index 45b8575..ebaa8c7 100644 --- a/src/db/strings.rs +++ b/src/db/strings.rs @@ -13,4 +13,15 @@ lazy_static! { pub(crate) static ref CREATE_USER: &'static str = r" INSERT INTO users(email,password,display_name) VALUES ($1, $2, $3) RETURNING * "; + pub(crate) static ref CREATE_ZONE: &'static str = r" + INSERT INTO zones(id,owner_uuid) VALUES ($1, $2) RETURNING * + "; + pub(crate) static ref GET_ZONES: &'static str = r" + SELECT id,owner_uuid,created_at,modified_at + FROM zones WHERE owner_uuid = $1 + "; + pub(crate) static ref GET_ZONE: &'static str = r" + SELECT id,owner_uuid,created_at,modified_at + FROM zones WHERE id = $1 + "; } diff --git a/src/db/zones.rs b/src/db/zones.rs new file mode 100644 index 0000000..0813bff --- /dev/null +++ b/src/db/zones.rs @@ -0,0 +1,38 @@ +use crate::db::models::Zone; +use crate::db::strings; +use sqlx::types::Uuid; +use sqlx::{Pool, Postgres}; + +pub async fn create_zone( + pool: &Pool<Postgres>, + id: &str, + owner_uuid: Uuid, +) -> Result<Zone, sqlx::Error> { + let mut transaction = pool.begin().await?; + let zone = sqlx::query_as::<_, Zone>(&strings::CREATE_ZONE) + .bind(id) + .bind(owner_uuid) + .fetch_one(&mut transaction) + .await?; + transaction.commit().await?; + Ok(zone) +} + +pub async fn get_zones(pool: &Pool<Postgres>, owner_uuid: Uuid) -> Result<Vec<Zone>, sqlx::Error> { + let zones = sqlx::query_as::<_, Zone>(&strings::GET_ZONES) + .bind(owner_uuid) + .fetch_all(pool) + .await?; + Ok(zones) +} + +pub async fn get_zone( + pool: &Pool<Postgres>, + id: &str, +) -> Result<Zone, sqlx::Error> { + let zone = sqlx::query_as::<_, Zone>(&strings::GET_ZONE) + .bind(id) + .fetch_one(pool) + .await?; + Ok(zone) +} diff --git a/src/extractors.rs b/src/extractors.rs index 907ba44..30e8235 100644 --- a/src/extractors.rs +++ b/src/extractors.rs @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; use serde_json::json; use serde_json::Value; use sha2::Sha256; +use sqlx::types::Uuid; use std::collections::BTreeMap; use std::env; use std::error::Error; @@ -26,7 +27,7 @@ pub struct Json<T>(pub T); #[derive(Debug, Serialize, Deserialize)] pub struct Token { pub iss: String, - pub sub: String, + pub sub: Uuid, pub iat: i64, pub exp: i64, pub dn: String, @@ -69,7 +70,7 @@ where let token = Token { iss: claims.get("iss").unwrap().to_string(), - sub: claims.get("sub").unwrap().to_string(), + sub: Uuid::parse_str(&claims.get("sub").unwrap().to_string()).unwrap(), iat: claims.get("iat").unwrap().parse().unwrap(), exp: claims.get("exp").unwrap().parse().unwrap(), dn: claims.get("dn").unwrap().to_string(), diff --git a/src/main.rs b/src/main.rs index 1816574..ba08cb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,21 +45,30 @@ async fn main() { "/api", Router::new().nest( "/v1", - Router::new().route("/", get(root)).nest( - "/users", - Router::new() - .route("/", post(routes::v1::users::create_user)) - .route("/all", get(routes::v1::users::get_all_users)) - .route("/totp", get(routes::v1::users::needs_totp)) - .route("/login", post(routes::v1::users::login)) - .route("/whoami", get(routes::v1::users::whoami)), - ), + Router::new() + .route("/", get(root)) + .nest( + "/users", + Router::new() + .route("/", post(routes::v1::users::create_user)) + .route("/", get(routes::v1::users::get_all_users)) + .route("/totp", get(routes::v1::users::needs_totp)) + .route("/login", post(routes::v1::users::login)) + .route("/whoami", get(routes::v1::users::whoami)), + ) + .nest( + "/zones", + Router::new() + .route("/", get(routes::v1::zones::list_zones)) + .route("/:id", post(routes::v1::zones::create_zone)) + .route("/:id", get(routes::v1::zones::get_zone)), + ), ), ) .layer( ServiceBuilder::new() .layer(TraceLayer::new_for_http()) - .layer(Extension(pg_pool)), + .layer(Extension(pg_pool)) ); let addr = SocketAddr::from(([0, 0, 0, 0], 8000)); diff --git a/src/routes/v1/mod.rs b/src/routes/v1/mod.rs index 616b7a6..9e3453c 100644 --- a/src/routes/v1/mod.rs +++ b/src/routes/v1/mod.rs @@ -1,3 +1,4 @@ pub mod users; +pub mod zones; mod requests; diff --git a/src/routes/v1/users.rs b/src/routes/v1/users.rs index 52e86f4..e3701eb 100644 --- a/src/routes/v1/users.rs +++ b/src/routes/v1/users.rs @@ -23,6 +23,13 @@ pub async fn create_user( Json(signup): Json<requests::Signup>, Extension(pool): Extension<Arc<Pool<Postgres>>>, ) -> impl IntoResponse { + // TODO: Potentially more checks for password strength + if signup.password.len() < 12 { + return ( + StatusCode::BAD_REQUEST, + Json(json!({"error": "Password must be at least 12 characters"})), + ); + } let user = db::users::create_user(&pool, &signup.email, &signup.password, &signup.display_name).await; match user { @@ -42,7 +49,14 @@ pub async fn create_user( } } -pub async fn get_all_users(Extension(pool): Extension<Arc<Pool<Postgres>>>) -> impl IntoResponse { +pub async fn get_all_users(Jwt(user): Jwt, Extension(pool): Extension<Arc<Pool<Postgres>>>) -> impl IntoResponse { + if !user.admin { + return ( + StatusCode::FORBIDDEN, + Json(json!({"error": "You do not have permission to perform this action"})), + ); + } + let users = db::users::get_all_users(&pool).await; match users { Ok(users) => (StatusCode::OK, Json(json!(users))), diff --git a/src/routes/v1/zones.rs b/src/routes/v1/zones.rs new file mode 100644 index 0000000..18e14ec --- /dev/null +++ b/src/routes/v1/zones.rs @@ -0,0 +1,45 @@ +use crate::db; +use crate::extractors::Json; +use crate::extractors::Jwt; +use axum::extract::Path; +use axum::http::StatusCode; +use axum::response::IntoResponse; +use axum::Extension; +use serde_json::json; +use sqlx::{Pool, Postgres}; +use std::sync::Arc; +use lazy_static::lazy_static; + +lazy_static!{ + static ref NAMESERVERS: Vec<String> = Vec::from([String::from("ns1.fdns.dev."), String::from("ns2.fdns.dev.")]); +} + +pub async fn list_zones( + Jwt(user): Jwt, + Extension(pool): Extension<Arc<Pool<Postgres>>>, +) -> impl IntoResponse { + let zones = db::zones::get_zones(&pool, user.sub).await; + match zones { + Ok(zones) => (StatusCode::OK, Json(json!(zones))), + Err(err) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": err.to_string()})), + ), + } +} + +pub async fn create_zone( + Path(_id): Path<String>, + Jwt(_user): Jwt, + Extension(_pool): Extension<Arc<Pool<Postgres>>>, +) -> impl IntoResponse { + (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "Not implemented"}))); +} + +pub async fn get_zone( + Path(_id): Path<String>, + Jwt(_user): Jwt, + Extension(_pool): Extension<Arc<Pool<Postgres>>>, +) -> impl IntoResponse { + (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "Not implemented"}))); +} |