From c956db8adfd9c08653b6e539eb765c86e3922c35 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sun, 20 Apr 2025 09:21:32 +0200 Subject: [PATCH] ... --- acldb/Cargo.lock | 2017 ++++++++++++++++++++++++ acldb/Cargo.toml | 7 +- acldb/src/acl.rs | 97 ++ acldb/src/error.rs | 47 + acldb/src/lib.rs | 267 ++++ acldb/src/main.rs | 42 + acldb/src/rpc.rs | 231 +++ acldb/src/server.rs | 486 ++++++ acldb/src/topic.rs | 344 ++++ acldb/src/utils.rs | 52 + acldb/static/openapi.json | 304 ++++ acldb/static/swagger-ui.html | 54 + herodb/examples/circle_basic_demo.rs | 108 ++ herodb/examples/circle_models_demo.rs | 151 ++ herodb/examples/circle_standalone.rs | 106 ++ herodb/src/db/model_methods.rs | 15 +- herodb/src/models/biz/contract.rs | 4 + herodb/src/models/biz/currency.rs | 6 +- herodb/src/models/biz/customer.rs | 3 + herodb/src/models/biz/exchange_rate.rs | 3 + herodb/src/models/biz/invoice.rs | 2 + herodb/src/models/biz/product.rs | 6 +- herodb/src/models/biz/sale.rs | 5 +- herodb/src/models/biz/service.rs | 6 +- herodb/src/models/circle/circle.rs | 5 +- herodb/src/models/circle/member.rs | 6 +- herodb/src/models/circle/name.rs | 6 +- herodb/src/models/circle/wallet.rs | 5 +- herodb/src/models/gov/company.rs | 16 +- herodb/src/models/gov/compliance.rs | 207 --- herodb/src/models/gov/meeting.rs | 1 + herodb/src/models/gov/mod.rs | 2 - herodb/src/models/gov/resolution.rs | 3 + herodb/src/models/gov/shareholder.rs | 2 + herodb/src/models/gov/user.rs | 2 + herodb/src/models/gov/vote.rs | 2 +- 36 files changed, 4391 insertions(+), 229 deletions(-) create mode 100644 acldb/Cargo.lock create mode 100644 acldb/src/acl.rs create mode 100644 acldb/src/error.rs create mode 100644 acldb/src/lib.rs create mode 100644 acldb/src/main.rs create mode 100644 acldb/src/rpc.rs create mode 100644 acldb/src/server.rs create mode 100644 acldb/src/topic.rs create mode 100644 acldb/src/utils.rs create mode 100644 acldb/static/openapi.json create mode 100644 acldb/static/swagger-ui.html create mode 100644 herodb/examples/circle_basic_demo.rs create mode 100644 herodb/examples/circle_models_demo.rs create mode 100644 herodb/examples/circle_standalone.rs delete mode 100644 herodb/src/models/gov/compliance.rs diff --git a/acldb/Cargo.lock b/acldb/Cargo.lock new file mode 100644 index 0000000..02bd1e6 --- /dev/null +++ b/acldb/Cargo.lock @@ -0,0 +1,2017 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "acldb" +version = "0.1.0" +dependencies = [ + "actix-cors", + "actix-rt", + "actix-web", + "async-trait", + "base64 0.13.1", + "dirs", + "env_logger", + "hex", + "log", + "ourdb", + "serde", + "serde_json", + "sha2", + "thiserror", + "tokio", + "tst", + "utoipa", + "utoipa-swagger-ui", +] + +[[package]] +name = "actix-codec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-sink", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "actix-cors" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0346d8c1f762b41b458ed3145eea914966bb9ad20b9be0d6d463b20d45586370" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more 0.99.19", + "futures-util", + "log", + "once_cell", + "smallvec", +] + +[[package]] +name = "actix-http" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa882656b67966045e4152c634051e70346939fced7117d5f0b52146a7c74c9" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "base64 0.22.1", + "bitflags", + "brotli", + "bytes", + "bytestring", + "derive_more 2.0.1", + "encoding_rs", + "flate2", + "foldhash", + "futures-core", + "h2", + "http", + "httparse", + "httpdate", + "itoa", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite", + "rand 0.9.1", + "sha1", + "smallvec", + "tokio", + "tokio-util", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" +dependencies = [ + "quote", + "syn 2.0.100", +] + +[[package]] +name = "actix-router" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" +dependencies = [ + "bytestring", + "cfg-if", + "http", + "regex", + "regex-lite", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" +dependencies = [ + "actix-macros", + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6398974fd4284f4768af07965701efbbb5fdc0616bff20cade1bb14b77675e24" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio", + "socket2", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e46f36bf0e5af44bdc4bdb36fbbd421aa98c79a9bce724e1edeb3894e10dc7f" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" +version = "4.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2e3b15b3dc6c6ed996e4032389e9849d4ab002b1e92fbfe85b5f307d1479b4d" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "bytes", + "bytestring", + "cfg-if", + "cookie", + "derive_more 2.0.1", + "encoding_rs", + "foldhash", + "futures-core", + "futures-util", + "impl-more", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite", + "regex", + "regex-lite", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2", + "time", + "tracing", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[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 = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "async-trait" +version = "0.1.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[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", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[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 = "brotli" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a334ef7c9e23abf0ce748e8cd309037da93e606ad52eb372e4ce327a0dcfbdfd" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "bytestring" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e465647ae23b2823b0753f50decb2d5a86d2bb2cac04788fafd1f80e45378e5f" +dependencies = [ + "bytes", +] + +[[package]] +name = "cc" +version = "1.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" +dependencies = [ + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cookie" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[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 = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_more" +version = "0.99.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.100", +] + +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[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-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[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-task", + "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 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "hermit-abi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" + +[[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 2.0.100", +] + +[[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 = "impl-more" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "is-terminal" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "jobserver" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +dependencies = [ + "getrandom 0.3.2", + "libc", +] + +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "litemap" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" + +[[package]] +name = "local-channel" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" +dependencies = [ + "futures-core", + "futures-sink", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" + +[[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.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "ourdb" +version = "0.1.0" +dependencies = [ + "crc32fast", + "log", + "rand 0.8.5", + "thiserror", +] + +[[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", +] + +[[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.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", +] + +[[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 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.15", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.15", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rust-embed" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "shellexpand", + "syn 2.0.100", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "7.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" +dependencies = [ + "sha2", + "walkdir", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +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 = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ee1aca2bc74ef9589efa7ccaa0f3752751399940356209b3fd80c078149b5e" +dependencies = [ + "libc", +] + +[[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.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" + +[[package]] +name = "socket2" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +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 2.0.100", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[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 2.0.100", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.44.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "tokio-util" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tst" +version = "0.1.0" +dependencies = [ + "ourdb", + "thiserror", +] + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[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 = "utoipa" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82b1bc5417102a73e8464c686eef947bdfb99fcdfc0a4f228e81afa9526470a" +dependencies = [ + "indexmap", + "serde", + "serde_json", + "utoipa-gen", +] + +[[package]] +name = "utoipa-gen" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d96dcd6fc96f3df9b3280ef480770af1b7c5d14bc55192baa9b067976d920c" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn 2.0.100", +] + +[[package]] +name = "utoipa-swagger-ui" +version = "3.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84614caa239fb25b2bb373a52859ffd94605ceb256eeb1d63436325cf81e3653" +dependencies = [ + "actix-web", + "mime_guess", + "regex", + "rust-embed", + "serde", + "serde_json", + "utoipa", + "zip", +] + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + +[[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 2.0.100", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", + "synstructure", +] + +[[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 2.0.100", +] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "byteorder", + "crc32fast", + "crossbeam-utils", + "flate2", +] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.15+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/acldb/Cargo.toml b/acldb/Cargo.toml index 26e51dc..bb03ae2 100644 --- a/acldb/Cargo.toml +++ b/acldb/Cargo.toml @@ -13,9 +13,14 @@ serde_json = "1.0" actix-web = "4" actix-rt = "2" actix-cors = "0.6" -openapi = "0.6" +utoipa = { version = "3.3", features = ["actix_extras"] } +utoipa-swagger-ui = { version = "3.1", features = ["actix-web"] } tokio = { version = "1", features = ["full"] } log = "0.4" +env_logger = "0.10" thiserror = "1.0" sha2 = "0.10" hex = "0.4" +base64 = "0.13" +dirs = "4.0" +async-trait = "0.1" diff --git a/acldb/src/acl.rs b/acldb/src/acl.rs new file mode 100644 index 0000000..64669e7 --- /dev/null +++ b/acldb/src/acl.rs @@ -0,0 +1,97 @@ +use std::collections::HashMap; +use serde::{Serialize, Deserialize}; + +/// Represents permission levels in the ACL system +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +pub enum ACLRight { + /// Read permission + Read, + /// Write permission (includes Read) + Write, + /// Delete permission (includes Write and Read) + Delete, + /// Execute permission (includes Delete, Write, and Read) + Execute, + /// Admin permission (includes all other permissions) + Admin, +} + +/// Access Control List for managing permissions +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ACL { + /// Unique name for the ACL within a circle + pub name: String, + /// Map of public keys to their permission levels + permissions: HashMap, +} + +impl ACL { + /// Creates a new ACL with the given name + pub fn new(name: &str) -> Self { + ACL { + name: name.to_string(), + permissions: HashMap::new(), + } + } + + /// Sets a permission for a public key + pub fn set_permission(&mut self, pubkey: &str, right: ACLRight) { + self.permissions.insert(pubkey.to_string(), right); + } + + /// Removes a permission for a public key + pub fn remove_permission(&mut self, pubkey: &str) { + self.permissions.remove(pubkey); + } + + /// Checks if a public key has at least the specified permission level + pub fn has_permission(&self, pubkey: &str, right: ACLRight) -> bool { + if let Some(assigned_right) = self.permissions.get(pubkey) { + return *assigned_right >= right; + } + false + } + + /// Gets all public keys with their associated permissions + pub fn get_all_permissions(&self) -> &HashMap { + &self.permissions + } + + /// Gets the permission level for a specific public key + pub fn get_permission(&self, pubkey: &str) -> Option { + self.permissions.get(pubkey).copied() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_acl_permissions() { + let mut acl = ACL::new("test_acl"); + + // Set permissions + acl.set_permission("user1", ACLRight::Read); + acl.set_permission("user2", ACLRight::Write); + acl.set_permission("user3", ACLRight::Admin); + + // Check permissions + assert!(acl.has_permission("user1", ACLRight::Read)); + assert!(!acl.has_permission("user1", ACLRight::Write)); + + assert!(acl.has_permission("user2", ACLRight::Read)); + assert!(acl.has_permission("user2", ACLRight::Write)); + assert!(!acl.has_permission("user2", ACLRight::Delete)); + + assert!(acl.has_permission("user3", ACLRight::Read)); + assert!(acl.has_permission("user3", ACLRight::Write)); + assert!(acl.has_permission("user3", ACLRight::Delete)); + assert!(acl.has_permission("user3", ACLRight::Execute)); + assert!(acl.has_permission("user3", ACLRight::Admin)); + + // Remove permission + acl.remove_permission("user2"); + assert!(!acl.has_permission("user2", ACLRight::Read)); + } +} diff --git a/acldb/src/error.rs b/acldb/src/error.rs new file mode 100644 index 0000000..ec4d7b6 --- /dev/null +++ b/acldb/src/error.rs @@ -0,0 +1,47 @@ +use thiserror::Error; + +/// Error types for the ACLDB module +#[derive(Error, Debug)] +pub enum Error { + /// Permission denied error + #[error("Permission denied")] + PermissionDenied, + + /// Record not found error + #[error("Record not found")] + NotFound, + + /// Invalid operation error + #[error("Invalid operation: {0}")] + InvalidOperation(String), + + /// Path error + #[error("Path error: {0}")] + PathError(String), + + /// OurDB error + #[error("OurDB error: {0}")] + OurDBError(#[from] ourdb::Error), + + /// TST error + #[error("TST error: {0}")] + TSTError(#[from] tst::Error), + + /// IO error + #[error("IO error: {0}")] + IOError(#[from] std::io::Error), + + /// Serialization error + #[error("Serialization error: {0}")] + SerializationError(#[from] serde_json::Error), + + /// Signature verification error + #[error("Signature verification error: {0}")] + SignatureError(String), + + /// Invalid request error + #[error("Invalid request: {0}")] + InvalidRequest(String), +} + + diff --git a/acldb/src/lib.rs b/acldb/src/lib.rs new file mode 100644 index 0000000..bb5ae44 --- /dev/null +++ b/acldb/src/lib.rs @@ -0,0 +1,267 @@ +mod acl; +mod error; +mod topic; +mod rpc; +mod server; +mod utils; + +pub use acl::{ACL, ACLRight}; +pub use error::Error; +pub use topic::ACLDBTopic; +pub use rpc::RpcInterface; +pub use server::Server; + +use std::path::Path; +use std::sync::Arc; +use tokio::sync::RwLock; +use std::collections::HashMap; +use ourdb::OurDB; +use tst::TST; + +/// ACLDB represents an access-controlled database instance for a specific circle +pub struct ACLDB { + /// Circle ID + circle_id: String, + /// Base directory path + base_path: String, + /// OurDB instance for the circle + db: OurDB, + /// TST instance for key-to-id mapping + tst: TST, + /// Cache of loaded ACLs + acl_cache: HashMap, + /// Topic instances + topics: HashMap>>, +} + +impl ACLDB { + /// Creates a new ACLDB instance for the specified circle + pub fn new(circle_id: &str) -> Result { + let home_dir = dirs::home_dir().ok_or_else(|| Error::PathError("Home directory not found".to_string()))?; + let base_path = home_dir.join("hero/var/ourdb").join(circle_id); + + // Create directory if it doesn't exist + std::fs::create_dir_all(&base_path)?; + + // Initialize OurDB for the circle + let ourdb_path = base_path.join("data"); + std::fs::create_dir_all(&ourdb_path)?; + + let db_config = ourdb::OurDBConfig { + path: ourdb_path, + incremental_mode: true, + file_size: None, + keysize: None, + reset: Some(false), + }; + + let db = OurDB::new(db_config)?; + + // Initialize TST for key-to-id mapping + let tst_path = base_path.join("tst").to_string_lossy().to_string(); + let tst = TST::new(&tst_path, false)?; + + Ok(ACLDB { + circle_id: circle_id.to_string(), + base_path: base_path.to_string_lossy().to_string(), + db, + tst, + acl_cache: HashMap::new(), + topics: HashMap::new(), + }) + } + + /// Gets a topic instance, creating it if it doesn't exist + pub fn topic(&mut self, topic_name: &str) -> Arc> { + if let Some(topic) = self.topics.get(topic_name) { + return Arc::clone(topic); + } + + // Since OurDB and TST don't implement Clone, we'll create new instances + // In a real implementation, we would use a connection pool or similar + let topic = Arc::new(RwLock::new(ACLDBTopic::new( + self.circle_id.clone(), + topic_name.to_string(), + Arc::new(RwLock::new(OurDB::new(ourdb::OurDBConfig { + path: Path::new(&self.base_path).join("data").join(topic_name), + incremental_mode: true, + file_size: None, + keysize: None, + reset: Some(false), + }).unwrap())), + Arc::new(RwLock::new(TST::new( + &Path::new(&self.base_path).join("tst").join(topic_name).to_string_lossy(), + false + ).unwrap())), + ))); + + self.topics.insert(topic_name.to_string(), Arc::clone(&topic)); + topic + } + + /// Updates or creates an ACL with specified permissions + pub async fn acl_update(&mut self, caller_pubkey: &str, name: &str, pubkeys: &[String], right: ACLRight) -> Result<(), Error> { + // Check if caller has admin rights + self.check_admin_rights(caller_pubkey).await?; + + // Get or create the ACL + let mut acl = self.get_or_create_acl(name).await?; + + // Update permissions for each public key + for pubkey in pubkeys { + acl.set_permission(pubkey, right); + } + + // Save the updated ACL + self.save_acl(&acl).await?; + + // Update cache + self.acl_cache.insert(name.to_string(), acl); + + Ok(()) + } + + /// Removes specific public keys from an existing ACL + pub async fn acl_remove(&mut self, caller_pubkey: &str, name: &str, pubkeys: &[String]) -> Result<(), Error> { + // Check if caller has admin rights + self.check_admin_rights(caller_pubkey).await?; + + // Get the ACL + let mut acl = self.get_acl(name).await?; + + // Remove permissions for each public key + for pubkey in pubkeys { + acl.remove_permission(pubkey); + } + + // Save the updated ACL + self.save_acl(&acl).await?; + + // Update cache + self.acl_cache.insert(name.to_string(), acl); + + Ok(()) + } + + /// Deletes an entire ACL + pub async fn acl_del(&mut self, caller_pubkey: &str, name: &str) -> Result<(), Error> { + // Check if caller has admin rights + self.check_admin_rights(caller_pubkey).await?; + + // Get the ACL to ensure it exists + let _acl = self.get_acl(name).await?; + + // Get the ACL topic + let topic = self.topic("acl"); + let topic = topic.write().await; + + // Delete the ACL + topic.delete(name).await?; + + // Remove from cache + self.acl_cache.remove(name); + + Ok(()) + } + + /// Gets an ACL by name + pub async fn get_acl(&mut self, name: &str) -> Result { + // Check cache first + if let Some(acl) = self.acl_cache.get(name) { + return Ok(acl.clone()); + } + + // Get the ACL topic + let topic = self.topic("acl"); + let topic = topic.read().await; + + // Get the ACL data + let acl_data = topic.get(name).await?; + + // Deserialize the ACL + let acl: ACL = serde_json::from_slice(&acl_data)?; + + // Update cache + self.acl_cache.insert(name.to_string(), acl.clone()); + + Ok(acl) + } + + /// Gets or creates an ACL + async fn get_or_create_acl(&mut self, name: &str) -> Result { + match self.get_acl(name).await { + Ok(acl) => Ok(acl), + Err(_) => { + // Create a new ACL + let acl = ACL::new(name); + + // Save the ACL + self.save_acl(&acl).await?; + + Ok(acl) + } + } + } + + /// Saves an ACL + async fn save_acl(&mut self, acl: &ACL) -> Result<(), Error> { + // Serialize the ACL + let acl_data = serde_json::to_vec(acl)?; + + // Get the ACL topic + let topic = self.topic("acl"); + let topic = topic.write().await; + + // Save the ACL + topic.set(&acl.name, &acl_data).await?; + + Ok(()) + } + + /// Checks if a caller has admin rights + async fn check_admin_rights(&mut self, caller_pubkey: &str) -> Result<(), Error> { + // For the circle creator/owner, always grant admin rights + if self.is_circle_owner(caller_pubkey) { + return Ok(()); + } + + // Check if there's an admin ACL + match self.get_acl("admin").await { + Ok(acl) => { + // Check if the caller has admin rights + if acl.has_permission(caller_pubkey, ACLRight::Admin) { + Ok(()) + } else { + Err(Error::PermissionDenied) + } + } + Err(_) => { + // If no admin ACL exists, only the circle owner can perform admin operations + Err(Error::PermissionDenied) + } + } + } + + /// Checks if a caller is the circle owner + fn is_circle_owner(&self, caller_pubkey: &str) -> bool { + // In a real implementation, this would check against the circle's owner + // For now, we'll use a simple check based on the circle ID + // This should be replaced with proper circle ownership verification + let circle_owner_file = Path::new(&self.base_path).join("owner"); + if circle_owner_file.exists() { + if let Ok(owner) = std::fs::read_to_string(circle_owner_file) { + return owner.trim() == caller_pubkey; + } + } + + // If no owner file exists, check if this is the first admin operation + self.acl_cache.is_empty() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + // Tests will be added here +} diff --git a/acldb/src/main.rs b/acldb/src/main.rs new file mode 100644 index 0000000..93144a2 --- /dev/null +++ b/acldb/src/main.rs @@ -0,0 +1,42 @@ +use acldb::{Server, Error}; +use std::env; +use log::{info, error, LevelFilter}; + +#[actix_web::main] +async fn main() -> Result<(), Error> { + // Initialize logger + env_logger::Builder::new() + .filter_level(LevelFilter::Info) + .init(); + + info!("Starting ACLDB server..."); + + // Parse command line arguments + let args: Vec = env::args().collect(); + let host = args.get(1).map_or("127.0.0.1".to_string(), |s| s.clone()); + let port = args.get(2) + .map_or(8080, |s| s.parse::().unwrap_or(8080)); + + // Create server configuration + let config = acldb::server::ServerConfig { + host, + port, + }; + + // Create and start server + let server = Server::new(config); + info!("Server listening on {}:{}", config.host, config.port); + info!("Swagger UI available at http://{}:{}/swagger", config.host, config.port); + + // Start the server + match server.start().await { + Ok(_) => { + info!("Server stopped"); + Ok(()) + } + Err(e) => { + error!("Server error: {}", e); + Err(Error::IOError(e)) + } + } +} diff --git a/acldb/src/rpc.rs b/acldb/src/rpc.rs new file mode 100644 index 0000000..0f7d6f7 --- /dev/null +++ b/acldb/src/rpc.rs @@ -0,0 +1,231 @@ +use serde::{Serialize, Deserialize}; +use crate::error::Error; +use crate::acl::ACLRight; +use std::collections::HashMap; +use utoipa::ToSchema; + +/// RPC request structure +#[derive(Debug, Clone, Deserialize, ToSchema)] +pub struct RpcRequest { + /// Method name + pub method: String, + /// JSON-encoded arguments + pub params: serde_json::Value, + /// Signature of the JSON data + pub signature: String, +} + +/// RPC response structure +#[derive(Debug, Clone, Serialize, ToSchema)] +pub struct RpcResponse { + /// Result of the operation + pub result: Option, + /// Error message if any + pub error: Option, +} + +/// ACL update request parameters +#[derive(Debug, Deserialize)] +pub struct AclUpdateParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the ACL exists + pub circle_id: String, + /// Unique name for the ACL within the circle + pub name: String, + /// Array of public keys to grant permissions to + pub pubkeys: Vec, + /// Permission level + pub right: String, +} + +/// ACL remove request parameters +#[derive(Debug, Deserialize)] +pub struct AclRemoveParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the ACL exists + pub circle_id: String, + /// Name of the ACL to modify + pub name: String, + /// Array of public keys to remove from the ACL + pub pubkeys: Vec, +} + +/// ACL delete request parameters +#[derive(Debug, Deserialize)] +pub struct AclDelParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the ACL exists + pub circle_id: String, + /// Name of the ACL to delete + pub name: String, +} + +/// Set request parameters +#[derive(Debug, Deserialize)] +pub struct SetParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the data belongs + pub circle_id: String, + /// String identifier for the database category + pub topic: String, + /// Optional string key for the record + pub key: Option, + /// Optional numeric ID for direct access + pub id: Option, + /// Base64-encoded data to store + pub value: String, + /// ID of the ACL to protect this record (0 for public access) + pub acl_id: Option, +} + +/// Delete request parameters +#[derive(Debug, Deserialize)] +pub struct DelParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the data belongs + pub circle_id: String, + /// String identifier for the database category + pub topic: String, + /// Optional string key for the record + pub key: Option, + /// Optional numeric ID for direct access + pub id: Option, +} + +/// Get request parameters +#[derive(Debug, Deserialize)] +pub struct GetParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the data belongs + pub circle_id: String, + /// String identifier for the database category + pub topic: String, + /// Optional string key for the record + pub key: Option, + /// Optional numeric ID for direct access + pub id: Option, +} + +/// Prefix request parameters +#[derive(Debug, Deserialize)] +pub struct PrefixParams { + /// Public key of the requesting user + pub caller_pubkey: String, + /// ID of the circle where the data belongs + pub circle_id: String, + /// String identifier for the database category + pub topic: String, + /// Prefix to search for + pub prefix: String, +} + +/// RPC interface for handling client requests +pub struct RpcInterface { + /// Map of method names to handler functions + handlers: HashMap Result + Send + Sync>>, +} + +impl RpcInterface { + /// Creates a new RPC interface + pub fn new() -> Self { + RpcInterface { + handlers: HashMap::new(), + } + } + + /// Registers a handler for a method + pub fn register(&mut self, method: &str, handler: F) + where + F: Fn(serde_json::Value) -> Result + Send + Sync + 'static, + { + self.handlers.insert(method.to_string(), Box::new(handler)); + } + + /// Handles an RPC request + pub fn handle(&self, request: RpcRequest) -> RpcResponse { + // Verify the signature + if let Err(err) = self.verify_signature(&request) { + return RpcResponse { + result: None, + error: Some(err.to_string()), + }; + } + + // Extract the caller's public key from the signature + let caller_pubkey = self.extract_pubkey(&request.signature).unwrap_or_default(); + + // Call the appropriate handler + match self.handlers.get(&request.method) { + Some(handler) => { + match handler(request.params) { + Ok(result) => RpcResponse { + result: Some(result), + error: None, + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + } + None => RpcResponse { + result: None, + error: Some(format!("Method not found: {}", request.method)), + }, + } + } + + /// Verifies the signature of an RPC request + fn verify_signature(&self, request: &RpcRequest) -> Result<(), Error> { + // In a real implementation, this would verify the cryptographic signature + // For now, we'll just check that the signature is not empty + if request.signature.is_empty() { + return Err(Error::SignatureError("Empty signature".to_string())); + } + + Ok(()) + } + + /// Extracts the public key from a signature + fn extract_pubkey(&self, signature: &str) -> Result { + // In a real implementation, this would extract the public key from the signature + // For now, we'll just return a placeholder + Ok("extracted_pubkey".to_string()) + } + + /// Parses a string to an ACLRight enum + pub fn parse_acl_right(right_str: &str) -> Result { + match right_str.to_lowercase().as_str() { + "read" => Ok(ACLRight::Read), + "write" => Ok(ACLRight::Write), + "delete" => Ok(ACLRight::Delete), + "execute" => Ok(ACLRight::Execute), + "admin" => Ok(ACLRight::Admin), + _ => Err(Error::InvalidRequest(format!("Invalid ACL right: {}", right_str))), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_acl_right() { + let rpc = RpcInterface::new(); + + assert_eq!(RpcInterface::parse_acl_right("read").unwrap(), ACLRight::Read); + assert_eq!(RpcInterface::parse_acl_right("write").unwrap(), ACLRight::Write); + assert_eq!(RpcInterface::parse_acl_right("delete").unwrap(), ACLRight::Delete); + assert_eq!(RpcInterface::parse_acl_right("execute").unwrap(), ACLRight::Execute); + assert_eq!(RpcInterface::parse_acl_right("admin").unwrap(), ACLRight::Admin); + + assert!(RpcInterface::parse_acl_right("invalid").is_err()); + } +} diff --git a/acldb/src/server.rs b/acldb/src/server.rs new file mode 100644 index 0000000..92e14e6 --- /dev/null +++ b/acldb/src/server.rs @@ -0,0 +1,486 @@ +use actix_web::{web, App, HttpResponse, HttpServer, Responder}; +use actix_web::middleware::Logger; +use actix_cors::Cors; +use std::collections::HashMap; +use std::sync::Arc; +use tokio::sync::mpsc; +use tokio::sync::RwLock; +use serde_json::json; +use log::{error}; +use utoipa::OpenApi; +use utoipa_swagger_ui::SwaggerUi; + +use crate::ACLDB; +use crate::rpc::{RpcInterface, RpcRequest, RpcResponse, AclUpdateParams, AclRemoveParams, AclDelParams, SetParams, DelParams, GetParams, PrefixParams}; +use crate::error::Error; +use crate::utils::base64_decode; +use std::collections::VecDeque; +use tokio::task; +use tokio::time::{sleep, Duration}; + +/// Server configuration +pub struct ServerConfig { + /// Host address + pub host: String, + /// Port number + pub port: u16, +} + +impl Default for ServerConfig { + fn default() -> Self { + ServerConfig { + host: "127.0.0.1".to_string(), + port: 8080, + } + } +} + +/// Request queue for a circle +struct CircleQueue { + /// Queue of pending requests + queue: VecDeque<(RpcRequest, mpsc::Sender)>, + /// Flag to indicate if a worker is currently processing this queue + is_processing: bool, +} + +impl CircleQueue { + /// Creates a new circle queue + fn new() -> Self { + CircleQueue { + queue: VecDeque::new(), + is_processing: false, + } + } + + /// Adds a request to the queue and starts processing if needed + async fn add_request( + &mut self, + request: RpcRequest, + response_sender: mpsc::Sender, + rpc_interface: Arc, + acldb_factory: Arc, + ) { + // Add the request to the queue + self.queue.push_back((request.clone(), response_sender)); + + // If no worker is processing this queue, start one + if !self.is_processing { + self.is_processing = true; + + // Clone what we need for the worker + let rpc = Arc::clone(&rpc_interface); + let factory = Arc::clone(&acldb_factory); + let mut queue = self.queue.clone(); + + // Spawn a worker task + task::spawn(async move { + // Process all requests in the queue + while let Some((req, sender)) = queue.pop_front() { + // Process the request + let response = process_request(&req, &rpc, &factory).await; + + // Send the response + if let Err(err) = sender.send(response).await { + error!("Failed to send response: {}", err); + } + + // Small delay to prevent CPU hogging + sleep(Duration::from_millis(1)).await; + } + }); + } + } +} + +/// Factory for creating ACLDB instances +pub struct ACLDBFactory { + /// Map of circle IDs to ACLDB instances + dbs: RwLock>>>, +} + +impl ACLDBFactory { + /// Creates a new ACLDBFactory + pub fn new() -> Self { + ACLDBFactory { + dbs: RwLock::new(HashMap::new()), + } + } + + /// Gets or creates an ACLDB instance for a circle + pub async fn get_or_create(&self, circle_id: &str) -> Result>, Error> { + // Try to get an existing instance + let dbs = self.dbs.read().await; + if let Some(db) = dbs.get(circle_id) { + return Ok(Arc::clone(db)); + } + drop(dbs); // Release the read lock + + // Create a new instance + let db = Arc::new(RwLock::new(ACLDB::new(circle_id)?)); + + // Store it in the map + let mut dbs = self.dbs.write().await; + dbs.insert(circle_id.to_string(), Arc::clone(&db)); + + Ok(db) + } +} + +/// Server for handling RPC requests +#[derive(Clone)] +pub struct Server { + /// Server configuration + config: ServerConfig, + /// RPC interface + rpc: Arc, + /// Map of circle IDs to request queues + queues: RwLock>, + /// Factory for creating ACLDB instances + acldb_factory: Arc, +} + +impl Server { + /// Creates a new server + pub fn new(config: ServerConfig) -> Self { + let rpc = Arc::new(RpcInterface::new()); + let queues = RwLock::new(HashMap::new()); + let acldb_factory = Arc::new(ACLDBFactory::new()); + + Server { + config, + rpc, + queues, + acldb_factory, + } + } + + /// Starts the server + pub async fn start(&self) -> std::io::Result<()> { + let server_data = web::Data::new(self.clone()); + + // Start the HTTP server + HttpServer::new(move || { + App::new() + .wrap(Logger::default()) + .wrap( + Cors::default() + .allow_any_origin() + .allow_any_method() + .allow_any_header() + .max_age(3600) + ) + .app_data(web::Data::clone(&server_data)) + .route("/rpc", web::post().to(handle_rpc)) + .route("/health", web::get().to(health_check)) + .service( + SwaggerUi::new("/swagger-ui/{_:.*}") + .url("/api-docs/openapi.json", ApiDoc::openapi()) + ) + }) + .bind(format!("{}:{}", self.config.host, self.config.port))? + .run() + .await + } + + /// Registers RPC handlers + fn register_handlers(&self) { + // Nothing to do here - handlers are now processed dynamically + } + + /// Adds a request to the queue for a circle + async fn add_to_queue(&self, circle_id: &str, request: RpcRequest) -> mpsc::Receiver { + let (response_sender, response_receiver) = mpsc::channel(1); + + // Get or create the queue for this circle + let mut queues = self.queues.write().await; + + if !queues.contains_key(circle_id) { + queues.insert(circle_id.to_string(), CircleQueue::new()); + } + + // Get a mutable reference to the queue + if let Some(queue) = queues.get_mut(circle_id) { + // Add the request to the queue + queue.add_request( + request, + response_sender, + Arc::clone(&self.rpc), + Arc::clone(&self.acldb_factory) + ).await; + } + + response_receiver + } +} + + + +/// Extracts the circle ID from an RPC request +fn extract_circle_id(request: &web::Json) -> Result { + // Extract from different parameter types based on the method + match request.method.as_str() { + "aclupdate" => { + let params: AclUpdateParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "aclremove" => { + let params: AclRemoveParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "acldel" => { + let params: AclDelParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "set" => { + let params: SetParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "del" => { + let params: DelParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "get" => { + let params: GetParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + "prefix" => { + let params: PrefixParams = serde_json::from_value(request.params.clone())?; + Ok(params.circle_id) + } + _ => Err(Error::InvalidRequest(format!("Unknown method: {}", request.method))), + } +} + +/// API documentation schema +#[derive(OpenApi)] +#[openapi( + paths( + health_check, + handle_rpc + ), + components( + schemas(RpcRequest, RpcResponse) + ), + tags( + (name = "acldb", description = "ACLDB API") + ) +)] +struct ApiDoc; + +/// Handler for RPC requests with OpenAPI documentation +#[utoipa::path( + post, + path = "/rpc", + request_body = RpcRequest, + responses( + (status = 200, description = "RPC request processed successfully", body = RpcResponse), + (status = 400, description = "Bad request", body = RpcResponse), + (status = 500, description = "Internal server error", body = RpcResponse) + ), + tag = "acldb" +)] +async fn handle_rpc( + server: web::Data, + request: web::Json, +) -> impl Responder { + // Extract the circle ID from the request + let circle_id = match extract_circle_id(&request) { + Ok(id) => id, + Err(err) => { + return HttpResponse::BadRequest().json(RpcResponse { + result: None, + error: Some(err.to_string()), + }); + } + }; + + // Add the request to the queue for this circle + let mut response_receiver = server.add_to_queue(&circle_id, request.0.clone()).await; + + // Wait for the response + match response_receiver.recv().await { + Some(response) => HttpResponse::Ok().json(response), + None => HttpResponse::InternalServerError().json(RpcResponse { + result: None, + error: Some("Failed to get response".to_string()), + }), + } +} + +/// Process an RPC request +async fn process_request( + request: &RpcRequest, + rpc_interface: &Arc, + acldb_factory: &Arc +) -> RpcResponse { + match request.method.as_str() { + "aclupdate" => { + match serde_json::from_value::(request.params.clone()) { + Ok(params) => { + match RpcInterface::parse_acl_right(¶ms.right) { + Ok(right) => { + match acldb_factory.get_or_create(¶ms.circle_id).await { + Ok(db) => { + let mut db = db.write().await; + match db.acl_update(¶ms.caller_pubkey, ¶ms.name, ¶ms.pubkeys, right) { + Ok(_) => RpcResponse { + result: Some(json!({"success": true})), + error: None, + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(format!("Invalid parameters: {}", err)), + }, + } + }, + "aclremove" => { + match serde_json::from_value::(request.params.clone()) { + Ok(params) => { + match acldb_factory.get_or_create(¶ms.circle_id).await { + Ok(db) => { + let mut db = db.write().await; + match db.acl_remove(¶ms.caller_pubkey, ¶ms.name, ¶ms.pubkeys) { + Ok(_) => RpcResponse { + result: Some(json!({"success": true})), + error: None, + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(format!("Invalid parameters: {}", err)), + }, + } + }, + "acldel" => { + match serde_json::from_value::(request.params.clone()) { + Ok(params) => { + match acldb_factory.get_or_create(¶ms.circle_id).await { + Ok(db) => { + let mut db = db.write().await; + match db.acl_del(¶ms.caller_pubkey, ¶ms.name) { + Ok(_) => RpcResponse { + result: Some(json!({"success": true})), + error: None, + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(format!("Invalid parameters: {}", err)), + }, + } + }, + "set" => { + match serde_json::from_value::(request.params.clone()) { + Ok(params) => { + match acldb_factory.get_or_create(¶ms.circle_id).await { + Ok(db) => { + let mut db = db.write().await; + let topic = db.topic(¶ms.topic); + + match base64_decode(¶ms.value) { + Ok(value) => { + let acl_id = params.acl_id.unwrap_or(0); + + let result = if let Some(key) = params.key { + let topic = topic.write().await; + topic.set_with_acl(&key, &value, acl_id) + } else if let Some(id) = params.id { + let topic = topic.write().await; + topic.set_with_acl(&id.to_string(), &value, acl_id) + } else { + Err(Error::InvalidRequest("Either key or id must be provided".to_string())) + }; + + match result { + Ok(id) => RpcResponse { + result: Some(json!({"id": id})), + error: None, + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(err.to_string()), + }, + } + }, + Err(err) => RpcResponse { + result: None, + error: Some(format!("Invalid parameters: {}", err)), + }, + } + }, + _ => RpcResponse { + result: None, + error: Some(format!("Unknown method: {}", request.method)), + }, + } +} + +/// Handler for health check with OpenAPI documentation +#[utoipa::path( + get, + path = "/health", + responses( + (status = 200, description = "Server is healthy", body = String) + ), + tag = "acldb" +)] +async fn health_check() -> impl Responder { + HttpResponse::Ok().json(json!({"status": "ok"})) +} + +#[cfg(test)] +mod tests { + // Tests will be added here +} diff --git a/acldb/src/topic.rs b/acldb/src/topic.rs new file mode 100644 index 0000000..dce98f9 --- /dev/null +++ b/acldb/src/topic.rs @@ -0,0 +1,344 @@ +use std::sync::Arc; +use tokio::sync::RwLock; +use ourdb::{OurDB, OurDBSetArgs}; +use tst::TST; +use crate::error::Error; +use crate::acl::{ACL, ACLRight}; + +/// ACLDBTopic represents a database instance for a specific topic within a circle +pub struct ACLDBTopic { + /// Circle ID + circle_id: String, + /// Topic name + topic: String, + /// OurDB instance + db: Arc>, + /// TST instance for key-to-id mapping + tst: Arc>, +} + +impl ACLDBTopic { + /// Creates a new ACLDBTopic instance + pub fn new(circle_id: String, topic: String, db: Arc>, tst: Arc>) -> Self { + ACLDBTopic { + circle_id, + topic, + db, + tst, + } + } + + /// Sets a value in the database with optional ACL protection + pub async fn set(&self, key: &str, value: &[u8]) -> Result { + self.set_with_acl(key, value, 0).await // 0 means no ACL protection + } + + /// Sets a value in the database with ACL protection + pub async fn set_with_acl(&self, key: &str, value: &[u8], acl_id: u32) -> Result { + // Create the TST key + let tst_key = format!("{}{}", self.topic, key); + + // Check if the key already exists in TST + let id = { + // First try to get the ID from TST + let mut id_opt = None; + { + let tst = self.tst.read().await; + if let Ok(id_bytes) = tst.list(&tst_key) { + if !id_bytes.is_empty() { + let id_str = String::from_utf8_lossy(&id_bytes[0].as_bytes()); + if let Ok(parsed_id) = id_str.parse::() { + id_opt = Some(parsed_id); + } + } + } + } + + // If not found, get a new ID + match id_opt { + Some(id) => id, + None => { + let mut db = self.db.write().await; + db.get_next_id()? + } + } + }; + + // Prepare the data with ACL ID prefix if needed + let data = if acl_id > 0 { + // Add ACL ID as the first 4 bytes + let mut acl_data = acl_id.to_be_bytes().to_vec(); + acl_data.extend_from_slice(value); + acl_data + } else { + value.to_vec() + }; + + // Store the data in OurDB + { + let mut db = self.db.write().await; + db.set(OurDBSetArgs { + id: Some(id), + data: &data, + })?; + } + + // Store the ID in TST + { + let mut tst = self.tst.write().await; + tst.set(&tst_key, id.to_string().into_bytes())?; + } + + Ok(id) + } + + /// Gets a value from the database + pub async fn get(&self, key: &str) -> Result, Error> { + // Create the TST key + let tst_key = format!("{}{}", self.topic, key); + + // Get the ID from TST + let id = { + let tst = self.tst.read().await; + let keys = tst.list(&tst_key)?; + if keys.is_empty() { + return Err(Error::NotFound); + } + let id_str = &keys[0]; + id_str.parse::().map_err(|_| Error::InvalidOperation("Invalid ID format in TST".to_string()))? + }; + + // Get the data from OurDB + let data = { + let mut db = self.db.write().await; + db.get(id)? + }; + + // Check if the data has an ACL ID prefix + if data.len() >= 4 { + let (acl_id_bytes, actual_data) = data.split_at(4); + let acl_id = u32::from_be_bytes([acl_id_bytes[0], acl_id_bytes[1], acl_id_bytes[2], acl_id_bytes[3]]); + + if acl_id > 0 { + // This record is ACL-protected, but we're not checking permissions here + // The permission check should be done at a higher level + return Ok(actual_data.to_vec()); + } + } + + Ok(data) + } + + /// Gets a value from the database with permission check + pub async fn get_with_permission(&self, key: &str, caller_pubkey: &str, parent_acls: &[ACL]) -> Result, Error> { + // Create the TST key + let tst_key = format!("{}{}", self.topic, key); + + // Get the ID from TST + let id = { + let tst = self.tst.read().await; + let keys = tst.list(&tst_key)?; + if keys.is_empty() { + return Err(Error::NotFound); + } + let id_str = &keys[0]; + id_str.parse::().map_err(|_| Error::InvalidOperation("Invalid ID format in TST".to_string()))? + }; + + // Get the data from OurDB + let data = { + let mut db = self.db.write().await; + db.get(id)? + }; + + // Check if the data has an ACL ID prefix + if data.len() >= 4 { + let (acl_id_bytes, actual_data) = data.split_at(4); + let acl_id = u32::from_be_bytes([acl_id_bytes[0], acl_id_bytes[1], acl_id_bytes[2], acl_id_bytes[3]]); + + if acl_id > 0 { + // This record is ACL-protected, check permissions + let acl_name = format!("acl_{}", acl_id); + + // Find the ACL in the parent ACLs + let has_permission = parent_acls.iter() + .find(|acl| acl.name == acl_name) + .map(|acl| acl.has_permission(caller_pubkey, ACLRight::Read)) + .unwrap_or(false); + + if !has_permission { + return Err(Error::PermissionDenied); + } + + return Ok(actual_data.to_vec()); + } + } + + Ok(data) + } + + /// Gets a value by ID from the database + pub async fn get_by_id(&self, id: u32) -> Result, Error> { + // Get the data from OurDB + let data = { + let mut db = self.db.write().await; + db.get(id)? + }; + + // Check if the data has an ACL ID prefix + if data.len() >= 4 { + let (_, actual_data) = data.split_at(4); + return Ok(actual_data.to_vec()); + } + + Ok(data) + } + + /// Gets a value by ID from the database with permission check + pub async fn get_by_id_with_permission(&self, id: u32, caller_pubkey: &str, parent_acls: &[ACL]) -> Result, Error> { + // Get the data from OurDB + let data = { + let mut db = self.db.write().await; + db.get(id)? + }; + + // Check if the data has an ACL ID prefix + if data.len() >= 4 { + let (acl_id_bytes, actual_data) = data.split_at(4); + let acl_id = u32::from_be_bytes([acl_id_bytes[0], acl_id_bytes[1], acl_id_bytes[2], acl_id_bytes[3]]); + + if acl_id > 0 { + // This record is ACL-protected, check permissions + let acl_name = format!("acl_{}", acl_id); + + // Find the ACL in the parent ACLs + let has_permission = parent_acls.iter() + .find(|acl| acl.name == acl_name) + .map(|acl| acl.has_permission(caller_pubkey, ACLRight::Read)) + .unwrap_or(false); + + if !has_permission { + return Err(Error::PermissionDenied); + } + + return Ok(actual_data.to_vec()); + } + } + + Ok(data) + } + + /// Deletes a value from the database + pub async fn delete(&self, key: &str) -> Result<(), Error> { + // Create the TST key + let tst_key = format!("{}{}", self.topic, key); + + // Get the ID from TST + let id = { + let tst = self.tst.read().await; + let keys = tst.list(&tst_key)?; + if keys.is_empty() { + return Err(Error::NotFound); + } + let id_str = &keys[0]; + id_str.parse::().map_err(|_| Error::InvalidOperation("Invalid ID format in TST".to_string()))? + }; + + // Delete from OurDB + { + let mut db = self.db.write().await; + db.delete(id)?; + } + + // Delete from TST + { + let mut tst = self.tst.write().await; + tst.delete(&tst_key)?; + } + + Ok(()) + } + + /// Deletes a value from the database with permission check + pub async fn delete_with_permission(&self, key: &str, caller_pubkey: &str, parent_acls: &[ACL]) -> Result<(), Error> { + // Create the TST key + let tst_key = format!("{}{}", self.topic, key); + + // Get the ID from TST + let id = { + let tst = self.tst.read().await; + let keys = tst.list(&tst_key)?; + if keys.is_empty() { + return Err(Error::NotFound); + } + let id_str = &keys[0]; + id_str.parse::().map_err(|_| Error::InvalidOperation("Invalid ID format in TST".to_string()))? + }; + + // Get the data to check ACL + let data = { + let db = self.db.read().await; + db.get(id)? + }; + + // Check if the data has an ACL ID prefix + if data.len() >= 4 { + let (acl_id_bytes, _) = data.split_at(4); + let acl_id = u32::from_be_bytes([acl_id_bytes[0], acl_id_bytes[1], acl_id_bytes[2], acl_id_bytes[3]]); + + if acl_id > 0 { + // This record is ACL-protected, check permissions + let acl_name = format!("acl_{}", acl_id); + + // Find the ACL in the parent ACLs + let has_permission = parent_acls.iter() + .find(|acl| acl.name == acl_name) + .map(|acl| acl.has_permission(caller_pubkey, ACLRight::Delete)) + .unwrap_or(false); + + if !has_permission { + return Err(Error::PermissionDenied); + } + } + } + + // Delete from OurDB + { + let mut db = self.db.write().await; + db.delete(id)? + }; + + // Delete from TST + { + let mut tst = self.tst.write().await; + tst.delete(&tst_key)? + }; + + Ok(()) + } + + /// Gets all keys with a given prefix + pub async fn prefix(&self, prefix: &str) -> Result, Error> { + // Create the TST prefix + let tst_prefix = format!("{}{}", self.topic, prefix); + + // Get all keys with the prefix + let keys = { + let tst = self.tst.read().await; + tst.list(&tst_prefix)? + }; + + // Remove the topic prefix from the keys + let topic_prefix = format!("{}", self.topic); + let keys = keys.into_iter() + .map(|key| key.strip_prefix(&topic_prefix).unwrap_or(&key).to_string()) + .collect(); + + Ok(keys) + } +} + +#[cfg(test)] +mod tests { + // Tests will be added here +} diff --git a/acldb/src/utils.rs b/acldb/src/utils.rs new file mode 100644 index 0000000..a34e101 --- /dev/null +++ b/acldb/src/utils.rs @@ -0,0 +1,52 @@ +use crate::error::Error; + +/// Decodes a base64 string to bytes +pub fn base64_decode(input: &str) -> Result, Error> { + base64::decode(input).map_err(|e| Error::InvalidRequest(format!("Invalid base64: {}", e))) +} + +/// Encodes bytes to a base64 string +pub fn base64_encode(input: &[u8]) -> String { + base64::encode(input) +} + +/// Generates a SHA-256 hash of the input +pub fn sha256_hash(input: &[u8]) -> Vec { + use sha2::{Sha256, Digest}; + let mut hasher = Sha256::new(); + hasher.update(input); + hasher.finalize().to_vec() +} + +/// Converts a hash to a hex string +pub fn to_hex(bytes: &[u8]) -> String { + hex::encode(bytes) +} + +/// Validates a signature against a message and public key +pub fn validate_signature(message: &[u8], signature: &str, pubkey: &str) -> Result { + // In a real implementation, this would validate the cryptographic signature + // For now, we'll just return true + Ok(true) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_base64() { + let original = b"Hello, world!"; + let encoded = base64_encode(original); + let decoded = base64_decode(&encoded).unwrap(); + assert_eq!(decoded, original); + } + + #[test] + fn test_sha256() { + let input = b"test"; + let hash = sha256_hash(input); + let hex = to_hex(&hash); + assert_eq!(hex, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); + } +} diff --git a/acldb/static/openapi.json b/acldb/static/openapi.json new file mode 100644 index 0000000..a0a7b69 --- /dev/null +++ b/acldb/static/openapi.json @@ -0,0 +1,304 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "ACLDB API", + "description": "API for the ACLDB module which implements an Access Control List layer on top of the existing ourdb and tst databases.", + "version": "1.0.0" + }, + "servers": [ + { + "url": "http://localhost:8080", + "description": "Local development server" + } + ], + "paths": { + "/rpc": { + "post": { + "summary": "RPC endpoint", + "description": "Handles all RPC requests to the ACLDB system", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RpcRequest" + } + } + } + }, + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RpcResponse" + } + } + } + }, + "400": { + "description": "Bad request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + } + } + }, + "/health": { + "get": { + "summary": "Health check", + "description": "Returns the health status of the server", + "responses": { + "200": { + "description": "Server is healthy", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "ok" + } + } + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "RpcRequest": { + "type": "object", + "required": ["method", "params", "signature"], + "properties": { + "method": { + "type": "string", + "description": "The name of the method to call", + "example": "set" + }, + "params": { + "type": "object", + "description": "The parameters for the method" + }, + "signature": { + "type": "string", + "description": "Cryptographic signature of the request" + } + } + }, + "RpcResponse": { + "type": "object", + "properties": { + "result": { + "type": "object", + "description": "The result of the method call if successful" + }, + "error": { + "type": "string", + "description": "Error message if the method call failed" + } + } + }, + "ErrorResponse": { + "type": "object", + "properties": { + "error": { + "type": "string", + "description": "Error message" + } + } + }, + "AclUpdateParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "name", "pubkeys", "right"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the ACL exists" + }, + "name": { + "type": "string", + "description": "Unique name for the ACL within the circle" + }, + "pubkeys": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Array of public keys to grant permissions to" + }, + "right": { + "type": "string", + "description": "Permission level (read/write/delete/execute/admin)", + "enum": ["read", "write", "delete", "execute", "admin"] + } + } + }, + "AclRemoveParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "name", "pubkeys"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the ACL exists" + }, + "name": { + "type": "string", + "description": "Name of the ACL to modify" + }, + "pubkeys": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Array of public keys to remove from the ACL" + } + } + }, + "AclDelParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "name"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the ACL exists" + }, + "name": { + "type": "string", + "description": "Name of the ACL to delete" + } + } + }, + "SetParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "topic", "value"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the data belongs" + }, + "topic": { + "type": "string", + "description": "String identifier for the database category" + }, + "key": { + "type": "string", + "description": "Optional string key for the record" + }, + "id": { + "type": "integer", + "description": "Optional numeric ID for direct access" + }, + "value": { + "type": "string", + "description": "Base64-encoded data to store" + }, + "acl_id": { + "type": "integer", + "description": "ID of the ACL to protect this record (0 for public access)" + } + } + }, + "DelParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "topic"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the data belongs" + }, + "topic": { + "type": "string", + "description": "String identifier for the database category" + }, + "key": { + "type": "string", + "description": "Optional string key for the record" + }, + "id": { + "type": "integer", + "description": "Optional numeric ID for direct access" + } + } + }, + "GetParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "topic"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the data belongs" + }, + "topic": { + "type": "string", + "description": "String identifier for the database category" + }, + "key": { + "type": "string", + "description": "Optional string key for the record" + }, + "id": { + "type": "integer", + "description": "Optional numeric ID for direct access" + } + } + }, + "PrefixParams": { + "type": "object", + "required": ["caller_pubkey", "circle_id", "topic", "prefix"], + "properties": { + "caller_pubkey": { + "type": "string", + "description": "Public key of the requesting user" + }, + "circle_id": { + "type": "string", + "description": "ID of the circle where the data belongs" + }, + "topic": { + "type": "string", + "description": "String identifier for the database category" + }, + "prefix": { + "type": "string", + "description": "Prefix to search for" + } + } + } + } + } +} diff --git a/acldb/static/swagger-ui.html b/acldb/static/swagger-ui.html new file mode 100644 index 0000000..59a45b8 --- /dev/null +++ b/acldb/static/swagger-ui.html @@ -0,0 +1,54 @@ + + + + + ACLDB API Documentation + + + + + + + +
+ + + + + + diff --git a/herodb/examples/circle_basic_demo.rs b/herodb/examples/circle_basic_demo.rs new file mode 100644 index 0000000..264b5da --- /dev/null +++ b/herodb/examples/circle_basic_demo.rs @@ -0,0 +1,108 @@ +// This example demonstrates the basic functionality of the circle models +// without using the database functionality + +use herodb::models::circle::{Circle, Member, Name, Wallet, Role, Record, RecordType}; + +fn main() -> Result<(), Box> { + println!("Circle Module Basic Demo"); + + // Create a circle + let circle = Circle::new( + 1, + "ThreeFold Community".to_string(), + "A circle for ThreeFold community members".to_string(), + ); + + println!("Created circle: {:?}", circle); + + // Create members + let mut alice = Member::new( + 1, + "Alice".to_string(), + "Core contributor".to_string(), + Role::Admin, + ); + alice.add_email("alice@example.com".to_string()); + + let mut bob = Member::new( + 2, + "Bob".to_string(), + "Community member".to_string(), + Role::Member, + ); + bob.add_email("bob@example.com".to_string()); + + println!("Created members: {:?}, {:?}", alice, bob); + + // Create a domain name + let mut domain = Name::new( + 1, + "threefold.io".to_string(), + "ThreeFold main domain".to_string(), + ); + + let record = Record { + name: "www".to_string(), + text: "ThreeFold Website".to_string(), + category: RecordType::A, + addr: vec!["192.168.1.1".to_string()], + }; + + domain.add_record(record); + domain.add_admin("alice_pubkey".to_string()); + + println!("Created domain: {:?}", domain); + + // Create wallets + let mut alice_wallet = Wallet::new( + 1, + "Alice's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GALICE...".to_string(), + ); + + alice_wallet.set_asset("TFT".to_string(), 1000.0); + alice_wallet.set_asset("XLM".to_string(), 100.0); + + let mut bob_wallet = Wallet::new( + 2, + "Bob's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GBOB...".to_string(), + ); + + bob_wallet.set_asset("TFT".to_string(), 500.0); + + println!("Created wallets: {:?}, {:?}", alice_wallet, bob_wallet); + + // Link wallets to members + alice.link_wallet(alice_wallet.id); + bob.link_wallet(bob_wallet.id); + + println!("Linked wallets to members"); + + // Demonstrate wallet operations + println!("\nDemonstrating wallet operations:"); + + println!("Alice's wallet before transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + println!("Bob's wallet before transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + // Simulate a transfer of 100 TFT from Alice to Bob + alice_wallet.set_asset("TFT".to_string(), 900.0); // Decrease Alice's TFT by 100 + bob_wallet.set_asset("TFT".to_string(), 600.0); // Increase Bob's TFT by 100 + + println!("Alice's wallet after transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + println!("Bob's wallet after transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + println!("\nCircle basic demo completed successfully!"); + + Ok(()) +} \ No newline at end of file diff --git a/herodb/examples/circle_models_demo.rs b/herodb/examples/circle_models_demo.rs new file mode 100644 index 0000000..eacc904 --- /dev/null +++ b/herodb/examples/circle_models_demo.rs @@ -0,0 +1,151 @@ +use herodb::db::{DB, DBBuilder}; +use herodb::models::circle::{Circle, Member, Name, Wallet, Asset, Role, Record, RecordType}; +use std::path::Path; + +fn main() -> Result<(), Box> { + // Create a temporary directory for the database + let db_path = Path::new("./tmp/circle_demo"); + if db_path.exists() { + std::fs::remove_dir_all(db_path)?; + } + std::fs::create_dir_all(db_path)?; + + println!("Creating database at {:?}", db_path); + + // Create a database with all circle models registered + let db = DBBuilder::new(db_path) + .register_model::() + .register_model::() + .register_model::() + .register_model::() + .build()?; + + // Create a circle + let mut circle = Circle::new( + 1, + "ThreeFold Community".to_string(), + "A circle for ThreeFold community members".to_string(), + ); + + println!("Created circle: {:?}", circle); + db.set(&circle)?; + + // Create members + let mut alice = Member::new( + 1, + "Alice".to_string(), + "Core contributor".to_string(), + Role::Admin, + ); + alice.add_email("alice@example.com".to_string()); + + let mut bob = Member::new( + 2, + "Bob".to_string(), + "Community member".to_string(), + Role::Member, + ); + bob.add_email("bob@example.com".to_string()); + + println!("Created members: {:?}, {:?}", alice, bob); + db.set(&alice)?; + db.set(&bob)?; + + // Create a domain name + let mut domain = Name::new( + 1, + "threefold.io".to_string(), + "ThreeFold main domain".to_string(), + ); + + let record = Record { + name: "www".to_string(), + text: "ThreeFold Website".to_string(), + category: RecordType::A, + addr: vec!["192.168.1.1".to_string()], + }; + + domain.add_record(record); + domain.add_admin("alice_pubkey".to_string()); + + println!("Created domain: {:?}", domain); + db.set(&domain)?; + + // Create wallets + let mut alice_wallet = Wallet::new( + 1, + "Alice's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GALICE...".to_string(), + ); + + alice_wallet.set_asset("TFT".to_string(), 1000.0); + alice_wallet.set_asset("XLM".to_string(), 100.0); + + let mut bob_wallet = Wallet::new( + 2, + "Bob's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GBOB...".to_string(), + ); + + bob_wallet.set_asset("TFT".to_string(), 500.0); + + println!("Created wallets: {:?}, {:?}", alice_wallet, bob_wallet); + db.set(&alice_wallet)?; + db.set(&bob_wallet)?; + + // Link wallets to members + alice.link_wallet(alice_wallet.id); + bob.link_wallet(bob_wallet.id); + + db.set(&alice)?; + db.set(&bob)?; + + // Retrieve and display all data + println!("\nRetrieving data from database:"); + + let circles = db.list_circles()?; + println!("Circles: {:#?}", circles); + + let members = db.list_members()?; + println!("Members: {:#?}", members); + + let names = db.list_names()?; + println!("Names: {:#?}", names); + + let wallets = db.list_wallets()?; + println!("Wallets: {:#?}", wallets); + + // Demonstrate wallet operations + println!("\nDemonstrating wallet operations:"); + + let mut alice_wallet = db.get_wallet(1)?; + println!("Alice's wallet before transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + let mut bob_wallet = db.get_wallet(2)?; + println!("Bob's wallet before transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + // Simulate a transfer of 100 TFT from Alice to Bob + alice_wallet.set_asset("TFT".to_string(), 900.0); // Decrease Alice's TFT by 100 + bob_wallet.set_asset("TFT".to_string(), 600.0); // Increase Bob's TFT by 100 + + db.set(&alice_wallet)?; + db.set(&bob_wallet)?; + + let alice_wallet = db.get_wallet(1)?; + println!("Alice's wallet after transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + let bob_wallet = db.get_wallet(2)?; + println!("Bob's wallet after transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + println!("\nCircle models demo completed successfully!"); + + Ok(()) +} \ No newline at end of file diff --git a/herodb/examples/circle_standalone.rs b/herodb/examples/circle_standalone.rs new file mode 100644 index 0000000..68f243d --- /dev/null +++ b/herodb/examples/circle_standalone.rs @@ -0,0 +1,106 @@ +//! This is a standalone example that demonstrates the circle models +//! without using any database functionality. + +use herodb::models::circle::{Circle, Member, Name, Wallet, Role, Record, RecordType}; + +fn main() { + println!("Circle Module Standalone Demo"); + + // Create a circle + let circle = Circle::new( + 1, + "ThreeFold Community".to_string(), + "A circle for ThreeFold community members".to_string(), + ); + + println!("Created circle: {:?}", circle); + + // Create members + let mut alice = Member::new( + 1, + "Alice".to_string(), + "Core contributor".to_string(), + Role::Admin, + ); + alice.add_email("alice@example.com".to_string()); + + let mut bob = Member::new( + 2, + "Bob".to_string(), + "Community member".to_string(), + Role::Member, + ); + bob.add_email("bob@example.com".to_string()); + + println!("Created members: {:?}, {:?}", alice, bob); + + // Create a domain name + let mut domain = Name::new( + 1, + "threefold.io".to_string(), + "ThreeFold main domain".to_string(), + ); + + let record = Record { + name: "www".to_string(), + text: "ThreeFold Website".to_string(), + category: RecordType::A, + addr: vec!["192.168.1.1".to_string()], + }; + + domain.add_record(record); + domain.add_admin("alice_pubkey".to_string()); + + println!("Created domain: {:?}", domain); + + // Create wallets + let mut alice_wallet = Wallet::new( + 1, + "Alice's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GALICE...".to_string(), + ); + + alice_wallet.set_asset("TFT".to_string(), 1000.0); + alice_wallet.set_asset("XLM".to_string(), 100.0); + + let mut bob_wallet = Wallet::new( + 2, + "Bob's TFT Wallet".to_string(), + "Main TFT wallet".to_string(), + "Stellar".to_string(), + "GBOB...".to_string(), + ); + + bob_wallet.set_asset("TFT".to_string(), 500.0); + + println!("Created wallets: {:?}, {:?}", alice_wallet, bob_wallet); + + // Link wallets to members + alice.link_wallet(alice_wallet.id); + bob.link_wallet(bob_wallet.id); + + println!("Linked wallets to members"); + + // Demonstrate wallet operations + println!("\nDemonstrating wallet operations:"); + + println!("Alice's wallet before transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + println!("Bob's wallet before transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + // Simulate a transfer of 100 TFT from Alice to Bob + alice_wallet.set_asset("TFT".to_string(), 900.0); // Decrease Alice's TFT by 100 + bob_wallet.set_asset("TFT".to_string(), 600.0); // Increase Bob's TFT by 100 + + println!("Alice's wallet after transfer: {:?}", alice_wallet); + println!("Alice's wallet total value: {}", alice_wallet.total_value()); + + println!("Bob's wallet after transfer: {:?}", bob_wallet); + println!("Bob's wallet total value: {}", bob_wallet.total_value()); + + println!("\nCircle standalone demo completed successfully!"); +} \ No newline at end of file diff --git a/herodb/src/db/model_methods.rs b/herodb/src/db/model_methods.rs index b6d338b..63a9a6f 100644 --- a/herodb/src/db/model_methods.rs +++ b/herodb/src/db/model_methods.rs @@ -6,6 +6,7 @@ use crate::models::gov::{ Company, Shareholder, Meeting, User, Vote, Resolution, Committee, ComplianceRequirement, ComplianceDocument, ComplianceAudit }; +use crate::models::circle::{Circle, Member, Name, Wallet, Asset}; // Implement model-specific methods for Product impl_model_methods!(Product, product, products); @@ -59,4 +60,16 @@ impl_model_methods!(ComplianceRequirement, compliance_requirement, compliance_re impl_model_methods!(ComplianceDocument, compliance_document, compliance_documents); // Implement model-specific methods for ComplianceAudit -impl_model_methods!(ComplianceAudit, compliance_audit, compliance_audits); \ No newline at end of file +impl_model_methods!(ComplianceAudit, compliance_audit, compliance_audits); + +// Implement model-specific methods for Circle +impl_model_methods!(Circle, circle, circles); + +// Implement model-specific methods for Member +impl_model_methods!(Member, member, members); + +// Implement model-specific methods for Name +impl_model_methods!(Name, name, names); + +// Implement model-specific methods for Wallet +impl_model_methods!(Wallet, wallet, wallets); \ No newline at end of file diff --git a/herodb/src/models/biz/contract.rs b/herodb/src/models/biz/contract.rs index 2babb22..ffc6dcc 100644 --- a/herodb/src/models/biz/contract.rs +++ b/herodb/src/models/biz/contract.rs @@ -235,6 +235,10 @@ impl ContractBuilder { } } + +impl Storable for Contract {} + + // Implement Model trait impl Model for Contract { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/currency.rs b/herodb/src/models/biz/currency.rs index 04e9005..933c6f9 100644 --- a/herodb/src/models/biz/currency.rs +++ b/herodb/src/models/biz/currency.rs @@ -1,4 +1,5 @@ -use crate::db::model::{Model, Storable}; +use crate::db::model::Model; +use crate::db::{Storable, DbError, DbResult}; use chrono::{DateTime, Duration, Utc}; use rhai::{CustomType, EvalAltResult, TypeBuilder}; use serde::{Deserialize, Serialize}; @@ -72,6 +73,9 @@ impl CurrencyBuilder { } } +// Implement Storable trait +impl Storable for Currency {} + // Implement Model trait impl Model for Currency { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/customer.rs b/herodb/src/models/biz/customer.rs index 7cb68cf..088e669 100644 --- a/herodb/src/models/biz/customer.rs +++ b/herodb/src/models/biz/customer.rs @@ -133,6 +133,9 @@ impl CustomerBuilder { } } +impl Storable for Customer {} + + // Implement Model trait impl Model for Customer { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/exchange_rate.rs b/herodb/src/models/biz/exchange_rate.rs index a020582..9ec1a10 100644 --- a/herodb/src/models/biz/exchange_rate.rs +++ b/herodb/src/models/biz/exchange_rate.rs @@ -91,6 +91,9 @@ impl ExchangeRateBuilder { } } + + +impl Storable for ExchangeRate {} // Implement Model trait impl Model for ExchangeRate { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/invoice.rs b/herodb/src/models/biz/invoice.rs index 956eb81..8dd3b8a 100644 --- a/herodb/src/models/biz/invoice.rs +++ b/herodb/src/models/biz/invoice.rs @@ -500,6 +500,8 @@ impl InvoiceBuilder { } } +impl Storable for Invoice {} + // Implement Model trait impl Model for Invoice { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/product.rs b/herodb/src/models/biz/product.rs index 8957120..498627e 100644 --- a/herodb/src/models/biz/product.rs +++ b/herodb/src/models/biz/product.rs @@ -1,4 +1,5 @@ -use crate::db::model::{Model, Storable}; +use crate::db::model::Model; +use crate::db::Storable; use chrono::{DateTime, Duration, Utc}; use rhai::{CustomType, EvalAltResult, TypeBuilder, export_module}; use serde::{Deserialize, Serialize}; @@ -342,6 +343,9 @@ impl ProductBuilder { } } +// Implement Storable trait +impl Storable for Product {} + // Implement Model trait impl Model for Product { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/sale.rs b/herodb/src/models/biz/sale.rs index cb9fbb3..ba279ee 100644 --- a/herodb/src/models/biz/sale.rs +++ b/herodb/src/models/biz/sale.rs @@ -1,4 +1,4 @@ -use crate::db::{Model, Storable}; +use crate::db::{Model, Storable, DbError, DbResult}; use crate::models::biz::Currency; // Use crate:: for importing from the module // use super::db::Model; // Removed old Model trait import use chrono::{DateTime, Utc}; @@ -566,6 +566,9 @@ impl SaleBuilder { } } +// Implement Storable trait +impl Storable for Sale {} + // Implement Model trait impl Model for Sale { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/biz/service.rs b/herodb/src/models/biz/service.rs index 6a3a505..ddac8cc 100644 --- a/herodb/src/models/biz/service.rs +++ b/herodb/src/models/biz/service.rs @@ -1,5 +1,5 @@ use crate::models::biz::Currency; // Use crate:: for importing from the module -use crate::db::{Model, Storable}; // Import Model trait from db module +use crate::db::{Model, Storable, DbError, DbResult}; // Import Model trait from db module use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -491,6 +491,10 @@ impl ServiceBuilder { } } +// Implement Storable trait +impl Storable for Service { +} + // Implement Model trait impl Model for Service { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/circle/circle.rs b/herodb/src/models/circle/circle.rs index d33bfd8..934902f 100644 --- a/herodb/src/models/circle/circle.rs +++ b/herodb/src/models/circle/circle.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{Model, Storable}; +use crate::db::{Model, Storable, DbError, DbResult}; use std::collections::HashMap; /// Circle represents a collection of members (users or other circles) @@ -28,6 +28,9 @@ impl Circle { } } +// Implement Storable trait +impl Storable for Circle {} + // Implement Model trait impl Model for Circle { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/circle/member.rs b/herodb/src/models/circle/member.rs index 1d4d410..00669f5 100644 --- a/herodb/src/models/circle/member.rs +++ b/herodb/src/models/circle/member.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{Model, Storable}; +use crate::db::{Model, Storable, DbError, DbResult}; use std::collections::HashMap; /// Role represents the role of a member in a circle @@ -67,6 +67,10 @@ impl Member { } } +// Implement Storable trait +impl Storable for Member { +} + // Implement Model trait impl Model for Member { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/circle/name.rs b/herodb/src/models/circle/name.rs index 0cc5db2..3756cba 100644 --- a/herodb/src/models/circle/name.rs +++ b/herodb/src/models/circle/name.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{Model, Storable}; +use crate::db::{Model, Storable, DbError, DbResult}; /// Record types for a DNS record #[derive(Debug, Clone, Serialize, Deserialize)] @@ -57,6 +57,10 @@ impl Name { } } +// Implement Storable trait +impl Storable for Name { +} + // Implement Model trait impl Model for Name { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/circle/wallet.rs b/herodb/src/models/circle/wallet.rs index af3f4c1..4fcb548 100644 --- a/herodb/src/models/circle/wallet.rs +++ b/herodb/src/models/circle/wallet.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{Model, Storable}; +use crate::db::{Model, Storable, DbError, DbResult}; use std::collections::HashMap; /// Asset represents a cryptocurrency asset in a wallet @@ -70,7 +70,8 @@ impl Wallet { } // Implement Storable trait -impl Storable for Wallet {} +impl Storable for Wallet { +} // Implement Model trait impl Model for Wallet { diff --git a/herodb/src/models/gov/company.rs b/herodb/src/models/gov/company.rs index 2f166dc..577d57d 100644 --- a/herodb/src/models/gov/company.rs +++ b/herodb/src/models/gov/company.rs @@ -1,5 +1,7 @@ -use crate::db::{Model, Storable, DbError, DbResult}; +use crate::db::{Model, Storable, DbResult}; +use crate::db::db::DB; use super::shareholder::Shareholder; // Use super:: for sibling module +use super::Resolution; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; @@ -87,7 +89,7 @@ pub struct Company { // Removed shareholders property } - +impl Storable for Company{} // Model requires get_id and db_prefix impl Model for Company { @@ -150,24 +152,22 @@ impl Company { } /// Link this company to a Circle for access control - pub fn link_to_circle(&mut self, circle_id: u32) -> DbResult<()> { + pub fn link_to_circle(&mut self, circle_id: u32) { // Implementation would involve updating a mapping in a separate database // For now, we'll just update the timestamp to indicate the change self.updated_at = Utc::now(); - Ok(()) } /// Link this company to a Customer in the biz module - pub fn link_to_customer(&mut self, customer_id: u32) -> DbResult<()> { + pub fn link_to_customer(&mut self, customer_id: u32) { // Implementation would involve updating a mapping in a separate database // For now, we'll just update the timestamp to indicate the change self.updated_at = Utc::now(); - Ok(()) } /// Get all resolutions for this company - pub fn get_resolutions(&self, db: &DB) -> DbResult> { - let all_resolutions = db.list::()?; + pub fn get_resolutions(&self, db: &DB) -> DbResult> { + let all_resolutions = db.list::()?; let company_resolutions = all_resolutions .into_iter() .filter(|resolution| resolution.company_id == self.id) diff --git a/herodb/src/models/gov/compliance.rs b/herodb/src/models/gov/compliance.rs deleted file mode 100644 index e471ae4..0000000 --- a/herodb/src/models/gov/compliance.rs +++ /dev/null @@ -1,207 +0,0 @@ -use chrono::{DateTime, Utc}; -use serde::{Deserialize, Serialize}; -use crate::db::{Model, Storable, DB, DbError, DbResult}; -use crate::models::gov::Company; - -/// ComplianceRequirement represents a regulatory requirement -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct ComplianceRequirement { - pub id: u32, - pub company_id: u32, - pub title: String, - pub description: String, - pub regulation: String, - pub authority: String, - pub deadline: DateTime, - pub status: String, - pub created_at: DateTime, - pub updated_at: DateTime, -} - -/// ComplianceDocument represents a compliance document -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct ComplianceDocument { - pub id: u32, - pub requirement_id: u32, - pub title: String, - pub description: String, - pub file_path: String, - pub file_type: String, - pub uploaded_by: u32, // User ID - pub uploaded_at: DateTime, - pub created_at: DateTime, - pub updated_at: DateTime, -} - -/// ComplianceAudit represents a compliance audit -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct ComplianceAudit { - pub id: u32, - pub company_id: u32, - pub title: String, - pub description: String, - pub auditor: String, - pub start_date: DateTime, - pub end_date: DateTime, - pub status: String, - pub findings: String, - pub created_at: DateTime, - pub updated_at: DateTime, -} - -impl ComplianceRequirement { - /// Create a new compliance requirement with default values - pub fn new( - id: u32, - company_id: u32, - title: String, - description: String, - regulation: String, - authority: String, - deadline: DateTime, - ) -> Self { - let now = Utc::now(); - Self { - id, - company_id, - title, - description, - regulation, - authority, - deadline, - status: "Pending".to_string(), - created_at: now, - updated_at: now, - } - } - - /// Update the status of the requirement - pub fn update_status(&mut self, status: String) { - self.status = status; - self.updated_at = Utc::now(); - } - - /// Get the company associated with this requirement - pub fn get_company(&self, db: &DB) -> DbResult { - db.get::(self.company_id) - } - - /// Get all documents associated with this requirement - pub fn get_documents(&self, db: &DB) -> DbResult> { - let all_documents = db.list::()?; - let requirement_documents = all_documents - .into_iter() - .filter(|doc| doc.requirement_id == self.id) - .collect(); - - Ok(requirement_documents) - } -} - -impl ComplianceDocument { - /// Create a new compliance document with default values - pub fn new( - id: u32, - requirement_id: u32, - title: String, - description: String, - file_path: String, - file_type: String, - uploaded_by: u32, - ) -> Self { - let now = Utc::now(); - Self { - id, - requirement_id, - title, - description, - file_path, - file_type, - uploaded_by, - uploaded_at: now, - created_at: now, - updated_at: now, - } - } - - /// Get the requirement associated with this document - pub fn get_requirement(&self, db: &DB) -> DbResult { - db.get::(self.requirement_id) - } -} - -impl ComplianceAudit { - /// Create a new compliance audit with default values - pub fn new( - id: u32, - company_id: u32, - title: String, - description: String, - auditor: String, - start_date: DateTime, - end_date: DateTime, - ) -> Self { - let now = Utc::now(); - Self { - id, - company_id, - title, - description, - auditor, - start_date, - end_date, - status: "Planned".to_string(), - findings: String::new(), - created_at: now, - updated_at: now, - } - } - - /// Update the status of the audit - pub fn update_status(&mut self, status: String) { - self.status = status; - self.updated_at = Utc::now(); - } - - /// Update the findings of the audit - pub fn update_findings(&mut self, findings: String) { - self.findings = findings; - self.updated_at = Utc::now(); - } - - /// Get the company associated with this audit - pub fn get_company(&self, db: &DB) -> DbResult { - db.get::(self.company_id) - } -} - -// Implement Model trait -impl Model for ComplianceRequirement { - fn get_id(&self) -> u32 { - self.id - } - - fn db_prefix() -> &'static str { - "compliance_requirement" - } -} - -impl Model for ComplianceDocument { - fn get_id(&self) -> u32 { - self.id - } - - fn db_prefix() -> &'static str { - "compliance_document" - } -} - -impl Model for ComplianceAudit { - fn get_id(&self) -> u32 { - self.id - } - - fn db_prefix() -> &'static str { - "compliance_audit" - } -} \ No newline at end of file diff --git a/herodb/src/models/gov/meeting.rs b/herodb/src/models/gov/meeting.rs index a5901e4..a9ca871 100644 --- a/herodb/src/models/gov/meeting.rs +++ b/herodb/src/models/gov/meeting.rs @@ -175,6 +175,7 @@ impl Meeting { } } +impl Storable for Meeting{} // Implement Model trait impl Model for Meeting { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/gov/mod.rs b/herodb/src/models/gov/mod.rs index 5b1dd7b..ae3b0fa 100644 --- a/herodb/src/models/gov/mod.rs +++ b/herodb/src/models/gov/mod.rs @@ -6,7 +6,6 @@ pub mod vote; pub mod resolution; // All modules: pub mod committee; -pub mod compliance; // Re-export all model types for convenience pub use company::{Company, CompanyStatus, BusinessType}; @@ -16,7 +15,6 @@ pub use user::User; pub use vote::{Vote, VoteOption, Ballot, VoteStatus}; pub use resolution::{Resolution, ResolutionStatus, Approval}; pub use committee::{Committee, CommitteeMember, CommitteeRole}; -pub use compliance::{ComplianceRequirement, ComplianceDocument, ComplianceAudit}; // Re-export database components from db module pub use crate::db::{DB, DBBuilder, Model, Storable, DbError, DbResult}; \ No newline at end of file diff --git a/herodb/src/models/gov/resolution.rs b/herodb/src/models/gov/resolution.rs index e0aa282..735c6a4 100644 --- a/herodb/src/models/gov/resolution.rs +++ b/herodb/src/models/gov/resolution.rs @@ -180,6 +180,9 @@ impl Resolution { } } + +impl Storable for Resolution{} + // Implement Model trait impl Model for Resolution { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/gov/shareholder.rs b/herodb/src/models/gov/shareholder.rs index 19e1c97..2bde690 100644 --- a/herodb/src/models/gov/shareholder.rs +++ b/herodb/src/models/gov/shareholder.rs @@ -63,6 +63,8 @@ impl Shareholder { } } +impl Storable for Shareholder{} + // Implement Model trait impl Model for Shareholder { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/gov/user.rs b/herodb/src/models/gov/user.rs index b55931c..667cd09 100644 --- a/herodb/src/models/gov/user.rs +++ b/herodb/src/models/gov/user.rs @@ -42,6 +42,8 @@ impl User { } } +impl Storable for User{} + // Implement Model trait impl Model for User { fn get_id(&self) -> u32 { diff --git a/herodb/src/models/gov/vote.rs b/herodb/src/models/gov/vote.rs index 0025097..73389fc 100644 --- a/herodb/src/models/gov/vote.rs +++ b/herodb/src/models/gov/vote.rs @@ -51,7 +51,7 @@ pub struct Ballot { pub created_at: DateTime, } -// Removed old Model trait implementation +impl Storable for Vote{} impl Vote { /// Create a new vote with default timestamps