diff --git a/.gitignore b/.gitignore index 6b39d31..573792f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target +**/target .idea/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 1d02378..d49a76d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1383,6 +1383,7 @@ dependencies = [ "base64 0.22.1", "chrono", "config", + "lnvps_db", "log", "nostr", "pretty_env_logger", @@ -1390,10 +1391,20 @@ dependencies = [ "rocket", "serde", "serde_json", - "sqlx", "tokio", ] +[[package]] +name = "lnvps_db" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "serde", + "sqlx", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -1543,10 +1554,11 @@ dependencies = [ [[package]] name = "nostr" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56db234b2e07901e372f34e9463f91590579cd8e6dbd34ed2ccc7e461e4ba639" +checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d" dependencies = [ + "async-trait", "base64 0.22.1", "bech32", "bip39", diff --git a/Cargo.toml b/Cargo.toml index 8c2db7e..6c87c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,16 +7,16 @@ edition = "2021" name = "api" [dependencies] +lnvps_db = { path = "lnvps_db" } tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread", "macros"] } anyhow = "1.0.83" log = "0.4.21" -config = { version = "0.14.0", features = ["toml"] } +config = { version = "0.14.0", features = ["yaml"] } pretty_env_logger = "0.5.0" serde = { version = "1.0.213", features = ["derive"] } reqwest = { version = "0.12.8", features = ["json"] } serde_json = "1.0.132" -sqlx = { version = "0.8.2", features = ["mysql", "chrono", "migrate", "runtime-tokio"] } rocket = { version = "0.5.1", features = ["json"] } chrono = { version = "0.4.38", features = ["serde"] } -nostr = { version = "0.35.0", default-features = false, features = ["std"] } +nostr = { version = "0.36.0", default-features = false, features = ["std"] } base64 = "0.22.1" diff --git a/config.toml b/config.toml deleted file mode 100644 index f8adbd7..0000000 --- a/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -# MySQL database connection string -db = "mysql://root:root@localhost:3376/lnvps" \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..5ee4c72 --- /dev/null +++ b/config.yaml @@ -0,0 +1,2 @@ +# MySQL database connection string +db: "mysql://root:root@localhost:3376/lnvps" \ No newline at end of file diff --git a/dev_setup.sql b/dev_setup.sql index 4759d4e..0eb5e2a 100644 --- a/dev_setup.sql +++ b/dev_setup.sql @@ -1,5 +1,15 @@ -insert ignore into vm_host(id,kind,name,ip,cpu,memory,enabled,api_token) values(1, 0, "lab", "https://185.18.221.8:8006", 4, 4096*1024, 1, "root@pam!tester=c82f8a57-f876-4ca4-8610-c086d8d9d51c"); -insert ignore into vm_host_disk(id,host_id,name,size,kind,interface,enabled) values(1,1,"local-lvm",1000*1000*1000*1000, 0, 0, 1); -insert ignore into vm_os_image(id,name,enabled) values(1,"Ubuntu 24.04",1); -insert ignore into ip_range(id,cidr,enabled) values(1,"185.18.221.80/28",1); -insert ignore into vm_template(id,name,enabled,cpu,memory,disk_size,disk_id) values(1,"Basic",1,2,2048,1000*1000*1000*80,1); \ No newline at end of file +insert +ignore into vm_host_region(id,name,enabled) values(1,"uat",1); +insert +ignore into vm_host(id,kind,region_id,name,ip,cpu,memory,enabled,api_token) values(1, 0, 1, "lab", "https://185.18.221.8:8006", 4, 4096*1024, 1, "root@pam!tester=c82f8a57-f876-4ca4-8610-c086d8d9d51c"); +insert +ignore into vm_host_disk(id,host_id,name,size,kind,interface,enabled) values(1,1,"local-lvm",1000*1000*1000*1000, 0, 0, 1); +insert +ignore into vm_os_image(id,name,distribution,flavour,version,enabled,url) values(1,0,"Server","24.04",1,"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"); +insert +ignore into ip_range(id,cidr,enabled) values(1,"185.18.221.80/28",1); +insert +ignore into vm_cost_plan(id,name,amount,currency,interval_amount,interval_type) values(1,"tiny_monthly",3,"EUR",1,1); +insert +ignore into vm_template(id,name,enabled,cpu,memory,disk_size,disk_type,disk_interface,cost_plan_id,region_id) +values(1,"Tiny",1,2,1024*1024*2,1000*1000*1000*80,1,2,1,1); \ No newline at end of file diff --git a/lnvps_db/Cargo.lock b/lnvps_db/Cargo.lock new file mode 100644 index 0000000..c09645a --- /dev/null +++ b/lnvps_db/Cargo.lock @@ -0,0 +1,2019 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" + +[[package]] +name = "async-trait" +version = "0.1.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" + +[[package]] +name = "cc" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-targets 0.52.6", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +dependencies = [ + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" + +[[package]] +name = "hashlink" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +dependencies = [ + "hashbrown 0.14.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.1", +] + +[[package]] +name = "itoa" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "540654e97a3f4470a492cd30ff187bc95d89557a903a2bbf112e2fae98104ef2" + +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" + +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + +[[package]] +name = "lnvps_db" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "serde", + "sqlx", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlformat" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" +dependencies = [ + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93334716a037193fac19df402f8571269c84a00852f6a7066b5d2616dcd64d3e" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d8060b456358185f7d50c55d9b5066ad956956fddec42ee2e8567134a8936e" +dependencies = [ + "atoi", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.14.5", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cac0692bcc9de3b073e8d747391827297e075c7710ff6276d9f7a1f3d58c6657" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5b2cf34a45953bfd3daaf3db0f7a7878ab9b7a6b91b422d24a7a9e4c857b680" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "tracing", + "url", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tempfile" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "whoami" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" +dependencies = [ + "redox_syscall", + "wasite", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/lnvps_db/Cargo.toml b/lnvps_db/Cargo.toml new file mode 100644 index 0000000..8aefae0 --- /dev/null +++ b/lnvps_db/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "lnvps_db" +version = "0.1.0" +edition = "2021" + +[features] +default = ["mysql"] +mysql = ["sqlx/mysql"] + +[dependencies] +anyhow = "1.0.83" +sqlx = { version = "0.8.2", features = ["chrono", "migrate", "runtime-tokio"] } +serde = { version = "1.0.213", features = ["derive"] } +chrono = { version = "0.4.38", features = ["serde"] } +async-trait = "0.1.83" \ No newline at end of file diff --git a/migrations/20241103155733_init.sql b/lnvps_db/migrations/20241103155733_init.sql similarity index 52% rename from migrations/20241103155733_init.sql rename to lnvps_db/migrations/20241103155733_init.sql index 34a5fe5..41c314d 100644 --- a/migrations/20241103155733_init.sql +++ b/lnvps_db/migrations/20241103155733_init.sql @@ -1,36 +1,44 @@ create table users ( - id integer unsigned not null auto_increment primary key, - pubkey binary(32) not null, - created timestamp default current_timestamp -); -create table user_ssh_key -( - id integer unsigned not null auto_increment primary key, - name varchar(100) not null, - user_id integer unsigned not null, - created timestamp default current_timestamp, - key varchar(2048) not null, - - constraint fk_ssh_key_user_id foreign key (user_id) references users (id) + id integer unsigned not null auto_increment primary key, + pubkey binary(32) not null, + created timestamp default current_timestamp, + email varchar(200), + contact_nip4 bit(1) not null, + contact_nip17 bit(1) not null, + contact_email bit(1) not null, ); create unique index ix_user_pubkey on users (pubkey); +create unique index ix_user_email on users (email); +create table user_ssh_key +( + id integer unsigned not null auto_increment primary key, + name varchar(100) not null, + user_id integer unsigned not null, + created timestamp default current_timestamp, + key_data varchar(2048) not null, + + constraint fk_ssh_key_user foreign key (user_id) references users (id) +); create table vm_host_region ( - id integer unsigned not null auto_increment primary key, - name varchar(100) not null, - enabled bit(1) not null, + id integer unsigned not null auto_increment primary key, + name varchar(100) not null, + enabled bit(1) not null ); create table vm_host ( id integer unsigned not null auto_increment primary key, kind smallint unsigned not null, + region_id integer unsigned not null, name varchar(100) not null, ip varchar(250) not null, cpu bigint unsigned not null, memory bigint unsigned not null, enabled bit(1) not null, - api_token varchar(200) not null + api_token varchar(200) not null, + + constraint fk_host_region foreign key (region_id) references vm_host_region (id) ); create table vm_host_disk ( @@ -42,46 +50,58 @@ create table vm_host_disk interface smallint unsigned not null, enabled bit(1) not null, - constraint fk_vm_host_disk foreign key (host_id) references vm_host (id) + constraint fk_host_disk_host foreign key (host_id) references vm_host (id) ); create table vm_os_image ( - id integer unsigned not null auto_increment primary key, - name varchar(200) not null, - enabled bit(1) not null + id integer unsigned not null auto_increment primary key, + name varchar(200) not null, + distribution smallint unsigned not null, + flavour varchar(50) not null, + version varchar(50) not null, + enabled bit(1) not null, + url varchar(1024) not null, ); +create unique index ix_vm_os_image_name on vm_os_image (name); create table ip_range ( - id integer unsigned not null auto_increment primary key, - cidr varchar(200) not null, - enabled bit(1) not null + id integer unsigned not null auto_increment primary key, + cidr varchar(200) not null, + enabled bit(1) not null, + region_id integer unsigned not null, + + constraint fk_ip_range_region foreign key (region_id) references vm_host_region (id) ); create table vm_cost_plan ( - id integer unsigned not null auto_increment primary key, - name varchar(200) not null, - enabled bit(1) not null, - created timestamp default current_timestamp, - expires timestamp, - amount integer unsigned not null, - currency varchar(4) not null, - interval integer unsigned not null, - interval_type smallint unsigned not null, + id integer unsigned not null auto_increment primary key, + name varchar(200) not null, + created timestamp default current_timestamp, + amount integer unsigned not null, + currency varchar(4) not null, + interval_amount integer unsigned not null, + interval_type smallint unsigned not null ); +-- IE. VM Offers create table vm_template ( - id integer unsigned not null auto_increment primary key, - name varchar(200) not null, - enabled bit(1) not null, - created timestamp default current_timestamp, - expires timestamp, - cpu smallint unsigned not null, - memory bigint unsigned not null, - disk_size bigint unsigned not null, - disk_id integer unsigned not null, + id integer unsigned not null auto_increment primary key, + name varchar(200) not null, + enabled bit(1) not null, + created timestamp default current_timestamp, + expires timestamp, + cpu tinyint unsigned not null, + memory bigint unsigned not null, + disk_size bigint unsigned not null, + disk_type smallint unsigned not null, + disk_interface smallint unsigned not null, + cost_plan_id integer unsigned not null, + region_id integer unsigned not null, - constraint fk_vm_host_disk_id foreign key (disk_id) references vm_host_disk (id) + constraint fk_template_cost_plan foreign key (cost_plan_id) references vm_cost_plan (id), + constraint fk_template_region foreign key (region_id) references vm_template (id) ); +-- An instance of a VM create table vm ( id integer unsigned not null auto_increment primary key, @@ -121,7 +141,7 @@ create table vm_payment expires timestamp not null, amount bigint unsigned not null, invoice varchar(2048) not null, - time_value integer unsigned not null, + time_value bigint unsigned not null, is_paid bit(1) not null, constraint fk_vm_payment_vm foreign key (vm_id) references vm (id) diff --git a/lnvps_db/src/lib.rs b/lnvps_db/src/lib.rs new file mode 100644 index 0000000..2147728 --- /dev/null +++ b/lnvps_db/src/lib.rs @@ -0,0 +1,82 @@ +use anyhow::Result; +use async_trait::async_trait; + +mod model; +#[cfg(feature = "mysql")] +mod mysql; + +pub use model::*; +#[cfg(feature = "mysql")] +pub use mysql::*; + +#[async_trait] +pub trait LNVpsDb: Sync + Send { + /// Migrate database + async fn migrate(&self) -> Result<()>; + + /// Insert/Fetch user by pubkey + async fn upsert_user(&self, pubkey: &[u8; 32]) -> Result; + + /// Get a user by id + async fn get_user(&self, id: u64) -> Result; + + /// Update user record + async fn update_user(&self, user: &User) -> Result<()>; + + /// Delete user record + async fn delete_user(&self, id: u64) -> Result<()>; + + /// Insert a new user ssh key + async fn insert_user_ssh_key(&self, new_key: UserSshKey) -> Result; + + /// Get user ssh key by id + async fn get_user_ssh_key(&self, id: u64) -> Result; + + /// Delete a user ssh key by id + async fn delete_user_ssh_key(&self, id: u64) -> Result<()>; + + /// List a users ssh keys + async fn list_user_ssh_key(&self, user_id: u64) -> Result>; + + /// Get VM host region by id + async fn get_host_region(&self, id: u64) -> Result; + + /// List VM's owned by a specific user + async fn list_hosts(&self) -> Result>; + + /// Update host resources (usually from [auto_discover]) + async fn update_host(&self, host: VmHost) -> Result<()>; + + /// List VM's owned by a specific user + async fn list_host_disks(&self, host_id: u64) -> Result>; + + /// List available OS images + async fn list_os_image(&self) -> Result>; + + /// List available IP Ranges + async fn list_ip_range(&self) -> Result>; + + /// Get a VM cost plan by id + async fn get_cost_plan(&self, id: u64) -> Result; + + /// List VM templates + async fn list_vm_templates(&self) -> Result>; + + /// List VM's owned by a specific user + async fn list_user_vms(&self, id: u64) -> Result>; + + /// Insert a new VM record + async fn insert_vm(&self, vm: Vm) -> Result; + + /// List VM ip assignments + async fn get_vm_ip_assignments(&self, vm_id: u64) -> Result>; + + /// List payments by VM id + async fn list_vm_payment(&self, vm_id: u64) -> Result>; + + /// Insert a new VM payment record + async fn insert_vm_payment(&self, vm_payment: VmPayment) -> Result; + + /// Update a VM payment record + async fn update_vm_payment(&self, vm_payment: VmPayment) -> Result<()>; +} \ No newline at end of file diff --git a/lnvps_db/src/model.rs b/lnvps_db/src/model.rs new file mode 100644 index 0000000..c3a92e6 --- /dev/null +++ b/lnvps_db/src/model.rs @@ -0,0 +1,215 @@ +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use sqlx::FromRow; + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +/// Users who buy VM's +pub struct User { + /// Unique ID of this user (database generated) + pub id: u64, + /// The nostr public key for this user + pub pubkey: Vec, + /// When this user first started using the service (first login) + pub created: DateTime, + + pub email: Option, + pub contact_nip4: bool, + pub contact_nip17: bool, + pub contact_email: bool, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct UserSshKey { + pub id: u64, + pub name: String, + pub user_id: u64, + pub created: DateTime, + pub key_data: String, + + #[sqlx(skip)] + #[serde(skip_serializing_if = "Option::is_none")] + pub vms: Option>, +} + +#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[repr(u16)] +/// The type of VM host +pub enum VmHostKind { + Proxmox = 0, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmHostRegion { + pub id: u64, + pub name: String, + pub enabled: bool, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +/// A VM host +pub struct VmHost { + /// Unique id of this host + pub id: u64, + /// The host kind (Hypervisor) + pub kind: VmHostKind, + /// What region / group this host is part of + pub region_id: u64, + /// Internal name of this host + pub name: String, + /// Endpoint for controlling this host + pub ip: String, + /// Total number of CPU cores + pub cpu: u16, + /// Total memory size in bytes + pub memory: u64, + /// If VM's should be provisioned on this host + pub enabled: bool, + /// API token used to control this host via [ip] + pub api_token: String, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmHostDisk { + pub id: u64, + pub host_id: u64, + pub name: String, + pub size: u64, + pub kind: DiskType, + pub interface: DiskInterface, + pub enabled: bool, +} + +#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[repr(u16)] +pub enum DiskType { + HDD = 0, + SSD = 1, +} + +#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[repr(u16)] +pub enum DiskInterface { + SATA = 0, + SCSI = 1, + PCIe = 2, +} + +#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[repr(u16)] +pub enum OsDistribution { + Ubuntu = 0, + Debian = 1, +} + +/// OS Images are templates which are used as a basis for +/// provisioning new vms +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmOsImage { + pub id: u64, + pub name: String, + pub distribution: OsDistribution, + pub flavour: String, + pub version: String, + pub enabled: bool, + /// URL location of cloud image + pub url: String, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct IpRange { + pub id: u64, + pub cidr: String, + pub enabled: bool, + pub region_id: u64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[repr(u16)] +pub enum VmCostPlanIntervalType { + Day = 0, + Month = 1, + Year = 2, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmCostPlan { + pub id: u64, + pub name: String, + pub created: DateTime, + pub amount: u64, + pub currency: String, + pub interval_amount: u64, + pub interval_type: VmCostPlanIntervalType, +} + +/// Offers. +/// These are the same as the offers visible to customers +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmTemplate { + pub id: u64, + pub name: String, + pub enabled: bool, + pub created: DateTime, + #[serde(skip_serializing_if = "Option::is_none")] + pub expires: Option>, + pub cpu: u16, + pub memory: u64, + pub disk_type: DiskType, + pub disk_interface: DiskInterface, + pub cost_plan_id: u64, + pub region_id: u64, + + #[sqlx(skip)] + #[serde(skip_serializing_if = "Option::is_none")] + pub cost_plan: Option, + #[sqlx(skip)] + #[serde(skip_serializing_if = "Option::is_none")] + pub region: Option, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct Vm { + /// Unique VM ID (Same in proxmox) + pub id: u64, + /// The host this VM is on + pub host_id: u64, + /// The user that owns this VM + pub user_id: u64, + /// The base image of this VM + pub image_id: u64, + /// The base image of this VM + pub template_id: u64, + /// Users ssh-key assigned to this VM + pub ssh_key_id: u64, + /// When the VM was created + pub created: DateTime, + /// When the VM expires + pub expires: DateTime, + /// How many vCPU's this VM has + pub cpu: u16, + /// How much RAM this VM has in bytes + pub memory: u64, + /// How big the disk is on this VM in bytes + pub disk_size: u64, + /// The [VmHostDisk] this VM is on + pub disk_id: u64, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmIpAssignment { + pub id: u64, + pub vm_id: u64, + pub ip_range_id: u64, +} + +#[derive(Serialize, Deserialize, FromRow, Clone, Debug)] +pub struct VmPayment { + pub id: u64, + pub vm_id: u64, + pub created: DateTime, + pub expires: DateTime, + pub amount: u64, + pub invoice: String, + pub time_value: u64, + pub is_paid: bool, +} \ No newline at end of file diff --git a/lnvps_db/src/mysql.rs b/lnvps_db/src/mysql.rs new file mode 100644 index 0000000..4dc7797 --- /dev/null +++ b/lnvps_db/src/mysql.rs @@ -0,0 +1,152 @@ +use crate::{IpRange, LNVpsDb, User, UserSshKey, Vm, VmCostPlan, VmHost, VmHostDisk, VmHostRegion, VmIpAssignment, VmOsImage, VmPayment, VmTemplate}; +use anyhow::{Error, Result}; +use async_trait::async_trait; +use sqlx::{Executor, MySqlPool, Row}; + +#[derive(Clone)] +pub struct LNVpsDbMysql { + db: MySqlPool, +} + +impl LNVpsDbMysql { + pub async fn new(conn: &str) -> Result { + let db = MySqlPool::connect(conn).await?; + Ok(Self { + db + }) + } + + #[cfg(debug_assertions)] + pub async fn execute(&self, sql: &str) -> Result<()> { + self.db.execute(sql).await.map_err(Error::new)?; + Ok(()) + } +} + +#[async_trait] +impl LNVpsDb for LNVpsDbMysql { + async fn migrate(&self) -> anyhow::Result<()> { + sqlx::migrate!().run(&self.db).await.map_err(Error::new) + } + + async fn upsert_user(&self, pubkey: &[u8; 32]) -> anyhow::Result { + let res = sqlx::query("insert ignore into users(pubkey) values(?) returning id") + .bind(pubkey.as_slice()) + .fetch_optional(&self.db) + .await?; + match res { + None => sqlx::query("select id from users where pubkey = ?") + .bind(pubkey.as_slice()) + .fetch_one(&self.db) + .await? + .try_get(0) + .map_err(Error::new), + Some(res) => res.try_get(0).map_err(Error::new), + } + } + + async fn get_user(&self, id: u64) -> Result { + todo!() + } + + async fn update_user(&self, user: &User) -> Result<()> { + todo!() + } + + async fn delete_user(&self, id: u64) -> Result<()> { + todo!() + } + + async fn insert_user_ssh_key(&self, new_key: UserSshKey) -> Result { + todo!() + } + + async fn get_user_ssh_key(&self, id: u64) -> Result { + todo!() + } + + async fn delete_user_ssh_key(&self, id: u64) -> Result<()> { + todo!() + } + + async fn list_user_ssh_key(&self, user_id: u64) -> Result> { + todo!() + } + + async fn get_host_region(&self, id: u64) -> Result { + todo!() + } + + async fn list_hosts(&self) -> anyhow::Result> { + sqlx::query_as("select * from vm_host") + .fetch_all(&self.db) + .await + .map_err(Error::new) + } + + async fn update_host(&self, host: VmHost) -> anyhow::Result<()> { + sqlx::query("update vm_host set name = ?, cpu = ?, memory = ? where id = ?") + .bind(&host.name) + .bind(&host.cpu) + .bind(&host.memory) + .bind(&host.id) + .execute(&self.db) + .await?; + Ok(()) + } + + async fn list_host_disks(&self, host_id: u64) -> anyhow::Result> { + sqlx::query_as("select * from vm_host_disk where host_id = ?") + .bind(&host_id) + .fetch_all(&self.db) + .await + .map_err(Error::new) + } + + async fn list_os_image(&self) -> Result> { + todo!() + } + + async fn list_ip_range(&self) -> Result> { + todo!() + } + + async fn get_cost_plan(&self, id: u64) -> Result { + todo!() + } + + async fn list_vm_templates(&self) -> anyhow::Result> { + sqlx::query_as("select * from vm_template where enabled = 1 and (expires is null or expires > now())") + .fetch_all(&self.db) + .await + .map_err(Error::new) + } + + async fn list_user_vms(&self, id: u64) -> Result> { + sqlx::query_as("select * from vm where user_id = ?") + .bind(&id) + .fetch_all(&self.db) + .await + .map_err(Error::new) + } + + async fn insert_vm(&self, vm: Vm) -> Result { + todo!() + } + + async fn get_vm_ip_assignments(&self, vm_id: u64) -> Result> { + todo!() + } + + async fn list_vm_payment(&self, vm_id: u64) -> Result> { + todo!() + } + + async fn insert_vm_payment(&self, vm_payment: VmPayment) -> Result { + todo!() + } + + async fn update_vm_payment(&self, vm_payment: VmPayment) -> Result<()> { + todo!() + } +} \ No newline at end of file diff --git a/src/api.rs b/src/api.rs index 09f94ec..d6d4cde 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,14 +1,13 @@ -use crate::db; use crate::nip98::Nip98Auth; use crate::provisioner::Provisioner; use anyhow::Error; +use lnvps_db::{LNVpsDb, Vm, VmTemplate}; use rocket::serde::json::Json; -use rocket::{get, post, routes, Data, Responder, Route, State}; +use rocket::{get, post, routes, Responder, Route, State}; use serde::{Deserialize, Serialize}; -use crate::vm::VMSpec; pub fn routes() -> Vec { - routes![v1_list_vms] + routes![v1_list_vms, v1_list_vm_templates, v1_provision_vm] } type ApiResult = Result>, ApiError>; @@ -38,35 +37,40 @@ impl From for ApiError { } } -#[derive(Debug, Serialize, Deserialize)] -struct CreateVmRequest {} - -impl From for VMSpec { - fn from(value: CreateVmRequest) -> Self { - todo!() - } -} - #[get("/api/v1/vms")] -async fn v1_list_vms(auth: Nip98Auth, provisioner: &State) -> ApiResult> { +async fn v1_list_vms(auth: Nip98Auth, db: &State>) -> ApiResult> { let pubkey = auth.event.pubkey.to_bytes(); - let uid = provisioner.upsert_user(&pubkey).await?; - let vms = provisioner.list_vms(uid).await?; + let uid = db.upsert_user(&pubkey).await?; + let vms = db.list_user_vms(uid).await?; ApiData::ok(vms) } #[get("/api/v1/vm/templates")] -async fn v1_list_vm_templates(provisioner: &State) -> ApiResult> { - let vms = provisioner.list_vm_templates().await?; +async fn v1_list_vm_templates(db: &State>) -> ApiResult> { + let vms = db.list_vm_templates().await?; ApiData::ok(vms) } #[post("/api/v1/vm", data = "", format = "json")] -async fn v1_provision_vm(auth: Nip98Auth, provisioner: &State, req: Json) -> ApiResult { +async fn v1_provision_vm( + auth: Nip98Auth, + db: &State>, + provisioner: &State>, + req: Json, +) -> ApiResult { let pubkey = auth.event.pubkey.to_bytes(); - let uid = provisioner.upsert_user(&pubkey).await?; + let uid = db.upsert_user(&pubkey).await?; let req = req.0; let rsp = provisioner.provision(req.into()).await?; ApiData::ok(rsp) -} \ No newline at end of file +} + +#[derive(Deserialize)] +pub struct CreateVmRequest {} + +impl Into for CreateVmRequest { + fn into(self) -> VmTemplate { + todo!() + } +} diff --git a/src/bin/api.rs b/src/bin/api.rs index a4b33b2..d36941b 100644 --- a/src/bin/api.rs +++ b/src/bin/api.rs @@ -2,10 +2,10 @@ use anyhow::Error; use config::{Config, File}; use lnvps::api; use lnvps::cors::CORS; -use lnvps::provisioner::Provisioner; +use lnvps::provisioner::{LNVpsProvisioner, Provisioner}; +use lnvps_db::{LNVpsDb, LNVpsDbMysql}; use log::error; use serde::{Deserialize, Serialize}; -use sqlx::{Executor, MySqlPool}; #[derive(Debug, Deserialize, Serialize)] pub struct Settings { @@ -17,13 +17,14 @@ async fn main() -> Result<(), Error> { pretty_env_logger::init(); let config: Settings = Config::builder() - .add_source(File::with_name("config.toml")) + .add_source(File::with_name("config.yaml")) .build()? .try_deserialize()?; - let db = MySqlPool::connect(&config.db).await?; - sqlx::migrate!().run(&db).await?; - let provisioner = Provisioner::new(db.clone()); + let db = LNVpsDbMysql::new(&config.db).await?; + db.migrate().await?; + + let provisioner = LNVpsProvisioner::new(db.clone()); #[cfg(debug_assertions)] { let setup_script = include_str!("../../dev_setup.sql"); @@ -31,9 +32,12 @@ async fn main() -> Result<(), Error> { provisioner.auto_discover().await?; } + let db: Box = Box::new(db.clone()); + let pv: Box = Box::new(provisioner); if let Err(e) = rocket::build() .attach(CORS) - .manage(provisioner) + .manage(db) + .manage(pv) .mount("/", api::routes()) .launch() .await diff --git a/src/db.rs b/src/db.rs deleted file mode 100644 index c29b5d4..0000000 --- a/src/db.rs +++ /dev/null @@ -1,114 +0,0 @@ -use chrono::{DateTime, Utc}; -use rocket::serde::Serialize; -use sqlx::FromRow; - -#[derive(Serialize, FromRow)] -/// Users who buy VM's -pub struct User { - /// Unique ID of this user (database generated) - pub id: u64, - /// The nostr public key for this user - pub pubkey: [u8; 32], - /// When this user first started using the service (first login) - pub created: DateTime, -} - -#[derive(Serialize, sqlx::Type, Clone, Debug)] -#[repr(u8)] -/// The type of VM host -pub enum VmHostKind { - Proxmox = 0, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -/// A VM host -pub struct VmHost { - pub id: u64, - pub kind: VmHostKind, - pub name: String, - pub ip: String, - /// Total number of CPU cores - pub cpu: u16, - /// Total memory size in bytes - pub memory: u64, - /// If VM's should be provisioned on this host - pub enabled: bool, - pub api_token: String, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -pub struct VmHostDisk { - pub id: u64, - pub host_id: u64, - pub name: String, - pub size: u64, - pub kind: DiskType, - pub interface: DiskInterface, - pub enabled: bool, -} - -#[derive(Serialize, sqlx::Type, Clone, Debug)] -#[repr(u8)] -pub enum DiskType { - HDD = 0, - SSD = 1, -} - -#[derive(Serialize, sqlx::Type, Clone, Debug)] -#[repr(u8)] -pub enum DiskInterface { - SATA = 0, - SCSI = 1, - PCIe = 2, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -pub struct VmOsImage { - pub id: u64, - pub name: String, - pub enabled: bool, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -pub struct IpRange { - pub id: u64, - pub cidr: String, - pub enabled: bool, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -pub struct VmTemplate { - pub id: u64, - pub name: String, - pub enabled: bool, - pub created: DateTime, - pub expires: Option>, - pub cpu: u16, - pub memory: u64, - pub disk_size: u64, - pub disk_id: u64, -} - -#[derive(Serialize, FromRow, Clone, Debug)] -pub struct Vm { - /// Unique VM ID (Same in proxmox) - pub id: u64, - /// The host this VM is on - pub host_id: u64, - /// The user that owns this VM - pub user_id: u64, - /// The base image of this VM - pub image_id: u64, - /// When the VM was created - pub created: DateTime, - /// When the VM expires - pub expires: DateTime, - /// How many vCPU's this VM has - pub cpu: u16, - /// How much RAM this VM has in bytes - pub memory: u64, - /// How big the disk is on this VM in bytes - pub disk_size: u64, - /// The [VmHostDisk] this VM is on - pub disk_id: u64, -} diff --git a/src/host/proxmox.rs b/src/host/proxmox.rs index ddd2c0f..5aeb06e 100644 --- a/src/host/proxmox.rs +++ b/src/host/proxmox.rs @@ -1,7 +1,7 @@ -use anyhow::Error; -use reqwest::{Body, ClientBuilder, Url}; +use anyhow::Result; +use reqwest::{ClientBuilder, Url}; use serde::de::DeserializeOwned; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::fmt::Debug; pub struct ProxmoxClient { @@ -31,28 +31,35 @@ impl ProxmoxClient { } /// Get version info - pub async fn version(&self) -> Result { + pub async fn version(&self) -> Result { let rsp: ResponseBase = self.get("/api2/json/version").await?; Ok(rsp.data) } /// List nodes - pub async fn list_nodes(&self) -> Result, Error> { + pub async fn list_nodes(&self) -> Result> { let rsp: ResponseBase> = self.get("/api2/json/nodes").await?; Ok(rsp.data) } - pub async fn list_vms(&self, node: &str, full: bool) -> Result, Error> { + pub async fn list_vms(&self, node: &str, full: bool) -> Result> { let rsp: ResponseBase> = self.get(&format!("/api2/json/nodes/{node}/qemu")).await?; Ok(rsp.data) } - pub async fn list_storage(&self) -> Result, Error> { + pub async fn list_storage(&self) -> Result> { let rsp: ResponseBase> = self.get("/api2/json/storage").await?; Ok(rsp.data) } - async fn get(&self, path: &str) -> Result { + pub async fn create_vm(&self, node: &str, req: CreateVm) -> Result { + let rsp: ResponseBase = self + .post(&format!("/api2/json/nodes/{node}/qemu"), req) + .await?; + Ok(rsp.data) + } + + async fn get(&self, path: &str) -> Result { Ok(self .client .get(self.base.join(path)?) @@ -61,19 +68,15 @@ impl ProxmoxClient { .await? .json::() .await - .map_err(|e| Error::new(e))?) + .map_err(|e| anyhow::Error::new(e))?) } - async fn post>( - &self, - path: &str, - body: R, - ) -> Result { + async fn post(&self, path: &str, body: R) -> Result { Ok(self .client .post(self.base.join(path)?) .header("Authorization", format!("PVEAPIToken={}", self.token)) - .body(body) + .json(&body) .send() .await? .error_for_status()? @@ -165,3 +168,62 @@ pub struct NodeStorage { #[serde(rename = "thinpool")] pub thin_pool: Option, } + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum VmBios { + SeaBios, + OVMF, +} + +#[derive(Debug, Deserialize, Serialize, Default)] +pub struct CreateVm { + pub node: String, + #[serde(rename = "vmid")] + pub vm_id: i32, + #[serde(rename = "onboot")] + #[serde(skip_serializing_if = "Option::is_none")] + pub on_boot: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub balloon: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub bios: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub boot: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub cores: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub cpu: Option, + #[serde(rename = "ipconfig0")] + #[serde(skip_serializing_if = "Option::is_none")] + pub ip_config: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub machine: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub memory: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "net0")] + #[serde(skip_serializing_if = "Option::is_none")] + pub net: Option, + #[serde(rename = "ostype")] + #[serde(skip_serializing_if = "Option::is_none")] + pub os_type: Option, + #[serde(rename = "scsi0")] + #[serde(skip_serializing_if = "Option::is_none")] + pub scsi_0: Option, + #[serde(rename = "scsi1")] + #[serde(skip_serializing_if = "Option::is_none")] + pub scsi_1: Option, + #[serde(rename = "scsihw")] + #[serde(skip_serializing_if = "Option::is_none")] + pub scsi_hw: Option, + #[serde(rename = "sshkeys")] + #[serde(skip_serializing_if = "Option::is_none")] + pub ssh_keys: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub tags: Option, + #[serde(rename = "efidisk0")] + #[serde(skip_serializing_if = "Option::is_none")] + pub efi_disk_0: Option, +} diff --git a/src/lib.rs b/src/lib.rs index a647722..412786c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ pub mod api; pub mod cors; -pub mod db; pub mod host; mod nip98; pub mod provisioner; -mod vm; diff --git a/src/provisioner.rs b/src/provisioner.rs index c5c7481..04e6ef6 100644 --- a/src/provisioner.rs +++ b/src/provisioner.rs @@ -1,24 +1,27 @@ -use crate::db; -use crate::db::{VmHost, VmHostDisk}; -use crate::host::proxmox::ProxmoxClient; -use crate::vm::VMSpec; -use anyhow::{Error, Result}; +use crate::host::proxmox::{CreateVm, ProxmoxClient, VmBios}; +use anyhow::{bail, Result}; +use lnvps_db::{LNVpsDb, Vm, VmTemplate}; use log::{info, warn}; -use sqlx::{MySqlPool, Row}; +use rocket::async_trait; -#[derive(Debug, Clone)] -pub struct Provisioner { - db: MySqlPool, +#[async_trait] +pub trait Provisioner: Send + Sync { + /// Provision a new VM + async fn provision(&self, spec: VmTemplate) -> Result; } -impl Provisioner { - pub fn new(db: MySqlPool) -> Self { - Self { db } +pub struct LNVpsProvisioner { + db: Box, +} + +impl LNVpsProvisioner { + pub fn new(db: impl LNVpsDb + 'static) -> Self { + Self { db: Box::new(db) } } /// Auto-discover resources pub async fn auto_discover(&self) -> Result<()> { - let hosts = self.list_hosts().await?; + let hosts = self.db.list_hosts().await?; for host in hosts { let api = ProxmoxClient::new(host.ip.parse()?).with_api_token(&host.api_token); @@ -32,11 +35,11 @@ impl Provisioner { host.cpu = node.max_cpu.unwrap_or(host.cpu); host.memory = node.max_mem.unwrap_or(host.memory); info!("Patching host: {:?}", host); - self.update_host(host).await?; + self.db.update_host(host).await?; } // Update disk info let storages = api.list_storage().await?; - let host_disks = self.list_host_disks(host.id).await?; + let host_disks = self.db.list_host_disks(host.id).await?; for storage in storages { let host_storage = if let Some(s) = host_disks.iter().find(|d| d.name == storage.storage) { @@ -45,6 +48,8 @@ impl Provisioner { warn!("Disk not found: {} on {}", storage.storage, host.name); continue; }; + + // TODO: patch host storage info } } info!( @@ -56,72 +61,67 @@ impl Provisioner { Ok(()) } +} - /// Provision a new VM - pub async fn provision(&self, spec: VMSpec) -> Result { - todo!() - } +#[async_trait] +impl Provisioner for LNVpsProvisioner { + async fn provision(&self, spec: VmTemplate) -> Result { + let hosts = self.db.list_hosts().await?; - /// Insert/Fetch user id - pub async fn upsert_user(&self, pubkey: &[u8; 32]) -> Result { - let res = sqlx::query("insert ignore into users(pubkey) values(?) returning id") - .bind(pubkey.as_slice()) - .fetch_optional(&self.db) - .await?; - match res { - None => sqlx::query("select id from users where pubkey = ?") - .bind(pubkey.as_slice()) - .fetch_one(&self.db) - .await? - .try_get(0) - .map_err(Error::new), - Some(res) => res.try_get(0).map_err(Error::new), + // try any host + // TODO: impl resource usage based provisioning + for host in hosts { + let api = ProxmoxClient::new(host.ip.parse()?).with_api_token(&host.api_token); + + let nodes = api.list_nodes().await?; + let node = if let Some(n) = nodes.iter().find(|n| n.name == host.name) { + n + } else { + continue; + }; + let host_disks = self.db.list_host_disks(host.id).await?; + let disk_name = if let Some(d) = host_disks.first() { + d + } else { + continue; + }; + let next_id = 101; + let vm_result = api + .create_vm( + &node.name, + CreateVm { + vm_id: next_id, + bios: Some(VmBios::OVMF), + boot: Some("order=scsi0".to_string()), + cores: Some(spec.cpu as i32), + cpu: Some("kvm64".to_string()), + memory: Some((spec.memory / 1024 / 1024).to_string()), + machine: Some("q35".to_string()), + scsi_hw: Some("virtio-scsi-pci".to_string()), + efi_disk_0: Some(format!("{}:vm-{next_id}-efi,size=1M", &disk_name.name)), + net: Some("virtio=auto,bridge=vmbr0,tag=100".to_string()), + ip_config: Some(format!("ip=auto,ipv6=auto")), + ..Default::default() + }, + ) + .await?; + + return Ok(Vm { + id: 0, + host_id: 0, + user_id: 0, + image_id: 0, + template_id: 0, + ssh_key_id: 0, + created: Default::default(), + expires: Default::default(), + cpu: 0, + memory: 0, + disk_size: 0, + disk_id: 0, + }); } - } - /// List VM templates - pub async fn list_vm_templates(&self) -> Result> { - sqlx::query_as("select * from vm_template where enabled = 1 and (expires is null or expires < now())") - .fetch_all(&self.db) - .await - .map_err(Error::new) - } - - /// List VM's owned by a specific user - pub async fn list_vms(&self, id: u64) -> Result> { - sqlx::query_as("select * from vm where user_id = ?") - .bind(&id) - .fetch_all(&self.db) - .await - .map_err(Error::new) - } - - /// List VM's owned by a specific user - pub async fn list_hosts(&self) -> Result> { - sqlx::query_as("select * from vm_host") - .fetch_all(&self.db) - .await - .map_err(Error::new) - } - - /// List VM's owned by a specific user - pub async fn list_host_disks(&self, host_id: u64) -> Result> { - sqlx::query_as("select * from vm_host_disk where host_id = ?") - .bind(&host_id) - .fetch_all(&self.db) - .await - .map_err(Error::new) - } - - /// Update host resources (usually from [auto_discover]) - pub async fn update_host(&self, host: VmHost) -> Result<()> { - sqlx::query("update vm_host set name = ?, cpu = ?, memory = ? where id = ?") - .bind(&host.name) - .bind(&host.cpu) - .bind(&host.memory) - .bind(&host.id) - .execute(&self.db) - .await?; - Ok(()) + bail!("Failed to create VM") } } diff --git a/src/vm.rs b/src/vm.rs deleted file mode 100644 index 942941e..0000000 --- a/src/vm.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub enum DiskType { - SSD, - HDD, -} - -pub struct VMSpec { - pub cpu: u16, - pub memory: u64, - pub disk: u64, - pub disk_type: DiskType, -}