From 53c6fb18fde1a003d9987b440516f5276ddb1116 Mon Sep 17 00:00:00 2001 From: core Date: Sat, 18 Nov 2023 22:51:45 -0500 Subject: [PATCH] new work --- Cargo.lock | 1891 +++-------------- Cargo.toml | 6 +- Dockerfile | 4 +- database_structure | 2 + docs/docusaurus.config.js | 4 +- tfcli/src/main.rs | 8 +- tfclient/src/main.rs | 2 +- {trifid-api => trifid-api-old}/.env | 0 trifid-api-old/build.rs | 3 + .../config.example.toml | 20 +- .../src/auth_tokens.rs | 2 +- .../src/codegen/mod.rs | 0 trifid-api-old/src/config.rs | 736 +++++++ {trifid-api => trifid-api-old}/src/crypto.rs | 2 +- {trifid-api => trifid-api-old}/src/cursor.rs | 2 +- trifid-api-old/src/error.rs | 132 ++ .../src/legacy_keystore.rs | 0 .../src/magic_link.rs | 2 +- trifid-api-old/src/response.rs | 49 + trifid-api-old/src/routes/mod.rs | 2 + .../src/routes/v1/auth/magic_link.rs | 2 +- .../src/routes/v1/auth/mod.rs | 0 .../src/routes/v1/auth/totp.rs | 2 +- .../src/routes/v1/auth/verify_magic_link.rs | 2 +- .../src/routes/v1/dnclient.rs | 0 .../src/routes/v1/hosts.rs | 2 +- trifid-api-old/src/routes/v1/mod.rs | 10 + .../src/routes/v1/networks.rs | 2 +- .../src/routes/v1/organization.rs | 4 +- .../src/routes/v1/roles.rs | 2 +- trifid-api-old/src/routes/v1/signup.rs | 151 ++ .../src/routes/v1/totp_authenticators.rs | 4 +- .../src/routes/v1/trifid.rs | 4 +- .../routes/v1/verify_totp_authenticators.rs | 2 +- .../src/routes/v2/enroll.rs | 0 .../src/routes/v2/mod.rs | 0 .../src/routes/v2/whoami.rs | 2 +- {trifid-api => trifid-api-old}/src/timers.rs | 2 +- {trifid-api => trifid-api-old}/src/tokens.rs | 2 +- .../trifid_api_entities/Cargo.toml | 0 .../trifid_api_entities/src/entity/api_key.rs | 0 .../src/entity/api_key_scope.rs | 0 .../src/entity/auth_token.rs | 0 .../src/entity/firewall_rule.rs | 0 .../trifid_api_entities/src/entity/host.rs | 0 .../src/entity/host_config_override.rs | 0 .../src/entity/host_enrollment_code.rs | 0 .../src/entity/host_static_address.rs | 0 .../src/entity/keystore_entry.rs | 0 .../src/entity/keystore_host.rs | 0 .../src/entity/magic_link.rs | 0 .../trifid_api_entities/src/entity/mod.rs | 0 .../trifid_api_entities/src/entity/network.rs | 0 .../src/entity/organization.rs | 0 .../trifid_api_entities/src/entity/prelude.rs | 0 .../trifid_api_entities/src/entity/role.rs | 0 .../src/entity/session_token.rs | 0 .../src/entity/signing_ca.rs | 0 .../src/entity/totp_authenticator.rs | 0 .../trifid_api_entities/src/entity/user.rs | 0 .../trifid_api_entities/src/lib.rs | 0 .../trifid_api_migration/Cargo.toml | 0 .../trifid_api_migration/README.md | 0 .../trifid_api_migration/src/lib.rs | 0 .../m20230402_162601_create_table_users.rs | 0 ...0230402_183515_create_table_magic_links.rs | 0 ...0402_213712_create_table_session_tokens.rs | 0 ...30402_232316_create_table_organizations.rs | 0 .../m20230402_233043_create_table_api_keys.rs | 0 ...402_233047_create_table_api_keys_scopes.rs | 0 ...234025_create_table_totp_authenticators.rs | 0 ...0230403_002256_create_table_auth_tokens.rs | 0 ...0230403_142517_create_table_signing_cas.rs | 0 .../m20230403_173431_create_table_networks.rs | 0 .../m20230404_133809_create_table_roles.rs | 0 ...0404_133813_create_table_firewall_rules.rs | 0 .../m20230427_170037_create_table_hosts.rs | 0 ...517_create_table_hosts_static_addresses.rs | 0 ...529_create_table_hosts_config_overrides.rs | 0 ...0511_create_table_host_enrollment_codes.rs | 0 ...0815_225520_create_table_keystore_hosts.rs | 0 ...15_230218_create_table_keystore_entries.rs | 0 .../trifid_api_migration/src/main.rs | 0 .../trifid_api_entities/src/entity/api_key.rs | 0 .../src/entity/api_key_scope.rs | 0 .../src/entity/auth_token.rs | 0 .../src/entity/firewall_rule.rs | 0 .../src/entity/magic_link.rs | 0 .../trifid_api_entities/src/entity/mod.rs | 0 .../trifid_api_entities/src/entity/network.rs | 0 .../src/entity/organization.rs | 0 .../trifid_api_entities/src/entity/prelude.rs | 0 .../trifid_api_entities/src/entity/role.rs | 0 .../src/entity/session_token.rs | 0 .../src/entity/signing_ca.rs | 0 .../src/entity/totp_authenticator.rs | 0 .../trifid_api_entities/src/entity/user.rs | 0 .../trifiddata/tfks.toml | 0 trifid-api/Cargo.toml | 55 +- trifid-api/build.rs | 4 +- trifid-api/config.toml | 18 + trifid-api/diesel.toml | 6 +- trifid-api/migrations/.keep | 0 .../down.sql | 6 + .../up.sql | 36 + .../2023-11-19-033954_create_users/down.sql | 1 + .../2023-11-19-033954_create_users/up.sql | 4 + trifid-api/src/config.rs | 747 +------ trifid-api/src/error.rs | 73 +- trifid-api/src/macros.rs | 63 + trifid-api/src/main.rs | 211 +- trifid-api/src/response.rs | 73 +- trifid-api/src/routes/mod.rs | 3 +- trifid-api/src/routes/v1/mod.rs | 11 +- trifid-api/src/routes/v1/signup.rs | 152 +- 115 files changed, 1715 insertions(+), 2808 deletions(-) create mode 100644 database_structure rename {trifid-api => trifid-api-old}/.env (100%) create mode 100644 trifid-api-old/build.rs rename {trifid-api => trifid-api-old}/config.example.toml (91%) rename {trifid-api => trifid-api-old}/src/auth_tokens.rs (98%) rename {trifid-api => trifid-api-old}/src/codegen/mod.rs (100%) create mode 100644 trifid-api-old/src/config.rs rename {trifid-api => trifid-api-old}/src/crypto.rs (94%) rename {trifid-api => trifid-api-old}/src/cursor.rs (94%) create mode 100644 trifid-api-old/src/error.rs rename {trifid-api => trifid-api-old}/src/legacy_keystore.rs (100%) rename {trifid-api => trifid-api-old}/src/magic_link.rs (89%) create mode 100644 trifid-api-old/src/response.rs create mode 100644 trifid-api-old/src/routes/mod.rs rename {trifid-api => trifid-api-old}/src/routes/v1/auth/magic_link.rs (97%) rename {trifid-api => trifid-api-old}/src/routes/v1/auth/mod.rs (100%) rename {trifid-api => trifid-api-old}/src/routes/v1/auth/totp.rs (98%) rename {trifid-api => trifid-api-old}/src/routes/v1/auth/verify_magic_link.rs (98%) rename {trifid-api => trifid-api-old}/src/routes/v1/dnclient.rs (100%) rename {trifid-api => trifid-api-old}/src/routes/v1/hosts.rs (99%) create mode 100644 trifid-api-old/src/routes/v1/mod.rs rename {trifid-api => trifid-api-old}/src/routes/v1/networks.rs (99%) rename {trifid-api => trifid-api-old}/src/routes/v1/organization.rs (98%) rename {trifid-api => trifid-api-old}/src/routes/v1/roles.rs (99%) create mode 100644 trifid-api-old/src/routes/v1/signup.rs rename {trifid-api => trifid-api-old}/src/routes/v1/totp_authenticators.rs (97%) rename {trifid-api => trifid-api-old}/src/routes/v1/trifid.rs (91%) rename {trifid-api => trifid-api-old}/src/routes/v1/verify_totp_authenticators.rs (98%) rename {trifid-api => trifid-api-old}/src/routes/v2/enroll.rs (100%) rename {trifid-api => trifid-api-old}/src/routes/v2/mod.rs (100%) rename {trifid-api => trifid-api-old}/src/routes/v2/whoami.rs (98%) rename {trifid-api => trifid-api-old}/src/timers.rs (91%) rename {trifid-api => trifid-api-old}/src/tokens.rs (94%) rename {trifid-api => trifid-api-old}/trifid_api_entities/Cargo.toml (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/api_key.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/api_key_scope.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/auth_token.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/firewall_rule.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/host.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/host_config_override.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/host_enrollment_code.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/host_static_address.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/keystore_entry.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/keystore_host.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/magic_link.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/mod.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/network.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/organization.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/prelude.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/role.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/session_token.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/signing_ca.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/totp_authenticator.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/entity/user.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_entities/src/lib.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/Cargo.toml (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/README.md (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/lib.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_162601_create_table_users.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_183515_create_table_magic_links.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_213712_create_table_session_tokens.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_232316_create_table_organizations.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_233043_create_table_api_keys.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_233047_create_table_api_keys_scopes.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230402_234025_create_table_totp_authenticators.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230403_002256_create_table_auth_tokens.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230403_142517_create_table_signing_cas.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230403_173431_create_table_networks.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230404_133809_create_table_roles.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230511_120511_create_table_host_enrollment_codes.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230815_225520_create_table_keystore_hosts.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/m20230815_230218_create_table_keystore_entries.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/src/main.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/api_key.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/api_key_scope.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/auth_token.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/firewall_rule.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/magic_link.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/mod.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/network.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/organization.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/prelude.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/role.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/session_token.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/signing_ca.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/totp_authenticator.rs (100%) rename {trifid-api => trifid-api-old}/trifid_api_migration/trifid_api_entities/src/entity/user.rs (100%) rename {trifid-api => trifid-api-old}/trifiddata/tfks.toml (100%) create mode 100644 trifid-api/config.toml create mode 100644 trifid-api/migrations/.keep create mode 100644 trifid-api/migrations/00000000000000_diesel_initial_setup/down.sql create mode 100644 trifid-api/migrations/00000000000000_diesel_initial_setup/up.sql create mode 100644 trifid-api/migrations/2023-11-19-033954_create_users/down.sql create mode 100644 trifid-api/migrations/2023-11-19-033954_create_users/up.sql create mode 100644 trifid-api/src/macros.rs diff --git a/Cargo.lock b/Cargo.lock index a86fbf4..7d4eb36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,7 +44,7 @@ dependencies = [ "actix-rt", "actix-service", "actix-utils", - "ahash 0.8.6", + "ahash", "base64 0.21.5", "bitflags 2.4.1", "brotli", @@ -83,17 +83,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "actix-request-identifier" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f620de7c806297b88cf39da5ef4293a59f7dc219a9838433e83238e53a9c7057" -dependencies = [ - "actix-web", - "futures", - "uuid", -] - [[package]] name = "actix-router" version = "0.5.1" @@ -170,7 +159,7 @@ dependencies = [ "actix-service", "actix-utils", "actix-web-codegen", - "ahash 0.8.6", + "ahash", "bytes", "bytestring", "cfg-if", @@ -222,52 +211,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "aead" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" -dependencies = [ - "crypto-common", - "generic-array", -] - -[[package]] -name = "aes" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "aes-gcm" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" -dependencies = [ - "aead", - "aes", - "cipher", - "ctr", - "ghash", - "subtle", -] - -[[package]] -name = "ahash" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.6" @@ -290,12 +233,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "alloc-no-stdlib" version = "2.0.4" @@ -311,12 +248,6 @@ dependencies = [ "alloc-no-stdlib", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -380,147 +311,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - -[[package]] -name = "async-attributes" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" -dependencies = [ - "async-lock", - "async-task", - "concurrent-queue", - "fastrand 2.0.1", - "futures-lite", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" -dependencies = [ - "async-channel", - "async-executor", - "async-io", - "async-lock", - "blocking", - "futures-lite", - "once_cell", - "tokio", -] - -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite", - "log", - "parking", - "polling", - "rustix 0.37.27", - "slab", - "socket2 0.4.10", - "waker-fn", -] - -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" -dependencies = [ - "async-attributes", - "async-channel", - "async-global-executor", - "async-io", - "async-lock", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-stream" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "async-task" -version = "4.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" - [[package]] name = "async-trait" version = "0.1.74" @@ -532,21 +322,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "atoi" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" -dependencies = [ - "num-traits", -] - -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.1.0" @@ -568,12 +343,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base32" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" - [[package]] name = "base64" version = "0.13.1" @@ -603,14 +372,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] -name = "bigdecimal" -version = "0.3.1" +name = "bb8" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +checksum = "98b4b0f25f18bcdc3ac72bdb486ed0acf7e185221fd4dc985bc15db5800b0ba2" dependencies = [ - "num-bigint", - "num-integer", - "num-traits", + "async-trait", + "futures-channel", + "futures-util", + "parking_lot", + "tokio", ] [[package]] @@ -647,21 +418,6 @@ name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] [[package]] name = "block-buffer" @@ -672,67 +428,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "blocking" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" -dependencies = [ - "async-channel", - "async-lock", - "async-task", - "fastrand 2.0.1", - "futures-io", - "futures-lite", - "piper", - "tracing", -] - -[[package]] -name = "borsh" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" -dependencies = [ - "borsh-derive", - "hashbrown 0.13.2", -] - -[[package]] -name = "borsh-derive" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" -dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", - "proc-macro-crate", - "proc-macro2", - "syn 1.0.109", -] - -[[package]] -name = "borsh-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "borsh-schema-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "brotli" version = "3.4.0" @@ -760,28 +455,6 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" -[[package]] -name = "bytecheck" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627" -dependencies = [ - "bytecheck_derive", - "ptr_meta", - "simdutf8", -] - -[[package]] -name = "bytecheck_derive" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -849,16 +522,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", -] - [[package]] name = "clang-sys" version = "1.6.1" @@ -927,27 +590,12 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "concurrent-queue" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "const-oid" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" -[[package]] -name = "constant_time_eq" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" - [[package]] name = "convert_case" version = "0.4.0" @@ -990,21 +638,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" - [[package]] name = "crc32fast" version = "1.3.2" @@ -1014,25 +647,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - [[package]] name = "crossterm" version = "0.25.0" @@ -1065,19 +679,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "rand_core", "typenum", ] -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher", -] - [[package]] name = "ctrlc" version = "3.4.1" @@ -1159,7 +763,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", - "pem-rfc7468", "zeroize", ] @@ -1173,17 +776,6 @@ dependencies = [ "serde", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -1197,6 +789,65 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "diesel" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8" +dependencies = [ + "bitflags 2.4.1", + "byteorder", + "diesel_derives", + "itoa", +] + +[[package]] +name = "diesel-async" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acada1517534c92d3f382217b485db8a8638f111b0e3f2a2a8e26165050f77be" +dependencies = [ + "async-trait", + "bb8", + "diesel", + "futures-util", + "scoped-futures", + "tokio", + "tokio-postgres", +] + +[[package]] +name = "diesel_derives" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "diesel_migrations" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6036b3f0120c5961381b570ee20a02432d7e2d27ea60de9578799cf9156914ac" +dependencies = [ + "diesel", + "migrations_internals", + "migrations_macros", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn 2.0.38", +] + [[package]] name = "digest" version = "0.10.7" @@ -1204,7 +855,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", "subtle", ] @@ -1232,7 +882,7 @@ dependencies = [ [[package]] name = "dnapi-rs" -version = "0.2.0" +version = "0.2.1" dependencies = [ "base64 0.21.5", "base64-serde", @@ -1243,16 +893,10 @@ dependencies = [ "serde", "serde_json", "serde_with", - "trifid-pki 0.1.11", + "trifid-pki", "url", ] -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - [[package]] name = "ed25519" version = "2.2.3" @@ -1283,9 +927,6 @@ name = "either" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -dependencies = [ - "serde", -] [[package]] name = "encoding_rs" @@ -1296,6 +937,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1313,36 +967,10 @@ dependencies = [ ] [[package]] -name = "etcetera" -version = "0.8.0" +name = "fallible-iterator" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" -dependencies = [ - "cfg-if", - "home", - "windows-sys 0.48.0", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fiat-crypto" @@ -1366,17 +994,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin 0.9.8", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1392,27 +1009,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "futures" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.29" @@ -1429,49 +1025,12 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" -[[package]] -name = "futures-executor" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-intrusive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot", -] - [[package]] name = "futures-io" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.29" @@ -1534,16 +1093,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "ghash" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40" -dependencies = [ - "opaque-debug", - "polyval", -] - [[package]] name = "gimli" version = "0.28.0" @@ -1556,18 +1105,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - [[package]] name = "h2" version = "0.3.21" @@ -1592,46 +1129,18 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.7", -] - -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash 0.8.6", -] [[package]] name = "hashbrown" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" -dependencies = [ - "ahash 0.8.6", - "allocator-api2", -] - -[[package]] -name = "hashlink" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" -dependencies = [ - "hashbrown 0.14.2", -] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "hermit-abi" @@ -1645,15 +1154,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hkdf" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" -dependencies = [ - "hmac", -] - [[package]] name = "hmac" version = "0.12.1" @@ -1706,6 +1206,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.27" @@ -1805,46 +1311,6 @@ dependencies = [ "serde", ] -[[package]] -name = "inherent" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce243b1bfa62ffc028f1cc3b6034ec63d649f3031bc8a4fbbb004e1ac17d1f68" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.9.0" @@ -1861,19 +1327,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.21", + "rustix", "windows-sys 0.48.0", ] -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.9" @@ -1898,15 +1355,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "language-tags" version = "0.3.2" @@ -1918,9 +1366,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] [[package]] name = "lazycell" @@ -1944,29 +1389,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "libsqlite3-sys" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.10" @@ -2005,18 +1427,6 @@ name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -dependencies = [ - "value-bag", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] [[package]] name = "md-5" @@ -2034,6 +1444,27 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "migrations_internals" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f23f71580015254b020e856feac3df5878c2c7a8812297edd6c0a485ac9dada" +dependencies = [ + "serde", + "toml 0.7.8", +] + +[[package]] +name = "migrations_macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cce3325ac70e67bbab5bd837a31cae01f1a6db64e0e744a33cb03a543469ef08" +dependencies = [ + "migrations_internals", + "proc-macro2", + "quote", +] + [[package]] name = "mime" version = "0.3.17" @@ -2096,55 +1527,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num-bigint" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-bigint-dig" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.17" @@ -2152,7 +1534,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -2189,57 +1570,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "option-ext" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "ordered-float" -version = "3.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" -dependencies = [ - "num-traits", -] - -[[package]] -name = "ouroboros" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2ba07320d39dfea882faa70554b4bd342a5f273ed59ba7c1c6b4c840492c954" -dependencies = [ - "aliasable", - "ouroboros_macro", - "static_assertions", -] - -[[package]] -name = "ouroboros_macro" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "parking" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" - [[package]] name = "parking_lot" version = "0.12.1" @@ -2284,21 +1620,30 @@ dependencies = [ "base64 0.13.1", ] -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - [[package]] name = "percent-encoding" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -2311,28 +1656,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "piper" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" -dependencies = [ - "atomic-waker", - "fastrand 2.0.1", - "futures-io", -] - -[[package]] -name = "pkcs1" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" -dependencies = [ - "der", - "pkcs8", - "spki", -] - [[package]] name = "pkcs8" version = "0.10.2" @@ -2356,31 +1679,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" [[package]] -name = "polling" -version = "2.8.0" +name = "postgres-protocol" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +checksum = "49b6c5ef183cd3ab4ba005f1ca64c21e8bd97ce4699cfea9e8d9a2c4958ca520" dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", + "base64 0.21.5", + "byteorder", + "bytes", + "fallible-iterator", + "hmac", + "md-5", + "memchr", + "rand", + "sha2", + "stringprep", ] [[package]] -name = "polyval" -version = "0.6.1" +name = "postgres-types" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb" +checksum = "8d2234cdee9408b523530a9b6d2d6b373d1db34f6a8e51dc03ded1828d7fb67c" dependencies = [ - "cfg-if", - "cpufeatures", - "opaque-debug", - "universal-hash", + "bytes", + "fallible-iterator", + "postgres-protocol", ] [[package]] @@ -2405,39 +1729,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml 0.5.11", -] - -[[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.69" @@ -2447,26 +1738,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "ptr_meta" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" -dependencies = [ - "ptr_meta_derive", -] - -[[package]] -name = "ptr_meta_derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "qr2term" version = "0.3.1" @@ -2504,12 +1775,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -2549,15 +1814,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -2586,17 +1842,8 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-automata", + "regex-syntax", ] [[package]] @@ -2607,30 +1854,15 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "rend" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2571463863a6bd50c32f94402933f03457a3fbaf697a707c5be741e459f08fd" -dependencies = [ - "bytecheck", -] - [[package]] name = "reqwest" version = "0.11.22" @@ -2667,7 +1899,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.25.2", + "webpki-roots", "winreg", ] @@ -2680,75 +1912,11 @@ dependencies = [ "cc", "getrandom", "libc", - "spin 0.9.8", + "spin", "untrusted", "windows-sys 0.48.0", ] -[[package]] -name = "rkyv" -version = "0.7.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" -dependencies = [ - "bitvec", - "bytecheck", - "hashbrown 0.12.3", - "ptr_meta", - "rend", - "rkyv_derive", - "seahash", - "tinyvec", - "uuid", -] - -[[package]] -name = "rkyv_derive" -version = "0.7.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2e06b915b5c230a17d7a736d1e2e63ee753c256a8614ef3f5147b13a4f5541d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "rsa" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ef35bf3e7fe15a53c4ab08a998e42271eab13eb0db224126bc7bc4c4bad96d" -dependencies = [ - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8", - "rand_core", - "signature", - "spki", - "subtle", - "zeroize", -] - -[[package]] -name = "rust_decimal" -version = "1.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c4216490d5a413bc6d10fa4742bd7d4955941d062c0ef873141d6b0e7b30fd" -dependencies = [ - "arrayvec", - "borsh", - "bytes", - "num-traits", - "rand", - "rkyv", - "serde", - "serde_json", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2770,20 +1938,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - [[package]] name = "rustix" version = "0.38.21" @@ -2793,7 +1947,7 @@ dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys 0.4.10", + "linux-raw-sys", "windows-sys 0.48.0", ] @@ -2834,6 +1988,16 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "scoped-futures" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1473e24c637950c9bd38763220bea91ec3e095a89f672bbd7a10d03e77ba467" +dependencies = [ + "cfg-if", + "pin-utils", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -2850,171 +2014,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sea-bae" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bd3534a9978d0aa7edd2808dc1f8f31c4d0ecd31ddf71d997b3c98e9f3c9114" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "sea-orm" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14d17105eb8049488d2528580ecc3f0912ab177d600f10e8e292d6994870ba6a" -dependencies = [ - "async-stream", - "async-trait", - "bigdecimal", - "chrono", - "futures", - "log", - "ouroboros", - "rust_decimal", - "sea-orm-macros", - "sea-query", - "sea-query-binder", - "serde", - "serde_json", - "sqlx", - "strum", - "thiserror", - "time", - "tracing", - "url", - "uuid", -] - -[[package]] -name = "sea-orm-cli" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66b46c28caf05824ecd1e68865de762959aa3640e1c21a415a00090e67b1658" -dependencies = [ - "chrono", - "clap", - "dotenvy", - "glob", - "regex", - "sea-schema", - "tracing", - "tracing-subscriber", - "url", -] - -[[package]] -name = "sea-orm-macros" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a836864040c92d0615497eeccf97e1aee312857bf2ab36d74a74ce1c5c2cefc3" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "sea-bae", - "syn 2.0.38", - "unicode-ident", -] - -[[package]] -name = "sea-orm-migration" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a340d727bafe3d817b55f920498cc469e8664e8b654017d2ec93a31aed40b70f" -dependencies = [ - "async-trait", - "clap", - "dotenvy", - "futures", - "sea-orm", - "sea-orm-cli", - "sea-schema", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "sea-query" -version = "0.30.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3e6bba153bb198646c8762c48414942a38db27d142e44735a133cabddcc820" -dependencies = [ - "bigdecimal", - "chrono", - "derivative", - "inherent", - "ordered-float", - "rust_decimal", - "sea-query-derive", - "serde_json", - "time", - "uuid", -] - -[[package]] -name = "sea-query-binder" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36bbb68df92e820e4d5aeb17b4acd5cc8b5d18b2c36a4dd6f4626aabfa7ab1b9" -dependencies = [ - "bigdecimal", - "chrono", - "rust_decimal", - "sea-query", - "serde_json", - "sqlx", - "time", - "uuid", -] - -[[package]] -name = "sea-query-derive" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a82fcb49253abcb45cdcb2adf92956060ec0928635eb21b4f7a6d8f25ab0bc" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.38", - "thiserror", -] - -[[package]] -name = "sea-schema" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd9561232bd1b82ea748b581f15909d11de0db6563ddcf28c5d908aee8282f1" -dependencies = [ - "futures", - "sea-query", - "sea-schema-derive", -] - -[[package]] -name = "sea-schema-derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f686050f76bffc4f635cda8aea6df5548666b830b52387e8bc7de11056d11e" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "seahash" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" - [[package]] name = "semver" version = "1.0.20" @@ -3137,15 +2136,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "shlex" version = "1.2.0" @@ -3187,16 +2177,6 @@ name = "signature" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "simdutf8" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" [[package]] name = "simple_logger" @@ -3210,6 +2190,12 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.9" @@ -3245,20 +2231,11 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] [[package]] name = "spki" @@ -3270,240 +2247,6 @@ dependencies = [ "der", ] -[[package]] -name = "sqlformat" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" -dependencies = [ - "itertools", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e50c216e3624ec8e7ecd14c6a6a6370aad6ee5d8cfc3ab30b5162eeeef2ed33" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d6753e460c998bbd4cd8c6f0ed9a64346fcca0723d6e75e52fdc351c5d2169d" -dependencies = [ - "ahash 0.8.6", - "atoi", - "bigdecimal", - "byteorder", - "bytes", - "chrono", - "crc", - "crossbeam-queue", - "dotenvy", - "either", - "event-listener", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashlink", - "hex", - "indexmap 2.0.2", - "log", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "rust_decimal", - "rustls", - "rustls-pemfile", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlformat", - "thiserror", - "time", - "tokio", - "tokio-stream", - "tracing", - "url", - "uuid", - "webpki-roots 0.24.0", -] - -[[package]] -name = "sqlx-macros" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a793bb3ba331ec8359c1853bd39eed32cdd7baaf22c35ccf5c92a7e8d1189ec" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn 1.0.109", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4ee1e104e00dedb6aa5ffdd1343107b0a4702e862a84320ee7cc74782d96fc" -dependencies = [ - "dotenvy", - "either", - "heck", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", - "syn 1.0.109", - "tempfile", - "tokio", - "url", -] - -[[package]] -name = "sqlx-mysql" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db" -dependencies = [ - "atoi", - "base64 0.21.5", - "bigdecimal", - "bitflags 2.4.1", - "byteorder", - "bytes", - "chrono", - "crc", - "digest", - "dotenvy", - "either", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "generic-array", - "hex", - "hkdf", - "hmac", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "percent-encoding", - "rand", - "rsa", - "rust_decimal", - "serde", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "time", - "tracing", - "uuid", - "whoami", -] - -[[package]] -name = "sqlx-postgres" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624" -dependencies = [ - "atoi", - "base64 0.21.5", - "bigdecimal", - "bitflags 2.4.1", - "byteorder", - "chrono", - "crc", - "dotenvy", - "etcetera", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "hex", - "hkdf", - "hmac", - "home", - "itoa", - "log", - "md-5", - "memchr", - "num-bigint", - "once_cell", - "rand", - "rust_decimal", - "serde", - "serde_json", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "time", - "tracing", - "uuid", - "whoami", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59dc83cf45d89c555a577694534fcd1b55c545a816c816ce51f20bbe56a4f3f" -dependencies = [ - "atoi", - "chrono", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "sqlx-core", - "time", - "tracing", - "url", - "uuid", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "stringprep" version = "0.1.4" @@ -3521,12 +2264,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" - [[package]] name = "subtle" version = "2.5.0" @@ -3577,22 +2314,12 @@ dependencies = [ ] [[package]] -name = "tap" -version = "1.0.1" +name = "termcolor" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "tempfile" -version = "3.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" dependencies = [ - "cfg-if", - "fastrand 2.0.1", - "redox_syscall 0.3.5", - "rustix 0.38.21", - "windows-sys 0.48.0", + "winapi-util", ] [[package]] @@ -3632,7 +2359,7 @@ dependencies = [ "sha2", "simple_logger", "toml 0.8.5", - "trifid-pki 0.1.11", + "trifid-pki", "url", ] @@ -3656,16 +2383,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "time" version = "0.3.30" @@ -3742,6 +2459,32 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "tokio-postgres" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d340244b32d920260ae7448cb72b6e238bddc3d4f7603394e7dd46ed8e48f5b8" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand", + "socket2 0.5.5", + "tokio", + "tokio-util", + "whoami", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -3752,17 +2495,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-stream" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.10" @@ -3779,11 +2511,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", ] [[package]] @@ -3795,7 +2530,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.20.5", ] [[package]] @@ -3807,6 +2542,19 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.0.2", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "toml_edit" version = "0.20.5" @@ -3820,22 +2568,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "totp-rs" -version = "5.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3504f96adf86d28e7eb16fa236a7951ec72c15ee100d1b5318e225944bc8cb" -dependencies = [ - "base32", - "constant_time_eq", - "hmac", - "rand", - "sha1", - "sha2", - "url", - "urlencoding", -] - [[package]] name = "tower-service" version = "0.3.2" @@ -3850,21 +2582,9 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "tracing-core" version = "0.1.32" @@ -3874,49 +2594,21 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tracing-subscriber" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" -dependencies = [ - "matchers", - "once_cell", - "regex", - "sharded-slab", - "thread_local", - "tracing", - "tracing-core", -] - [[package]] name = "trifid-api" -version = "0.2.3" +version = "0.3.0" dependencies = [ "actix-cors", - "actix-request-identifier", "actix-web", - "aes-gcm", - "base64 0.21.5", - "chrono", - "derivative", - "dnapi-rs", - "ed25519-dalek", - "hex", - "ipnet", + "bb8", + "diesel", + "diesel-async", + "diesel_migrations", + "env_logger", "log", - "once_cell", - "rand", - "sea-orm", "serde", "serde_json", - "serde_yaml", - "simple_logger", "toml 0.8.5", - "totp-rs", - "trifid-pki 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "trifid_api_entities", - "trifid_api_migration", ] [[package]] @@ -3935,40 +2627,6 @@ dependencies = [ "x25519-dalek", ] -[[package]] -name = "trifid-pki" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1f77edb049803362a6ca6b7a6694d94ef35da79244ee6379d9afe2451744545" -dependencies = [ - "ed25519-dalek", - "hex", - "ipnet", - "pem", - "quick-protobuf", - "rand", - "rand_core", - "serde", - "sha2", - "x25519-dalek", -] - -[[package]] -name = "trifid_api_entities" -version = "0.2.0" -dependencies = [ - "sea-orm", -] - -[[package]] -name = "trifid_api_migration" -version = "0.2.0" -dependencies = [ - "async-std", - "async-trait", - "sea-orm-migration", -] - [[package]] name = "try-lock" version = "0.2.4" @@ -4002,28 +2660,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - -[[package]] -name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" -dependencies = [ - "crypto-common", - "subtle", -] - [[package]] name = "unsafe-libyaml" version = "0.2.9" @@ -4047,52 +2683,18 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "uuid" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "value-bag" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72e1902dde2bd6441347de2b70b7f5d59bf157c6c62f0c44572607a1d55bbe" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" - [[package]] name = "want" version = "0.3.1" @@ -4184,15 +2786,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b291546d5d9d1eab74f069c77749f2cb8504a12caa20f0f2de93ddbf6f411888" -dependencies = [ - "rustls-webpki", -] - [[package]] name = "webpki-roots" version = "0.25.2" @@ -4208,7 +2801,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.21", + "rustix", ] [[package]] @@ -4216,6 +2809,10 @@ name = "whoami" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +dependencies = [ + "wasm-bindgen", + "web-sys", +] [[package]] name = "winapi" @@ -4233,6 +2830,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4390,15 +2996,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "x25519-dalek" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index f15d30e..a968496 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,10 @@ [workspace] members = [ - "trifid-api", - "trifid-api/trifid_api_migration", - "trifid-api/trifid_api_entities", "tfclient", "trifid-pki", "dnapi-rs", "tfcli", - "nebula-ffi" + "nebula-ffi", + "trifid-api" ] resolver = "2" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8a4b58f..2e54d88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM rust:latest COPY trifid-pki /trifid-pki COPY dnapi-rs /dnapi-rs -COPY trifid-api /trifid-api +COPY trifid-api-old /trifid-api -RUN cd /trifid-api && cargo build --release && cp target/release/trifid-api /bin/trifid-api +RUN cd /trifid-api-old && cargo build --release && cp target/release/trifid-api-old /bin/trifid-api-old CMD ["/bin/trifid-api"] diff --git a/database_structure b/database_structure new file mode 100644 index 0000000..f964897 --- /dev/null +++ b/database_structure @@ -0,0 +1,2 @@ +Users +\- \ No newline at end of file diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 9cbb918..7a30a64 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -82,8 +82,8 @@ const config = { to: '/docs/intro', }, { - label: 'trifid-api', - to: '/docs/trifid-api/intro', + label: 'trifid-api-old', + to: '/docs/trifid-api-old/intro', }, { label: 'tfweb', diff --git a/tfcli/src/main.rs b/tfcli/src/main.rs index adb6529..a4eba80 100644 --- a/tfcli/src/main.rs +++ b/tfcli/src/main.rs @@ -24,7 +24,7 @@ pub struct Args { #[command(subcommand)] command: Commands, #[clap(short, long, env = "TFCLI_SERVER")] - /// The base URL of your trifid-api instance. Defaults to the value in $XDG_CONFIG_HOME/tfcli-server-url.conf or the TFCLI_SERVER environment variable. + /// The base URL of your trifid-api-old instance. Defaults to the value in $XDG_CONFIG_HOME/tfcli-server-url.conf or the TFCLI_SERVER environment variable. server: Option } @@ -69,7 +69,7 @@ pub enum AccountCommands { #[clap(short, long)] email: String }, - /// Log in to your account with a magic-link token acquired via email or the trifid-api logs. + /// Log in to your account with a magic-link token acquired via email or the trifid-api-old logs. MagicLink { #[clap(short, long)] magic_link_token: String @@ -103,7 +103,7 @@ pub enum NetworkCommands { #[derive(Subcommand, Debug)] pub enum OrgCommands { - /// Create an organization on your trifid-api server. NOTE: This command ONLY works on trifid-api servers. It will NOT work on original DN servers. + /// Create an organization on your trifid-api-old server. NOTE: This command ONLY works on trifid-api-old servers. It will NOT work on original DN servers. Create { #[clap(short, long)] cidr: Ipv4Net @@ -179,7 +179,7 @@ pub enum HostCommands { #[clap(short, long)] id: String }, - /// Update a specific host by it's ID, changing the listen port and static addresses, as well as the name, ip and role. The name, ip and role updates will only work on trifid-api compatible servers. + /// Update a specific host by it's ID, changing the listen port and static addresses, as well as the name, ip and role. The name, ip and role updates will only work on trifid-api-old compatible servers. Update { #[clap(short, long)] id: String, diff --git a/tfclient/src/main.rs b/tfclient/src/main.rs index ba79d2e..f009358 100644 --- a/tfclient/src/main.rs +++ b/tfclient/src/main.rs @@ -55,7 +55,7 @@ enum Commands { server: String, }, - /// Enroll this host using a trifid-api enrollment code + /// Enroll this host using a trifid-api-old enrollment code Enroll { #[clap(short, long, default_value = "tfclient")] /// Service name specified on install diff --git a/trifid-api/.env b/trifid-api-old/.env similarity index 100% rename from trifid-api/.env rename to trifid-api-old/.env diff --git a/trifid-api-old/build.rs b/trifid-api-old/build.rs new file mode 100644 index 0000000..b8a52dd --- /dev/null +++ b/trifid-api-old/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rerun-if-changed=migrations/"); +} diff --git a/trifid-api/config.example.toml b/trifid-api-old/config.example.toml similarity index 91% rename from trifid-api/config.example.toml rename to trifid-api-old/config.example.toml index c892cde..d26bd8b 100644 --- a/trifid-api/config.example.toml +++ b/trifid-api-old/config.example.toml @@ -1,7 +1,7 @@ ########################## -# trifid-api config file # +# trifid-api-old config file # ########################## -# trifid-api, an open source reimplementation of the Defined Networking nebula management server. +# trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. # Copyright (C) 2023 c0repwn3r # # This program is free software: you can redistribute it and/or modify @@ -18,7 +18,7 @@ # along with this program. If not, see . # Please read this file in it's entirety to learn what options you do or don't need to change -# to get a functional trifid-api instance. +# to get a functional trifid-api-old instance. #### [database] #### # Options related to the PostgreSQL database connection. @@ -30,7 +30,7 @@ url = "your-database-url-here" # The maximum number of connections that will be established to the database. -# This will effectively mean the amount of requests that trifid-api can process in parallel, as almost every +# This will effectively mean the amount of requests that trifid-api-old can process in parallel, as almost every # request handler acquires a connection from the pool. # Integer. Optional. Default: 100 # max_connections = 100 @@ -42,13 +42,13 @@ url = "your-database-url-here" # min_connections = 5 # The maximum amount of time (in seconds) that the database pool will wait in order to connect to the database. -# After this amount of time, the connection will return an error and trifid-api will exit. If you have a very high-latency +# After this amount of time, the connection will return an error and trifid-api-old will exit. If you have a very high-latency # database connection, raise this number. # Integer. Optional. Default = 8 # connect_timeout = 8 # The maximum amount of time (in seconds) that the database pool will wait in order to acquire a connection from the database pool. -# After this amount of time, the connection will return an error and trifid-api will exit. If you have a very high-latency +# After this amount of time, the connection will return an error and trifid-api-old will exit. If you have a very high-latency # database connection, raise this number. # Integer. Optional. Default = 8 # acquire_timeout = 8 @@ -71,9 +71,9 @@ url = "your-database-url-here" # sqlx_logging = true #### [server] #### -# Configure options for the trifid-api HTTP server. +# Configure options for the trifid-api-old HTTP server. [server] -# What IPs and ports should the trifid-api server listen on? +# What IPs and ports should the trifid-api-old server listen on? # This may need to be changed if you want to bind on a different port or interface. # SocketAddr. Optional. Default = 0.0.0.0:8080 (all IPs, port 8080) # bind = "0.0.0.0:8080" @@ -84,7 +84,7 @@ url = "your-database-url-here" # workers = 32 #### [tokens] #### -# Configure options related to the various tokens that may be issued by the trifid-api server. +# Configure options related to the various tokens that may be issued by the trifid-api-old server. [tokens] # How long (in seconds) should magic link tokens be valid for? # This controls how long links sent to user's email addresses will remain valid for login. @@ -113,7 +113,7 @@ url = "your-database-url-here" # mfa_tokens_expiry_time_seconds = 600 # 10 minutes #### [crypto] #### -# Configure settings related to the cryptography used inside trifid-api +# Configure settings related to the cryptography used inside trifid-api-old [crypto] # The per-instance data encryption key to protect sensitive data in the instance. diff --git a/trifid-api/src/auth_tokens.rs b/trifid-api-old/src/auth_tokens.rs similarity index 98% rename from trifid-api/src/auth_tokens.rs rename to trifid-api-old/src/auth_tokens.rs index abfe8cb..b2e310b 100644 --- a/trifid-api/src/auth_tokens.rs +++ b/trifid-api-old/src/auth_tokens.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/codegen/mod.rs b/trifid-api-old/src/codegen/mod.rs similarity index 100% rename from trifid-api/src/codegen/mod.rs rename to trifid-api-old/src/codegen/mod.rs diff --git a/trifid-api-old/src/config.rs b/trifid-api-old/src/config.rs new file mode 100644 index 0000000..ce217d8 --- /dev/null +++ b/trifid-api-old/src/config.rs @@ -0,0 +1,736 @@ +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. +// Copyright (C) 2023 c0repwn3r +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use ipnet::{IpNet, Ipv4Net}; +use log::error; +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::error::Error; +use std::fs; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use std::path::PathBuf; +use std::time::SystemTime; + +use trifid_pki::cert::deserialize_nebula_certificate_from_pem; + +pub static CONFIG: Lazy = Lazy::new(|| { + let config_str = match fs::read_to_string("/etc/trifid/config.toml") { + Ok(str) => str, + Err(e) => { + error!("Unable to read config file: {}", e); + std::process::exit(1); + } + }; + + match toml::from_str(&config_str) { + Ok(cfg) => cfg, + Err(e) => { + error!("Unable to parse config file: {}", e); + std::process::exit(1); + } + } +}); + +#[derive(Serialize, Debug, Deserialize)] +pub struct TrifidConfig { + pub database: TrifidConfigDatabase, + pub server: TrifidConfigServer, + pub tokens: TrifidConfigTokens, + pub crypto: TrifidConfigCryptography, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TrifidConfigDatabase { + pub url: String, + #[serde(default = "max_connections_default")] + pub max_connections: u32, + #[serde(default = "min_connections_default")] + pub min_connections: u32, + #[serde(default = "time_defaults")] + pub connect_timeout: u64, + #[serde(default = "time_defaults")] + pub acquire_timeout: u64, + #[serde(default = "time_defaults")] + pub idle_timeout: u64, + #[serde(default = "time_defaults")] + pub max_lifetime: u64, + #[serde(default = "sqlx_logging_default")] + pub sqlx_logging: bool, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TrifidConfigServer { + #[serde(default = "socketaddr_8080")] + pub bind: SocketAddr, + #[serde(default = "default_workers")] + pub workers: usize +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TrifidConfigTokens { + #[serde(default = "magic_link_expiry_time")] + pub magic_link_expiry_time_seconds: u64, + #[serde(default = "session_token_expiry_time")] + pub session_token_expiry_time_seconds: u64, + #[serde(default = "totp_setup_timeout_time")] + pub totp_setup_timeout_time_seconds: u64, + #[serde(default = "mfa_tokens_expiry_time")] + pub mfa_tokens_expiry_time_seconds: u64, + #[serde(default = "enrollment_tokens_expiry_time")] + pub enrollment_tokens_expiry_time: u64, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TrifidConfigCryptography { + pub data_encryption_key: String, + pub local_keystore_directory: PathBuf, + #[serde(default = "certs_expiry_time")] + pub certs_expiry_time: u64, +} + +fn max_connections_default() -> u32 { + 100 +} +fn min_connections_default() -> u32 { + 5 +} +fn time_defaults() -> u64 { + 8 +} +fn sqlx_logging_default() -> bool { + true +} +fn socketaddr_8080() -> SocketAddr { + SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::from([0, 0, 0, 0]), 8080)) +} +fn magic_link_expiry_time() -> u64 { + 3600 +} // 1 hour +fn session_token_expiry_time() -> u64 { + 15780000 +} // 6 months +fn totp_setup_timeout_time() -> u64 { + 600 +} // 10 minutes +fn mfa_tokens_expiry_time() -> u64 { + 600 +} // 10 minutes +fn enrollment_tokens_expiry_time() -> u64 { + 600 +} // 10 minutes +fn certs_expiry_time() -> u64 { + 3600 * 24 * 31 * 12 // 1 year +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfig { + pub pki: NebulaConfigPki, + #[serde(default = "empty_hashmap")] + #[serde(skip_serializing_if = "is_empty_hashmap")] + pub static_host_map: HashMap>, + #[serde(skip_serializing_if = "is_none")] + pub lighthouse: Option, + #[serde(skip_serializing_if = "is_none")] + pub listen: Option, + #[serde(skip_serializing_if = "is_none")] + pub punchy: Option, + #[serde(default = "cipher_aes")] + #[serde(skip_serializing_if = "is_cipher_aes")] + pub cipher: NebulaConfigCipher, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub preferred_ranges: Vec, + #[serde(skip_serializing_if = "is_none")] + pub relay: Option, + #[serde(skip_serializing_if = "is_none")] + pub tun: Option, + #[serde(skip_serializing_if = "is_none")] + pub logging: Option, + #[serde(skip_serializing_if = "is_none")] + pub sshd: Option, + + #[serde(skip_serializing_if = "is_none")] + pub firewall: Option, + + #[serde(default = "u64_1")] + #[serde(skip_serializing_if = "is_u64_1")] + pub routines: u64, + + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub stats: Option, + + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub local_range: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct NebulaConfigPki { + pub ca: String, + pub cert: String, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub key: Option, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub blocklist: Vec, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub disconnect_invalid: bool, +} + +impl PartialEq for NebulaConfigPki { + fn eq(&self, other: &Self) -> bool { + if self.ca != other.ca { + return false; + } + if self.key != other.key { + return false; + } + if self.blocklist != other.blocklist { + return false; + } + if self.disconnect_invalid != other.disconnect_invalid { + return false; + } + + // cert logic + // if the cert is invalid, fallback to just checking equality + match is_cert_equal_ignoring_expiry(&self.cert, &other.cert) { + Ok(res) => res, + Err(_) => self.cert == other.cert, + } + } +} + +fn is_cert_equal_ignoring_expiry(me: &str, other: &str) -> Result> { + // determines if the certificates are equal, ignoring not_before, not_after and the signature + // exception: if either certificate is expired, not_before and not_after will be checked anyway + + // parse cert A + let cert_a = deserialize_nebula_certificate_from_pem(me.as_bytes())?; + let cert_b = deserialize_nebula_certificate_from_pem(other.as_bytes())?; + + if cert_a.details.is_ca != cert_b.details.is_ca { + return Ok(false); + } + if cert_a.details.name != cert_b.details.name { + return Ok(false); + } + if cert_a.details.public_key != cert_b.details.public_key { + return Ok(false); + } + if cert_a.details.groups != cert_b.details.groups { + return Ok(false); + } + if cert_a.details.ips != cert_b.details.ips { + return Ok(false); + } + if cert_a.details.issuer != cert_b.details.issuer { + return Ok(false); + } + if cert_a.details.subnets != cert_b.details.subnets { + return Ok(false); + } + + if cert_a.expired(SystemTime::now()) || cert_b.expired(SystemTime::now()) { + if cert_a.details.not_before != cert_b.details.not_before { + return Ok(false); + } + if cert_a.details.not_after != cert_b.details.not_after { + return Ok(false); + } + if cert_a.signature != cert_b.signature { + return Ok(false); + } + } + + Ok(true) +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigLighthouse { + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub am_lighthouse: bool, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub serve_dns: bool, + #[serde(skip_serializing_if = "is_none")] + pub dns: Option, + #[serde(default = "u32_10")] + #[serde(skip_serializing_if = "is_u32_10")] + pub interval: u32, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub hosts: Vec, + #[serde(default = "empty_hashmap")] + #[serde(skip_serializing_if = "is_empty_hashmap")] + pub remote_allow_list: HashMap, + #[serde(default = "empty_hashmap")] + #[serde(skip_serializing_if = "is_empty_hashmap")] + pub local_allow_list: HashMap, // `interfaces` is not supported +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigLighthouseDns { + #[serde(default = "string_empty")] + #[serde(skip_serializing_if = "is_string_empty")] + pub host: String, + #[serde(default = "u16_53")] + #[serde(skip_serializing_if = "is_u16_53")] + pub port: u16, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigListen { + #[serde(default = "string_empty")] + #[serde(skip_serializing_if = "is_string_empty")] + pub host: String, + #[serde(default = "u16_0")] + #[serde(skip_serializing_if = "is_u16_0")] + pub port: u16, + #[serde(default = "u32_64")] + #[serde(skip_serializing_if = "is_u32_64")] + pub batch: u32, + #[serde(skip_serializing_if = "is_none")] + pub read_buffer: Option, + #[serde(skip_serializing_if = "is_none")] + pub write_buffer: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigPunchy { + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub punch: bool, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub respond: bool, + #[serde(default = "string_1s")] + #[serde(skip_serializing_if = "is_string_1s")] + pub delay: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub enum NebulaConfigCipher { + #[serde(rename = "aes")] + Aes, + #[serde(rename = "chachapoly")] + ChaChaPoly, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigRelay { + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub relays: Vec, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub am_relay: bool, + #[serde(default = "bool_true")] + #[serde(skip_serializing_if = "is_bool_true")] + pub use_relays: bool, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigTun { + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub disabled: bool, + #[serde(skip_serializing_if = "is_none")] + pub dev: Option, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub drop_local_broadcast: bool, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub drop_multicast: bool, + #[serde(default = "u64_500")] + #[serde(skip_serializing_if = "is_u64_500")] + pub tx_queue: u64, + #[serde(default = "u64_1300")] + #[serde(skip_serializing_if = "is_u64_1300")] + pub mtu: u64, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub routes: Vec, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub unsafe_routes: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigTunRouteOverride { + pub mtu: u64, + pub route: Ipv4Net, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigTunUnsafeRoute { + pub route: Ipv4Net, + pub via: Ipv4Addr, + #[serde(default = "u64_1300")] + #[serde(skip_serializing_if = "is_u64_1300")] + pub mtu: u64, + #[serde(default = "i64_100")] + #[serde(skip_serializing_if = "is_i64_100")] + pub metric: i64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigLogging { + #[serde(default = "loglevel_info")] + #[serde(skip_serializing_if = "is_loglevel_info")] + pub level: NebulaConfigLoggingLevel, + #[serde(default = "format_text")] + #[serde(skip_serializing_if = "is_format_text")] + pub format: NebulaConfigLoggingFormat, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub disable_timestamp: bool, + #[serde(default = "timestamp")] + #[serde(skip_serializing_if = "is_timestamp")] + pub timestamp_format: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub enum NebulaConfigLoggingLevel { + #[serde(rename = "panic")] + Panic, + #[serde(rename = "fatal")] + Fatal, + #[serde(rename = "error")] + Error, + #[serde(rename = "warning")] + Warning, + #[serde(rename = "info")] + Info, + #[serde(rename = "debug")] + Debug, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub enum NebulaConfigLoggingFormat { + #[serde(rename = "json")] + Json, + #[serde(rename = "text")] + Text, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigSshd { + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub enabled: bool, + pub listen: SocketAddrV4, + pub host_key: String, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub authorized_users: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigSshdAuthorizedUser { + pub user: String, + #[serde(default = "empty_vec")] + #[serde(skip_serializing_if = "is_empty_vec")] + pub keys: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(tag = "type")] +pub enum NebulaConfigStats { + #[serde(rename = "graphite")] + Graphite(NebulaConfigStatsGraphite), + #[serde(rename = "prometheus")] + Prometheus(NebulaConfigStatsPrometheus), +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigStatsGraphite { + #[serde(default = "string_nebula")] + #[serde(skip_serializing_if = "is_string_nebula")] + pub prefix: String, + #[serde(default = "protocol_tcp")] + #[serde(skip_serializing_if = "is_protocol_tcp")] + pub protocol: NebulaConfigStatsGraphiteProtocol, + pub host: SocketAddrV4, + pub interval: String, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub message_metrics: bool, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub lighthouse_metrics: bool, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub enum NebulaConfigStatsGraphiteProtocol { + #[serde(rename = "tcp")] + Tcp, + #[serde(rename = "udp")] + Udp, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigStatsPrometheus { + pub listen: String, + pub path: String, + #[serde(default = "string_nebula")] + #[serde(skip_serializing_if = "is_string_nebula")] + pub namespace: String, + #[serde(default = "string_nebula")] + #[serde(skip_serializing_if = "is_string_nebula")] + pub subsystem: String, + pub interval: String, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub message_metrics: bool, + #[serde(default = "bool_false")] + #[serde(skip_serializing_if = "is_bool_false")] + pub lighthouse_metrics: bool, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigFirewall { + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub conntrack: Option, + + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub inbound: Option>, + + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub outbound: Option>, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigFirewallConntrack { + #[serde(default = "string_12m")] + #[serde(skip_serializing_if = "is_string_12m")] + pub tcp_timeout: String, + #[serde(default = "string_3m")] + #[serde(skip_serializing_if = "is_string_3m")] + pub udp_timeout: String, + #[serde(default = "string_10m")] + #[serde(skip_serializing_if = "is_string_10m")] + pub default_timeout: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct NebulaConfigFirewallRule { + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub port: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub proto: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub ca_name: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub ca_sha: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub host: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub group: Option, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub groups: Option>, + #[serde(default = "none")] + #[serde(skip_serializing_if = "is_none")] + pub cidr: Option, +} + +// Default values for serde + +fn string_12m() -> String { + "12m".to_string() +} +fn is_string_12m(s: &str) -> bool { + s == "12m" +} + +fn string_3m() -> String { + "3m".to_string() +} +fn is_string_3m(s: &str) -> bool { + s == "3m" +} + +fn string_10m() -> String { + "10m".to_string() +} +fn is_string_10m(s: &str) -> bool { + s == "10m" +} + +fn empty_vec() -> Vec { + vec![] +} +fn is_empty_vec(v: &Vec) -> bool { + v.is_empty() +} + +fn empty_hashmap() -> HashMap { + HashMap::new() +} +fn is_empty_hashmap(h: &HashMap) -> bool { + h.is_empty() +} + +fn bool_false() -> bool { + false +} +fn is_bool_false(b: &bool) -> bool { + !*b +} + +fn bool_true() -> bool { + true +} +fn is_bool_true(b: &bool) -> bool { + *b +} + +fn u16_53() -> u16 { + 53 +} +fn is_u16_53(u: &u16) -> bool { + *u == 53 +} + +fn u32_10() -> u32 { + 10 +} +fn is_u32_10(u: &u32) -> bool { + *u == 10 +} + +fn u16_0() -> u16 { + 0 +} +fn is_u16_0(u: &u16) -> bool { + *u == 0 +} + +fn u32_64() -> u32 { + 64 +} +fn is_u32_64(u: &u32) -> bool { + *u == 64 +} + +fn string_1s() -> String { + "1s".to_string() +} +fn is_string_1s(s: &str) -> bool { + s == "1s" +} + +fn cipher_aes() -> NebulaConfigCipher { + NebulaConfigCipher::Aes +} +fn is_cipher_aes(c: &NebulaConfigCipher) -> bool { + matches!(c, NebulaConfigCipher::Aes) +} + +fn u64_500() -> u64 { + 500 +} +fn is_u64_500(u: &u64) -> bool { + *u == 500 +} + +fn u64_1300() -> u64 { + 1300 +} +fn is_u64_1300(u: &u64) -> bool { + *u == 1300 +} + +fn i64_100() -> i64 { + 100 +} +fn is_i64_100(i: &i64) -> bool { + *i == 100 +} + +fn loglevel_info() -> NebulaConfigLoggingLevel { + NebulaConfigLoggingLevel::Info +} +fn is_loglevel_info(l: &NebulaConfigLoggingLevel) -> bool { + matches!(l, NebulaConfigLoggingLevel::Info) +} + +fn format_text() -> NebulaConfigLoggingFormat { + NebulaConfigLoggingFormat::Text +} +fn is_format_text(f: &NebulaConfigLoggingFormat) -> bool { + matches!(f, NebulaConfigLoggingFormat::Text) +} + +fn timestamp() -> String { + "2006-01-02T15:04:05Z07:00".to_string() +} +fn is_timestamp(s: &str) -> bool { + s == "2006-01-02T15:04:05Z07:00" +} + +fn u64_1() -> u64 { + 1 +} +fn is_u64_1(u: &u64) -> bool { + *u == 1 +} + +fn string_nebula() -> String { + "nebula".to_string() +} +fn is_string_nebula(s: &str) -> bool { + s == "nebula" +} + +fn string_empty() -> String { + String::new() +} +fn is_string_empty(s: &str) -> bool { + s.is_empty() +} + +fn protocol_tcp() -> NebulaConfigStatsGraphiteProtocol { + NebulaConfigStatsGraphiteProtocol::Tcp +} +fn is_protocol_tcp(p: &NebulaConfigStatsGraphiteProtocol) -> bool { + matches!(p, NebulaConfigStatsGraphiteProtocol::Tcp) +} + +fn none() -> Option { + None +} +fn is_none(o: &Option) -> bool { + o.is_none() +} + +fn default_workers() -> usize { 32 } \ No newline at end of file diff --git a/trifid-api/src/crypto.rs b/trifid-api-old/src/crypto.rs similarity index 94% rename from trifid-api/src/crypto.rs rename to trifid-api-old/src/crypto.rs index 4add179..9073112 100644 --- a/trifid-api/src/crypto.rs +++ b/trifid-api-old/src/crypto.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/cursor.rs b/trifid-api-old/src/cursor.rs similarity index 94% rename from trifid-api/src/cursor.rs rename to trifid-api-old/src/cursor.rs index 14a486f..4f3a16f 100644 --- a/trifid-api/src/cursor.rs +++ b/trifid-api-old/src/cursor.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api-old/src/error.rs b/trifid-api-old/src/error.rs new file mode 100644 index 0000000..2775b01 --- /dev/null +++ b/trifid-api-old/src/error.rs @@ -0,0 +1,132 @@ +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. +// Copyright (C) 2023 c0repwn3r +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use actix_web::error::{JsonPayloadError, PayloadError}; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct APIErrorsResponse { + pub errors: Vec, +} +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct APIError { + pub code: String, + pub message: String, + #[serde(skip_serializing_if = "is_none")] + #[serde(default)] + pub path: Option, +} + +fn is_none(o: &Option) -> bool { + o.is_none() +} + +impl From<&JsonPayloadError> for APIError { + fn from(value: &JsonPayloadError) -> Self { + match value { + JsonPayloadError::OverflowKnownLength { length, limit } => { + APIError { + code: "ERR_PAYLOAD_OVERFLOW_KNOWN_LENGTH".to_string(), + message: format!("Payload size is bigger than allowed & content length header set. (length: {}, limit: {})", length, limit), + path: None + } + }, + JsonPayloadError::Overflow { limit } => { + APIError { + code: "ERR_PAYLOAD_OVERFLOW".to_string(), + message: format!("Payload size is bigger than allowed but no content-length header is set. (limit: {})", limit), + path: None + } + }, + JsonPayloadError::ContentType => { + APIError { + code: "ERR_NOT_JSON".to_string(), + message: "Content-Type header not set to expected application/json".to_string(), + path: None, + } + }, + JsonPayloadError::Deserialize(e) => { + APIError { + code: "ERR_JSON_DESERIALIZE".to_string(), + message: format!("Error deserializing JSON: {}", e), + path: None, + } + }, + JsonPayloadError::Serialize(e) => { + APIError { + code: "ERR_JSON_SERIALIZE".to_string(), + message: format!("Error serializing JSON: {}", e), + path: None, + } + }, + JsonPayloadError::Payload(e) => { + e.into() + }, + _ => { + APIError { + code: "ERR_UNKNOWN_ERROR".to_string(), + message: "An unknown error has occured".to_string(), + path: None, + } + } + } + } +} + +impl From<&PayloadError> for APIError { + fn from(value: &PayloadError) -> Self { + match value { + PayloadError::Incomplete(e) => APIError { + code: "ERR_UNEXPECTED_EOF".to_string(), + message: match e { + None => "Payload reached EOF but was incomplete".to_string(), + Some(e) => format!("Payload reached EOF but was incomplete: {}", e), + }, + path: None, + }, + PayloadError::EncodingCorrupted => APIError { + code: "ERR_CORRUPTED_PAYLOAD".to_string(), + message: "Payload content encoding corrupted".to_string(), + path: None, + }, + PayloadError::Overflow => APIError { + code: "ERR_PAYLOAD_OVERFLOW".to_string(), + message: "Payload reached size limit".to_string(), + path: None, + }, + PayloadError::UnknownLength => APIError { + code: "ERR_PAYLOAD_UNKNOWN_LENGTH".to_string(), + message: "Unable to determine payload length".to_string(), + path: None, + }, + PayloadError::Http2Payload(e) => APIError { + code: "ERR_HTTP2_ERROR".to_string(), + message: format!("HTTP/2 error: {}", e), + path: None, + }, + PayloadError::Io(e) => APIError { + code: "ERR_IO_ERROR".to_string(), + message: format!("I/O error: {}", e), + path: None, + }, + _ => APIError { + code: "ERR_UNKNOWN_ERROR".to_string(), + message: "An unknown error has occured".to_string(), + path: None, + }, + } + } +} diff --git a/trifid-api/src/legacy_keystore.rs b/trifid-api-old/src/legacy_keystore.rs similarity index 100% rename from trifid-api/src/legacy_keystore.rs rename to trifid-api-old/src/legacy_keystore.rs diff --git a/trifid-api/src/magic_link.rs b/trifid-api-old/src/magic_link.rs similarity index 89% rename from trifid-api/src/magic_link.rs rename to trifid-api-old/src/magic_link.rs index e09261a..32f1add 100644 --- a/trifid-api/src/magic_link.rs +++ b/trifid-api-old/src/magic_link.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api-old/src/response.rs b/trifid-api-old/src/response.rs new file mode 100644 index 0000000..06e797e --- /dev/null +++ b/trifid-api-old/src/response.rs @@ -0,0 +1,49 @@ +use std::fmt::{Display, Formatter}; +use actix_web::{HttpRequest, HttpResponse, Responder, ResponseError}; +use actix_web::body::EitherBody; +use actix_web::web::Json; +use log::error; +use sea_orm::DbErr; + +use crate::error::{APIError, APIErrorsResponse}; + +pub struct OkResponse(T); + +#[derive(Debug)] +pub struct ErrResponse(APIErrorsResponse); + +impl Responder for OkResponse { + type Body = T::Body; + + fn respond_to(self, req: &HttpRequest) -> HttpResponse { + self.0.respond_to(req) + } +} +impl Responder for ErrResponse { + type Body = EitherBody; + + fn respond_to(self, req: &HttpRequest) -> HttpResponse { + Json(self.0).respond_to(req) + } +} + +impl From for ErrResponse { + fn from(value: DbErr) -> Self { + error!("database error: {}", value); + Self(APIErrorsResponse { errors: vec![ + APIError { + code: "ERR_DB_ERROR".to_string(), + message: "There was an error performing the database query. Please try again later.".to_string(), + path: None, + } + ] }) + } +} + +impl Display for ErrResponse { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + +impl ResponseError for ErrResponse {} \ No newline at end of file diff --git a/trifid-api-old/src/routes/mod.rs b/trifid-api-old/src/routes/mod.rs new file mode 100644 index 0000000..ae6adc7 --- /dev/null +++ b/trifid-api-old/src/routes/mod.rs @@ -0,0 +1,2 @@ +pub mod v1; +pub mod v2; diff --git a/trifid-api/src/routes/v1/auth/magic_link.rs b/trifid-api-old/src/routes/v1/auth/magic_link.rs similarity index 97% rename from trifid-api/src/routes/v1/auth/magic_link.rs rename to trifid-api-old/src/routes/v1/auth/magic_link.rs index 0c29e5f..0916988 100644 --- a/trifid-api/src/routes/v1/auth/magic_link.rs +++ b/trifid-api-old/src/routes/v1/auth/magic_link.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/routes/v1/auth/mod.rs b/trifid-api-old/src/routes/v1/auth/mod.rs similarity index 100% rename from trifid-api/src/routes/v1/auth/mod.rs rename to trifid-api-old/src/routes/v1/auth/mod.rs diff --git a/trifid-api/src/routes/v1/auth/totp.rs b/trifid-api-old/src/routes/v1/auth/totp.rs similarity index 98% rename from trifid-api/src/routes/v1/auth/totp.rs rename to trifid-api-old/src/routes/v1/auth/totp.rs index 045734b..b1488bf 100644 --- a/trifid-api/src/routes/v1/auth/totp.rs +++ b/trifid-api-old/src/routes/v1/auth/totp.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/routes/v1/auth/verify_magic_link.rs b/trifid-api-old/src/routes/v1/auth/verify_magic_link.rs similarity index 98% rename from trifid-api/src/routes/v1/auth/verify_magic_link.rs rename to trifid-api-old/src/routes/v1/auth/verify_magic_link.rs index 884ad75..62b79c0 100644 --- a/trifid-api/src/routes/v1/auth/verify_magic_link.rs +++ b/trifid-api-old/src/routes/v1/auth/verify_magic_link.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/routes/v1/dnclient.rs b/trifid-api-old/src/routes/v1/dnclient.rs similarity index 100% rename from trifid-api/src/routes/v1/dnclient.rs rename to trifid-api-old/src/routes/v1/dnclient.rs diff --git a/trifid-api/src/routes/v1/hosts.rs b/trifid-api-old/src/routes/v1/hosts.rs similarity index 99% rename from trifid-api/src/routes/v1/hosts.rs rename to trifid-api-old/src/routes/v1/hosts.rs index 59d96b7..16c7c07 100644 --- a/trifid-api/src/routes/v1/hosts.rs +++ b/trifid-api-old/src/routes/v1/hosts.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api-old/src/routes/v1/mod.rs b/trifid-api-old/src/routes/v1/mod.rs new file mode 100644 index 0000000..7e8f5a9 --- /dev/null +++ b/trifid-api-old/src/routes/v1/mod.rs @@ -0,0 +1,10 @@ +pub mod auth; +pub mod dnclient; +pub mod hosts; +pub mod networks; +pub mod organization; +pub mod roles; +pub mod signup; +pub mod totp_authenticators; +pub mod trifid; +pub mod verify_totp_authenticators; diff --git a/trifid-api/src/routes/v1/networks.rs b/trifid-api-old/src/routes/v1/networks.rs similarity index 99% rename from trifid-api/src/routes/v1/networks.rs rename to trifid-api-old/src/routes/v1/networks.rs index c7cd6b3..a02f9fa 100644 --- a/trifid-api/src/routes/v1/networks.rs +++ b/trifid-api-old/src/routes/v1/networks.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/routes/v1/organization.rs b/trifid-api-old/src/routes/v1/organization.rs similarity index 98% rename from trifid-api/src/routes/v1/organization.rs rename to trifid-api-old/src/routes/v1/organization.rs index af60899..ac67771 100644 --- a/trifid-api/src/routes/v1/organization.rs +++ b/trifid-api-old/src/routes/v1/organization.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ // along with this program. If not, see . // //#POST /v1/organization t+parity:none t+type:fabricated t+status:done t+status:want-reveng t+feature:definednetworking -// This is NOT a DN-compatible API. The organization create API has not yet been reverse engineered. This endpoint is a complete fabrication of trifid-api. +// This is NOT a DN-compatible API. The organization create API has not yet been reverse engineered. This endpoint is a complete fabrication of trifid-api-old. // While this endpoint is considered done, help is wanted with reverse engineering the original API. Major features should not be added or removed unless it is replacing this endpoint with the correct, DN-compatible endpoint. // This endpoint requires the `definednetworking` extension to be enabled to be used. diff --git a/trifid-api/src/routes/v1/roles.rs b/trifid-api-old/src/routes/v1/roles.rs similarity index 99% rename from trifid-api/src/routes/v1/roles.rs rename to trifid-api-old/src/routes/v1/roles.rs index ecaddaa..f9da03c 100644 --- a/trifid-api/src/routes/v1/roles.rs +++ b/trifid-api-old/src/routes/v1/roles.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api-old/src/routes/v1/signup.rs b/trifid-api-old/src/routes/v1/signup.rs new file mode 100644 index 0000000..34844a6 --- /dev/null +++ b/trifid-api-old/src/routes/v1/signup.rs @@ -0,0 +1,151 @@ +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. +// Copyright (C) 2023 c0repwn3r +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +//#POST /v1/signup t+parity:full t+type:reverse_engineered t+status:done t+features:definednetworking +// This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. +// This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. + +use crate::config::CONFIG; +use crate::error::{APIError, APIErrorsResponse}; +use crate::magic_link::send_magic_link; +use crate::timers::expires_in_seconds; +use crate::tokens::{random_id, random_token}; +use crate::AppState; +use actix_web::web::{Data, Json}; +use actix_web::{post, HttpResponse}; +use log::error; +use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter}; +use serde::{Deserialize, Serialize}; +use trifid_api_entities::entity::user; +use trifid_api_entities::entity::user::Entity as UserEntity; + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct SignupRequest { + pub email: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct SignupResponse { + pub data: Option, + pub metadata: SignupResponseMetadata, +} +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct SignupResponseData {} +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct SignupResponseMetadata {} + +#[post("/v1/signup")] +pub async fn signup_request(data: Data, req: Json) -> HttpResponse { + let user: Vec = match UserEntity::find() + .filter(user::Column::Email.eq(&req.email)) + .all(&data.conn) + .await + { + Ok(r) => r, + Err(e) => { + error!("database error: {}", e); + return HttpResponse::InternalServerError().json(APIErrorsResponse { + errors: vec![APIError { + code: "ERR_DB_ERROR".to_string(), + message: + "There was an error with the database request, please try again later." + .to_string(), + path: None, + }], + }); + } + }; + + if !user.is_empty() { + return HttpResponse::Unauthorized().json(APIErrorsResponse { + errors: vec![APIError { + code: "ERR_USER_EXISTS".to_string(), + message: "That user already exists.".to_string(), + path: None, + }], + }); + } + + let model = user::Model { + id: random_id("user"), + email: req.email.clone(), + }; + let id = model.id.clone(); + + let active_model = model.into_active_model(); + + match active_model.insert(&data.conn).await { + Ok(_) => (), + Err(e) => { + error!("database error: {}", e); + return HttpResponse::InternalServerError().json(APIErrorsResponse { + errors: vec![APIError { + code: "ERR_DB_ERROR".to_string(), + message: + "There was an error with the database request, please try again later." + .to_string(), + path: None, + }], + }); + } + } + + let model = trifid_api_entities::entity::magic_link::Model { + id: random_token("ml"), + user: id, + expires_on: expires_in_seconds(CONFIG.tokens.magic_link_expiry_time_seconds) as i64, + }; + + match send_magic_link(&model.id) { + Ok(_) => (), + Err(e) => { + error!("error sending magic link: {}", e); + return HttpResponse::InternalServerError().json(APIErrorsResponse { + errors: vec![APIError { + code: "ERR_ML_ERROR".to_string(), + message: + "There was an error sending the magic link email, please try again later." + .to_string(), + path: None, + }], + }); + } + } + + let active_model = model.into_active_model(); + + match active_model.insert(&data.conn).await { + Ok(_) => (), + Err(e) => { + error!("database error: {}", e); + return HttpResponse::InternalServerError().json(APIErrorsResponse { + errors: vec![APIError { + code: "ERR_DB_ERROR".to_string(), + message: + "There was an error with the database request, please try again later." + .to_string(), + path: None, + }], + }); + } + } + + HttpResponse::Ok().json(SignupResponse { + data: None, + metadata: SignupResponseMetadata {}, + }) +} diff --git a/trifid-api/src/routes/v1/totp_authenticators.rs b/trifid-api-old/src/routes/v1/totp_authenticators.rs similarity index 97% rename from trifid-api/src/routes/v1/totp_authenticators.rs rename to trifid-api-old/src/routes/v1/totp_authenticators.rs index e80b3dc..c1dac55 100644 --- a/trifid-api/src/routes/v1/totp_authenticators.rs +++ b/trifid-api-old/src/routes/v1/totp_authenticators.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify @@ -133,7 +133,7 @@ pub async fn totp_authenticators_request( 1, 30, secret.to_bytes().expect("Invalid randomized data"), - Some("trifid-api".to_string()), + Some("trifid-api-old".to_string()), session_token.user.email, ) { Ok(m) => m, diff --git a/trifid-api/src/routes/v1/trifid.rs b/trifid-api-old/src/routes/v1/trifid.rs similarity index 91% rename from trifid-api/src/routes/v1/trifid.rs rename to trifid-api-old/src/routes/v1/trifid.rs index 3445887..5a22457 100644 --- a/trifid-api/src/routes/v1/trifid.rs +++ b/trifid-api-old/src/routes/v1/trifid.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ // along with this program. If not, see . // //#GET /v1/trifid_extensions t+parity:none t+type:fabricated t+status:done t+status:special t+features:trifidextensions -// This is NOT a DN-compatible API. This endpoint is a fabrication of trifid-api to enable the TrifidExtensions codebase for clients. This allows clients to access additional functionality only available on servers that support it. +// This is NOT a DN-compatible API. This endpoint is a fabrication of trifid-api-old to enable the TrifidExtensions codebase for clients. This allows clients to access additional functionality only available on servers that support it. // This endpoint is considered done. It should not be modified unless for bugfixes. // This endpoint is a special endpoint, and may impact what features client are able to access. // This endpoint requires the `trifidextensions` extension to be enabled to be used. diff --git a/trifid-api/src/routes/v1/verify_totp_authenticators.rs b/trifid-api-old/src/routes/v1/verify_totp_authenticators.rs similarity index 98% rename from trifid-api/src/routes/v1/verify_totp_authenticators.rs rename to trifid-api-old/src/routes/v1/verify_totp_authenticators.rs index 418fead..52e4608 100644 --- a/trifid-api/src/routes/v1/verify_totp_authenticators.rs +++ b/trifid-api-old/src/routes/v1/verify_totp_authenticators.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/routes/v2/enroll.rs b/trifid-api-old/src/routes/v2/enroll.rs similarity index 100% rename from trifid-api/src/routes/v2/enroll.rs rename to trifid-api-old/src/routes/v2/enroll.rs diff --git a/trifid-api/src/routes/v2/mod.rs b/trifid-api-old/src/routes/v2/mod.rs similarity index 100% rename from trifid-api/src/routes/v2/mod.rs rename to trifid-api-old/src/routes/v2/mod.rs diff --git a/trifid-api/src/routes/v2/whoami.rs b/trifid-api-old/src/routes/v2/whoami.rs similarity index 98% rename from trifid-api/src/routes/v2/whoami.rs rename to trifid-api-old/src/routes/v2/whoami.rs index 074f70e..c1f11ba 100644 --- a/trifid-api/src/routes/v2/whoami.rs +++ b/trifid-api-old/src/routes/v2/whoami.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/timers.rs b/trifid-api-old/src/timers.rs similarity index 91% rename from trifid-api/src/timers.rs rename to trifid-api-old/src/timers.rs index a4c8c1a..9ee1ee2 100644 --- a/trifid-api/src/timers.rs +++ b/trifid-api-old/src/timers.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/src/tokens.rs b/trifid-api-old/src/tokens.rs similarity index 94% rename from trifid-api/src/tokens.rs rename to trifid-api-old/src/tokens.rs index cb276f1..8b20533 100644 --- a/trifid-api/src/tokens.rs +++ b/trifid-api-old/src/tokens.rs @@ -1,4 +1,4 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// trifid-api-old, an open source reimplementation of the Defined Networking nebula management server. // Copyright (C) 2023 c0repwn3r // // This program is free software: you can redistribute it and/or modify diff --git a/trifid-api/trifid_api_entities/Cargo.toml b/trifid-api-old/trifid_api_entities/Cargo.toml similarity index 100% rename from trifid-api/trifid_api_entities/Cargo.toml rename to trifid-api-old/trifid_api_entities/Cargo.toml diff --git a/trifid-api/trifid_api_entities/src/entity/api_key.rs b/trifid-api-old/trifid_api_entities/src/entity/api_key.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/api_key.rs rename to trifid-api-old/trifid_api_entities/src/entity/api_key.rs diff --git a/trifid-api/trifid_api_entities/src/entity/api_key_scope.rs b/trifid-api-old/trifid_api_entities/src/entity/api_key_scope.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/api_key_scope.rs rename to trifid-api-old/trifid_api_entities/src/entity/api_key_scope.rs diff --git a/trifid-api/trifid_api_entities/src/entity/auth_token.rs b/trifid-api-old/trifid_api_entities/src/entity/auth_token.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/auth_token.rs rename to trifid-api-old/trifid_api_entities/src/entity/auth_token.rs diff --git a/trifid-api/trifid_api_entities/src/entity/firewall_rule.rs b/trifid-api-old/trifid_api_entities/src/entity/firewall_rule.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/firewall_rule.rs rename to trifid-api-old/trifid_api_entities/src/entity/firewall_rule.rs diff --git a/trifid-api/trifid_api_entities/src/entity/host.rs b/trifid-api-old/trifid_api_entities/src/entity/host.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/host.rs rename to trifid-api-old/trifid_api_entities/src/entity/host.rs diff --git a/trifid-api/trifid_api_entities/src/entity/host_config_override.rs b/trifid-api-old/trifid_api_entities/src/entity/host_config_override.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/host_config_override.rs rename to trifid-api-old/trifid_api_entities/src/entity/host_config_override.rs diff --git a/trifid-api/trifid_api_entities/src/entity/host_enrollment_code.rs b/trifid-api-old/trifid_api_entities/src/entity/host_enrollment_code.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/host_enrollment_code.rs rename to trifid-api-old/trifid_api_entities/src/entity/host_enrollment_code.rs diff --git a/trifid-api/trifid_api_entities/src/entity/host_static_address.rs b/trifid-api-old/trifid_api_entities/src/entity/host_static_address.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/host_static_address.rs rename to trifid-api-old/trifid_api_entities/src/entity/host_static_address.rs diff --git a/trifid-api/trifid_api_entities/src/entity/keystore_entry.rs b/trifid-api-old/trifid_api_entities/src/entity/keystore_entry.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/keystore_entry.rs rename to trifid-api-old/trifid_api_entities/src/entity/keystore_entry.rs diff --git a/trifid-api/trifid_api_entities/src/entity/keystore_host.rs b/trifid-api-old/trifid_api_entities/src/entity/keystore_host.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/keystore_host.rs rename to trifid-api-old/trifid_api_entities/src/entity/keystore_host.rs diff --git a/trifid-api/trifid_api_entities/src/entity/magic_link.rs b/trifid-api-old/trifid_api_entities/src/entity/magic_link.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/magic_link.rs rename to trifid-api-old/trifid_api_entities/src/entity/magic_link.rs diff --git a/trifid-api/trifid_api_entities/src/entity/mod.rs b/trifid-api-old/trifid_api_entities/src/entity/mod.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/mod.rs rename to trifid-api-old/trifid_api_entities/src/entity/mod.rs diff --git a/trifid-api/trifid_api_entities/src/entity/network.rs b/trifid-api-old/trifid_api_entities/src/entity/network.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/network.rs rename to trifid-api-old/trifid_api_entities/src/entity/network.rs diff --git a/trifid-api/trifid_api_entities/src/entity/organization.rs b/trifid-api-old/trifid_api_entities/src/entity/organization.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/organization.rs rename to trifid-api-old/trifid_api_entities/src/entity/organization.rs diff --git a/trifid-api/trifid_api_entities/src/entity/prelude.rs b/trifid-api-old/trifid_api_entities/src/entity/prelude.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/prelude.rs rename to trifid-api-old/trifid_api_entities/src/entity/prelude.rs diff --git a/trifid-api/trifid_api_entities/src/entity/role.rs b/trifid-api-old/trifid_api_entities/src/entity/role.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/role.rs rename to trifid-api-old/trifid_api_entities/src/entity/role.rs diff --git a/trifid-api/trifid_api_entities/src/entity/session_token.rs b/trifid-api-old/trifid_api_entities/src/entity/session_token.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/session_token.rs rename to trifid-api-old/trifid_api_entities/src/entity/session_token.rs diff --git a/trifid-api/trifid_api_entities/src/entity/signing_ca.rs b/trifid-api-old/trifid_api_entities/src/entity/signing_ca.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/signing_ca.rs rename to trifid-api-old/trifid_api_entities/src/entity/signing_ca.rs diff --git a/trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs b/trifid-api-old/trifid_api_entities/src/entity/totp_authenticator.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs rename to trifid-api-old/trifid_api_entities/src/entity/totp_authenticator.rs diff --git a/trifid-api/trifid_api_entities/src/entity/user.rs b/trifid-api-old/trifid_api_entities/src/entity/user.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/entity/user.rs rename to trifid-api-old/trifid_api_entities/src/entity/user.rs diff --git a/trifid-api/trifid_api_entities/src/lib.rs b/trifid-api-old/trifid_api_entities/src/lib.rs similarity index 100% rename from trifid-api/trifid_api_entities/src/lib.rs rename to trifid-api-old/trifid_api_entities/src/lib.rs diff --git a/trifid-api/trifid_api_migration/Cargo.toml b/trifid-api-old/trifid_api_migration/Cargo.toml similarity index 100% rename from trifid-api/trifid_api_migration/Cargo.toml rename to trifid-api-old/trifid_api_migration/Cargo.toml diff --git a/trifid-api/trifid_api_migration/README.md b/trifid-api-old/trifid_api_migration/README.md similarity index 100% rename from trifid-api/trifid_api_migration/README.md rename to trifid-api-old/trifid_api_migration/README.md diff --git a/trifid-api/trifid_api_migration/src/lib.rs b/trifid-api-old/trifid_api_migration/src/lib.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/lib.rs rename to trifid-api-old/trifid_api_migration/src/lib.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_162601_create_table_users.rs b/trifid-api-old/trifid_api_migration/src/m20230402_162601_create_table_users.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_162601_create_table_users.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_162601_create_table_users.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_183515_create_table_magic_links.rs b/trifid-api-old/trifid_api_migration/src/m20230402_183515_create_table_magic_links.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_183515_create_table_magic_links.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_183515_create_table_magic_links.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_213712_create_table_session_tokens.rs b/trifid-api-old/trifid_api_migration/src/m20230402_213712_create_table_session_tokens.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_213712_create_table_session_tokens.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_213712_create_table_session_tokens.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_232316_create_table_organizations.rs b/trifid-api-old/trifid_api_migration/src/m20230402_232316_create_table_organizations.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_232316_create_table_organizations.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_232316_create_table_organizations.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_233043_create_table_api_keys.rs b/trifid-api-old/trifid_api_migration/src/m20230402_233043_create_table_api_keys.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_233043_create_table_api_keys.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_233043_create_table_api_keys.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_233047_create_table_api_keys_scopes.rs b/trifid-api-old/trifid_api_migration/src/m20230402_233047_create_table_api_keys_scopes.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_233047_create_table_api_keys_scopes.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_233047_create_table_api_keys_scopes.rs diff --git a/trifid-api/trifid_api_migration/src/m20230402_234025_create_table_totp_authenticators.rs b/trifid-api-old/trifid_api_migration/src/m20230402_234025_create_table_totp_authenticators.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230402_234025_create_table_totp_authenticators.rs rename to trifid-api-old/trifid_api_migration/src/m20230402_234025_create_table_totp_authenticators.rs diff --git a/trifid-api/trifid_api_migration/src/m20230403_002256_create_table_auth_tokens.rs b/trifid-api-old/trifid_api_migration/src/m20230403_002256_create_table_auth_tokens.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230403_002256_create_table_auth_tokens.rs rename to trifid-api-old/trifid_api_migration/src/m20230403_002256_create_table_auth_tokens.rs diff --git a/trifid-api/trifid_api_migration/src/m20230403_142517_create_table_signing_cas.rs b/trifid-api-old/trifid_api_migration/src/m20230403_142517_create_table_signing_cas.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230403_142517_create_table_signing_cas.rs rename to trifid-api-old/trifid_api_migration/src/m20230403_142517_create_table_signing_cas.rs diff --git a/trifid-api/trifid_api_migration/src/m20230403_173431_create_table_networks.rs b/trifid-api-old/trifid_api_migration/src/m20230403_173431_create_table_networks.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230403_173431_create_table_networks.rs rename to trifid-api-old/trifid_api_migration/src/m20230403_173431_create_table_networks.rs diff --git a/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs b/trifid-api-old/trifid_api_migration/src/m20230404_133809_create_table_roles.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs rename to trifid-api-old/trifid_api_migration/src/m20230404_133809_create_table_roles.rs diff --git a/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs b/trifid-api-old/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs rename to trifid-api-old/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs diff --git a/trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs b/trifid-api-old/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs rename to trifid-api-old/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs diff --git a/trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs b/trifid-api-old/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs rename to trifid-api-old/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs diff --git a/trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs b/trifid-api-old/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs rename to trifid-api-old/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs diff --git a/trifid-api/trifid_api_migration/src/m20230511_120511_create_table_host_enrollment_codes.rs b/trifid-api-old/trifid_api_migration/src/m20230511_120511_create_table_host_enrollment_codes.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230511_120511_create_table_host_enrollment_codes.rs rename to trifid-api-old/trifid_api_migration/src/m20230511_120511_create_table_host_enrollment_codes.rs diff --git a/trifid-api/trifid_api_migration/src/m20230815_225520_create_table_keystore_hosts.rs b/trifid-api-old/trifid_api_migration/src/m20230815_225520_create_table_keystore_hosts.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230815_225520_create_table_keystore_hosts.rs rename to trifid-api-old/trifid_api_migration/src/m20230815_225520_create_table_keystore_hosts.rs diff --git a/trifid-api/trifid_api_migration/src/m20230815_230218_create_table_keystore_entries.rs b/trifid-api-old/trifid_api_migration/src/m20230815_230218_create_table_keystore_entries.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/m20230815_230218_create_table_keystore_entries.rs rename to trifid-api-old/trifid_api_migration/src/m20230815_230218_create_table_keystore_entries.rs diff --git a/trifid-api/trifid_api_migration/src/main.rs b/trifid-api-old/trifid_api_migration/src/main.rs similarity index 100% rename from trifid-api/trifid_api_migration/src/main.rs rename to trifid-api-old/trifid_api_migration/src/main.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/api_key.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/api_key.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/api_key.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/api_key.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/api_key_scope.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/api_key_scope.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/api_key_scope.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/api_key_scope.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/auth_token.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/auth_token.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/auth_token.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/auth_token.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/firewall_rule.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/firewall_rule.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/firewall_rule.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/firewall_rule.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/magic_link.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/magic_link.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/magic_link.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/magic_link.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/mod.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/mod.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/mod.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/mod.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/network.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/network.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/network.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/network.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/organization.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/organization.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/organization.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/organization.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/prelude.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/prelude.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/prelude.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/prelude.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/role.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/role.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/role.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/role.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/session_token.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/session_token.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/session_token.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/session_token.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/signing_ca.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/signing_ca.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/signing_ca.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/signing_ca.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/totp_authenticator.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/totp_authenticator.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/totp_authenticator.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/totp_authenticator.rs diff --git a/trifid-api/trifid_api_migration/trifid_api_entities/src/entity/user.rs b/trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/user.rs similarity index 100% rename from trifid-api/trifid_api_migration/trifid_api_entities/src/entity/user.rs rename to trifid-api-old/trifid_api_migration/trifid_api_entities/src/entity/user.rs diff --git a/trifid-api/trifiddata/tfks.toml b/trifid-api-old/trifiddata/tfks.toml similarity index 100% rename from trifid-api/trifiddata/tfks.toml rename to trifid-api-old/trifiddata/tfks.toml diff --git a/trifid-api/Cargo.toml b/trifid-api/Cargo.toml index eae1626..2b22573 100644 --- a/trifid-api/Cargo.toml +++ b/trifid-api/Cargo.toml @@ -1,44 +1,25 @@ [package] name = "trifid-api" -version = "0.2.3" +version = "0.3.0" +authors = ["core "] edition = "2021" -description = "Pure-rust Defined Networking compatible management server" -license = "GPL-3.0-or-later" -documentation = "https://git.e3t.cc/~core/trifid" -homepage = "https://git.e3t.cc/~core/trifid" -repository = "https://git.e3t.cc/~core/trifid" +description = "An open-source reimplementation of the Defined Networking API server" +documentation = "https://trifid.e3t.cc/docs/trifid-api/intro" +homepage = "https://trifid.e3t.cc" +repository = "https://git.e3t.cc/core/trifid" +license = "GPL-3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "4" # Web framework -actix-request-identifier = "4" # Web framework -actix-cors = "0.6.4" # Web framework - -serde = { version = "1", features = ["derive"] } # Serialization and deserialization -serde_json = "1.0.95" # Serialization and deserialization (cursors) - -once_cell = "1" # Config -toml = "0.8" # Config / Serialization and deserialization -serde_yaml = "0.9.21" # Config / Serialization and deserialization - -log = "0.4" # Logging -simple_logger = "4" # Logging - -sea-orm = { version = "0.12", features = [ "sqlx-postgres", "runtime-actix-rustls", "macros" ]} # Database -trifid_api_migration = { version = "0.2", path = "trifid_api_migration" } # Database -trifid_api_entities = { version = "0.2", path = "trifid_api_entities" } # Database - -rand = "0.8" # Misc. -hex = "0.4" # Misc. -totp-rs = { version = "5.0.1", features = ["gen_secret", "otpauth"] } # Misc. -base64 = "0.21.0" # Misc. -chrono = "0.4.24" # Misc. -derivative = "2.2.0" # Misc. - -trifid-pki = { version = "0.1", features = ["serde_derive"] } # Cryptography -aes-gcm = "0.10.1" # Cryptography -ed25519-dalek = "2.0.0-rc.2" # Cryptography - -dnapi-rs = { version = "0.2", path = "../dnapi-rs" } # API message types -ipnet = "2.7.2" # API message types +actix-web = "4" +actix-cors = "0.6" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +log = "0.4" +env_logger = "0.10" +diesel = { version = "2" } +diesel-async = { version = "0.4", features = ["postgres", "bb8", "async-connection-wrapper"] } +diesel_migrations = "2" +bb8 = "0.8" \ No newline at end of file diff --git a/trifid-api/build.rs b/trifid-api/build.rs index b8a52dd..8d90706 100644 --- a/trifid-api/build.rs +++ b/trifid-api/build.rs @@ -1,3 +1,3 @@ fn main() { - println!("cargo:rerun-if-changed=migrations/"); -} + println!("cargo:rerun-if-changed=migrations") +} \ No newline at end of file diff --git a/trifid-api/config.toml b/trifid-api/config.toml new file mode 100644 index 0000000..5a424bf --- /dev/null +++ b/trifid-api/config.toml @@ -0,0 +1,18 @@ +## trifid-api configuration file ## +# This file contains all of the buttons and knobs you can use to configure trifid to your liking. +# This file does not autoreload, you need to restart trifid-api for changes here to apply. + + +# [server] contains options for the HTTP server used to serve the API. +[server] +# (Required) What IP and port to bind the HTTP listener to. +bind = { ip = "127.0.0.1", port = 8080 } +# How many worker threads to start. The higher the number, the more resources trifid-api will use while idle, but +# the more parallel requests it can handle. +# Optional. Defaults to the number of physical CPUs in the system. +#workers = 16 + +# [database] contains options for the Postgres database used for all data storage +[database] +# (Required) The postgres database connection url to use +url = "postgres://postgres:postgres@localhost/trifid2" \ No newline at end of file diff --git a/trifid-api/diesel.toml b/trifid-api/diesel.toml index 4ae5e4b..c028f4a 100644 --- a/trifid-api/diesel.toml +++ b/trifid-api/diesel.toml @@ -1,5 +1,9 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + [print_schema] file = "src/schema.rs" +custom_type_derives = ["diesel::query_builder::QueryId"] [migrations_directory] -dir = "migrations" \ No newline at end of file +dir = "migrations" diff --git a/trifid-api/migrations/.keep b/trifid-api/migrations/.keep new file mode 100644 index 0000000..e69de29 diff --git a/trifid-api/migrations/00000000000000_diesel_initial_setup/down.sql b/trifid-api/migrations/00000000000000_diesel_initial_setup/down.sql new file mode 100644 index 0000000..a9f5260 --- /dev/null +++ b/trifid-api/migrations/00000000000000_diesel_initial_setup/down.sql @@ -0,0 +1,6 @@ +-- This file was automatically created by Diesel to setup helper functions +-- and other internal bookkeeping. This file is safe to edit, any future +-- changes will be added to existing projects as new migrations. + +DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); +DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/trifid-api/migrations/00000000000000_diesel_initial_setup/up.sql b/trifid-api/migrations/00000000000000_diesel_initial_setup/up.sql new file mode 100644 index 0000000..d68895b --- /dev/null +++ b/trifid-api/migrations/00000000000000_diesel_initial_setup/up.sql @@ -0,0 +1,36 @@ +-- This file was automatically created by Diesel to setup helper functions +-- and other internal bookkeeping. This file is safe to edit, any future +-- changes will be added to existing projects as new migrations. + + + + +-- Sets up a trigger for the given table to automatically set a column called +-- `updated_at` whenever the row is modified (unless `updated_at` was included +-- in the modified columns) +-- +-- # Example +-- +-- ```sql +-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); +-- +-- SELECT diesel_manage_updated_at('users'); +-- ``` +CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ +BEGIN + EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s + FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ +BEGIN + IF ( + NEW IS DISTINCT FROM OLD AND + NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at + ) THEN + NEW.updated_at := current_timestamp; + END IF; + RETURN NEW; +END; +$$ LANGUAGE plpgsql; diff --git a/trifid-api/migrations/2023-11-19-033954_create_users/down.sql b/trifid-api/migrations/2023-11-19-033954_create_users/down.sql new file mode 100644 index 0000000..441087a --- /dev/null +++ b/trifid-api/migrations/2023-11-19-033954_create_users/down.sql @@ -0,0 +1 @@ +DROP TABLE users; \ No newline at end of file diff --git a/trifid-api/migrations/2023-11-19-033954_create_users/up.sql b/trifid-api/migrations/2023-11-19-033954_create_users/up.sql new file mode 100644 index 0000000..65f7aa6 --- /dev/null +++ b/trifid-api/migrations/2023-11-19-033954_create_users/up.sql @@ -0,0 +1,4 @@ +CREATE TABLE users ( + id VARCHAR NOT NULL PRIMARY KEY, + email VARCHAR NOT NULL PRIMARY KEY +); \ No newline at end of file diff --git a/trifid-api/src/config.rs b/trifid-api/src/config.rs index 082c878..0226ce9 100644 --- a/trifid-api/src/config.rs +++ b/trifid-api/src/config.rs @@ -1,736 +1,25 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. -// Copyright (C) 2023 c0repwn3r -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +use std::net::IpAddr; +use serde::Deserialize; -use ipnet::{IpNet, Ipv4Net}; -use log::error; -use once_cell::sync::Lazy; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::error::Error; -use std::fs; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; -use std::path::PathBuf; -use std::time::SystemTime; - -use trifid_pki::cert::deserialize_nebula_certificate_from_pem; - -pub static CONFIG: Lazy = Lazy::new(|| { - let config_str = match fs::read_to_string("/etc/trifid/config.toml") { - Ok(str) => str, - Err(e) => { - error!("Unable to read config file: {}", e); - std::process::exit(1); - } - }; - - match toml::from_str(&config_str) { - Ok(cfg) => cfg, - Err(e) => { - error!("Unable to parse config file: {}", e); - std::process::exit(1); - } - } -}); - -#[derive(Serialize, Debug, Deserialize)] -pub struct TrifidConfig { - pub database: TrifidConfigDatabase, - pub server: TrifidConfigServer, - pub tokens: TrifidConfigTokens, - pub crypto: TrifidConfigCryptography, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct TrifidConfigDatabase { - pub url: String, - #[serde(default = "max_connections_default")] - pub max_connections: u32, - #[serde(default = "min_connections_default")] - pub min_connections: u32, - #[serde(default = "time_defaults")] - pub connect_timeout: u64, - #[serde(default = "time_defaults")] - pub acquire_timeout: u64, - #[serde(default = "time_defaults")] - pub idle_timeout: u64, - #[serde(default = "time_defaults")] - pub max_lifetime: u64, - #[serde(default = "sqlx_logging_default")] - pub sqlx_logging: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct TrifidConfigServer { - #[serde(default = "socketaddr_8080")] - pub bind: SocketAddr, - #[serde(default = "default_workers")] - pub workers: usize -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct TrifidConfigTokens { - #[serde(default = "magic_link_expiry_time")] - pub magic_link_expiry_time_seconds: u64, - #[serde(default = "session_token_expiry_time")] - pub session_token_expiry_time_seconds: u64, - #[serde(default = "totp_setup_timeout_time")] - pub totp_setup_timeout_time_seconds: u64, - #[serde(default = "mfa_tokens_expiry_time")] - pub mfa_tokens_expiry_time_seconds: u64, - #[serde(default = "enrollment_tokens_expiry_time")] - pub enrollment_tokens_expiry_time: u64, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct TrifidConfigCryptography { - pub data_encryption_key: String, - pub local_keystore_directory: PathBuf, - #[serde(default = "certs_expiry_time")] - pub certs_expiry_time: u64, -} - -fn max_connections_default() -> u32 { - 100 -} -fn min_connections_default() -> u32 { - 5 -} -fn time_defaults() -> u64 { - 8 -} -fn sqlx_logging_default() -> bool { - true -} -fn socketaddr_8080() -> SocketAddr { - SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::from([0, 0, 0, 0]), 8080)) -} -fn magic_link_expiry_time() -> u64 { - 3600 -} // 1 hour -fn session_token_expiry_time() -> u64 { - 15780000 -} // 6 months -fn totp_setup_timeout_time() -> u64 { - 600 -} // 10 minutes -fn mfa_tokens_expiry_time() -> u64 { - 600 -} // 10 minutes -fn enrollment_tokens_expiry_time() -> u64 { - 600 -} // 10 minutes -fn certs_expiry_time() -> u64 { - 3600 * 24 * 31 * 12 // 1 year -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfig { - pub pki: NebulaConfigPki, - #[serde(default = "empty_hashmap")] - #[serde(skip_serializing_if = "is_empty_hashmap")] - pub static_host_map: HashMap>, - #[serde(skip_serializing_if = "is_none")] - pub lighthouse: Option, - #[serde(skip_serializing_if = "is_none")] - pub listen: Option, - #[serde(skip_serializing_if = "is_none")] - pub punchy: Option, - #[serde(default = "cipher_aes")] - #[serde(skip_serializing_if = "is_cipher_aes")] - pub cipher: NebulaConfigCipher, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub preferred_ranges: Vec, - #[serde(skip_serializing_if = "is_none")] - pub relay: Option, - #[serde(skip_serializing_if = "is_none")] - pub tun: Option, - #[serde(skip_serializing_if = "is_none")] - pub logging: Option, - #[serde(skip_serializing_if = "is_none")] - pub sshd: Option, - - #[serde(skip_serializing_if = "is_none")] - pub firewall: Option, - - #[serde(default = "u64_1")] - #[serde(skip_serializing_if = "is_u64_1")] - pub routines: u64, - - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub stats: Option, - - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub local_range: Option, -} - -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct NebulaConfigPki { - pub ca: String, - pub cert: String, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub key: Option, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub blocklist: Vec, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub disconnect_invalid: bool, -} - -impl PartialEq for NebulaConfigPki { - fn eq(&self, other: &Self) -> bool { - if self.ca != other.ca { - return false; - } - if self.key != other.key { - return false; - } - if self.blocklist != other.blocklist { - return false; - } - if self.disconnect_invalid != other.disconnect_invalid { - return false; - } - - // cert logic - // if the cert is invalid, fallback to just checking equality - match is_cert_equal_ignoring_expiry(&self.cert, &other.cert) { - Ok(res) => res, - Err(_) => self.cert == other.cert, - } - } -} - -fn is_cert_equal_ignoring_expiry(me: &str, other: &str) -> Result> { - // determines if the certificates are equal, ignoring not_before, not_after and the signature - // exception: if either certificate is expired, not_before and not_after will be checked anyway - - // parse cert A - let cert_a = deserialize_nebula_certificate_from_pem(me.as_bytes())?; - let cert_b = deserialize_nebula_certificate_from_pem(other.as_bytes())?; - - if cert_a.details.is_ca != cert_b.details.is_ca { - return Ok(false); - } - if cert_a.details.name != cert_b.details.name { - return Ok(false); - } - if cert_a.details.public_key != cert_b.details.public_key { - return Ok(false); - } - if cert_a.details.groups != cert_b.details.groups { - return Ok(false); - } - if cert_a.details.ips != cert_b.details.ips { - return Ok(false); - } - if cert_a.details.issuer != cert_b.details.issuer { - return Ok(false); - } - if cert_a.details.subnets != cert_b.details.subnets { - return Ok(false); - } - - if cert_a.expired(SystemTime::now()) || cert_b.expired(SystemTime::now()) { - if cert_a.details.not_before != cert_b.details.not_before { - return Ok(false); - } - if cert_a.details.not_after != cert_b.details.not_after { - return Ok(false); - } - if cert_a.signature != cert_b.signature { - return Ok(false); - } - } - - Ok(true) -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigLighthouse { - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub am_lighthouse: bool, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub serve_dns: bool, - #[serde(skip_serializing_if = "is_none")] - pub dns: Option, - #[serde(default = "u32_10")] - #[serde(skip_serializing_if = "is_u32_10")] - pub interval: u32, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub hosts: Vec, - #[serde(default = "empty_hashmap")] - #[serde(skip_serializing_if = "is_empty_hashmap")] - pub remote_allow_list: HashMap, - #[serde(default = "empty_hashmap")] - #[serde(skip_serializing_if = "is_empty_hashmap")] - pub local_allow_list: HashMap, // `interfaces` is not supported +#[derive(Deserialize, Clone)] +pub struct Config { + pub server: ConfigServer, + pub database: ConfigDatabase } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigLighthouseDns { - #[serde(default = "string_empty")] - #[serde(skip_serializing_if = "is_string_empty")] - pub host: String, - #[serde(default = "u16_53")] - #[serde(skip_serializing_if = "is_u16_53")] - pub port: u16, +#[derive(Deserialize, Clone)] +pub struct ConfigServer { + pub bind: ConfigServerBind, + pub workers: Option } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigListen { - #[serde(default = "string_empty")] - #[serde(skip_serializing_if = "is_string_empty")] - pub host: String, - #[serde(default = "u16_0")] - #[serde(skip_serializing_if = "is_u16_0")] - pub port: u16, - #[serde(default = "u32_64")] - #[serde(skip_serializing_if = "is_u32_64")] - pub batch: u32, - #[serde(skip_serializing_if = "is_none")] - pub read_buffer: Option, - #[serde(skip_serializing_if = "is_none")] - pub write_buffer: Option, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigPunchy { - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub punch: bool, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub respond: bool, - #[serde(default = "string_1s")] - #[serde(skip_serializing_if = "is_string_1s")] - pub delay: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub enum NebulaConfigCipher { - #[serde(rename = "aes")] - Aes, - #[serde(rename = "chachapoly")] - ChaChaPoly, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigRelay { - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub relays: Vec, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub am_relay: bool, - #[serde(default = "bool_true")] - #[serde(skip_serializing_if = "is_bool_true")] - pub use_relays: bool, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigTun { - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub disabled: bool, - #[serde(skip_serializing_if = "is_none")] - pub dev: Option, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub drop_local_broadcast: bool, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub drop_multicast: bool, - #[serde(default = "u64_500")] - #[serde(skip_serializing_if = "is_u64_500")] - pub tx_queue: u64, - #[serde(default = "u64_1300")] - #[serde(skip_serializing_if = "is_u64_1300")] - pub mtu: u64, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub routes: Vec, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub unsafe_routes: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigTunRouteOverride { - pub mtu: u64, - pub route: Ipv4Net, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigTunUnsafeRoute { - pub route: Ipv4Net, - pub via: Ipv4Addr, - #[serde(default = "u64_1300")] - #[serde(skip_serializing_if = "is_u64_1300")] - pub mtu: u64, - #[serde(default = "i64_100")] - #[serde(skip_serializing_if = "is_i64_100")] - pub metric: i64, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigLogging { - #[serde(default = "loglevel_info")] - #[serde(skip_serializing_if = "is_loglevel_info")] - pub level: NebulaConfigLoggingLevel, - #[serde(default = "format_text")] - #[serde(skip_serializing_if = "is_format_text")] - pub format: NebulaConfigLoggingFormat, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub disable_timestamp: bool, - #[serde(default = "timestamp")] - #[serde(skip_serializing_if = "is_timestamp")] - pub timestamp_format: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub enum NebulaConfigLoggingLevel { - #[serde(rename = "panic")] - Panic, - #[serde(rename = "fatal")] - Fatal, - #[serde(rename = "error")] - Error, - #[serde(rename = "warning")] - Warning, - #[serde(rename = "info")] - Info, - #[serde(rename = "debug")] - Debug, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub enum NebulaConfigLoggingFormat { - #[serde(rename = "json")] - Json, - #[serde(rename = "text")] - Text, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigSshd { - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub enabled: bool, - pub listen: SocketAddrV4, - pub host_key: String, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub authorized_users: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigSshdAuthorizedUser { - pub user: String, - #[serde(default = "empty_vec")] - #[serde(skip_serializing_if = "is_empty_vec")] - pub keys: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -#[serde(tag = "type")] -pub enum NebulaConfigStats { - #[serde(rename = "graphite")] - Graphite(NebulaConfigStatsGraphite), - #[serde(rename = "prometheus")] - Prometheus(NebulaConfigStatsPrometheus), -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigStatsGraphite { - #[serde(default = "string_nebula")] - #[serde(skip_serializing_if = "is_string_nebula")] - pub prefix: String, - #[serde(default = "protocol_tcp")] - #[serde(skip_serializing_if = "is_protocol_tcp")] - pub protocol: NebulaConfigStatsGraphiteProtocol, - pub host: SocketAddrV4, - pub interval: String, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub message_metrics: bool, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub lighthouse_metrics: bool, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub enum NebulaConfigStatsGraphiteProtocol { - #[serde(rename = "tcp")] - Tcp, - #[serde(rename = "udp")] - Udp, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigStatsPrometheus { - pub listen: String, - pub path: String, - #[serde(default = "string_nebula")] - #[serde(skip_serializing_if = "is_string_nebula")] - pub namespace: String, - #[serde(default = "string_nebula")] - #[serde(skip_serializing_if = "is_string_nebula")] - pub subsystem: String, - pub interval: String, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub message_metrics: bool, - #[serde(default = "bool_false")] - #[serde(skip_serializing_if = "is_bool_false")] - pub lighthouse_metrics: bool, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigFirewall { - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub conntrack: Option, - - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub inbound: Option>, - - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub outbound: Option>, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigFirewallConntrack { - #[serde(default = "string_12m")] - #[serde(skip_serializing_if = "is_string_12m")] - pub tcp_timeout: String, - #[serde(default = "string_3m")] - #[serde(skip_serializing_if = "is_string_3m")] - pub udp_timeout: String, - #[serde(default = "string_10m")] - #[serde(skip_serializing_if = "is_string_10m")] - pub default_timeout: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct NebulaConfigFirewallRule { - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub port: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub proto: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub ca_name: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub ca_sha: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub host: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub group: Option, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub groups: Option>, - #[serde(default = "none")] - #[serde(skip_serializing_if = "is_none")] - pub cidr: Option, -} - -// Default values for serde - -fn string_12m() -> String { - "12m".to_string() -} -fn is_string_12m(s: &str) -> bool { - s == "12m" -} - -fn string_3m() -> String { - "3m".to_string() -} -fn is_string_3m(s: &str) -> bool { - s == "3m" -} - -fn string_10m() -> String { - "10m".to_string() -} -fn is_string_10m(s: &str) -> bool { - s == "10m" -} - -fn empty_vec() -> Vec { - vec![] -} -fn is_empty_vec(v: &Vec) -> bool { - v.is_empty() -} - -fn empty_hashmap() -> HashMap { - HashMap::new() -} -fn is_empty_hashmap(h: &HashMap) -> bool { - h.is_empty() -} - -fn bool_false() -> bool { - false -} -fn is_bool_false(b: &bool) -> bool { - !*b -} - -fn bool_true() -> bool { - true -} -fn is_bool_true(b: &bool) -> bool { - *b -} - -fn u16_53() -> u16 { - 53 -} -fn is_u16_53(u: &u16) -> bool { - *u == 53 -} - -fn u32_10() -> u32 { - 10 -} -fn is_u32_10(u: &u32) -> bool { - *u == 10 -} - -fn u16_0() -> u16 { - 0 -} -fn is_u16_0(u: &u16) -> bool { - *u == 0 -} - -fn u32_64() -> u32 { - 64 -} -fn is_u32_64(u: &u32) -> bool { - *u == 64 -} - -fn string_1s() -> String { - "1s".to_string() -} -fn is_string_1s(s: &str) -> bool { - s == "1s" -} - -fn cipher_aes() -> NebulaConfigCipher { - NebulaConfigCipher::Aes -} -fn is_cipher_aes(c: &NebulaConfigCipher) -> bool { - matches!(c, NebulaConfigCipher::Aes) -} - -fn u64_500() -> u64 { - 500 -} -fn is_u64_500(u: &u64) -> bool { - *u == 500 -} - -fn u64_1300() -> u64 { - 1300 -} -fn is_u64_1300(u: &u64) -> bool { - *u == 1300 -} - -fn i64_100() -> i64 { - 100 -} -fn is_i64_100(i: &i64) -> bool { - *i == 100 -} - -fn loglevel_info() -> NebulaConfigLoggingLevel { - NebulaConfigLoggingLevel::Info -} -fn is_loglevel_info(l: &NebulaConfigLoggingLevel) -> bool { - matches!(l, NebulaConfigLoggingLevel::Info) -} - -fn format_text() -> NebulaConfigLoggingFormat { - NebulaConfigLoggingFormat::Text -} -fn is_format_text(f: &NebulaConfigLoggingFormat) -> bool { - matches!(f, NebulaConfigLoggingFormat::Text) -} - -fn timestamp() -> String { - "2006-01-02T15:04:05Z07:00".to_string() -} -fn is_timestamp(s: &str) -> bool { - s == "2006-01-02T15:04:05Z07:00" -} - -fn u64_1() -> u64 { - 1 -} -fn is_u64_1(u: &u64) -> bool { - *u == 1 -} - -fn string_nebula() -> String { - "nebula".to_string() -} -fn is_string_nebula(s: &str) -> bool { - s == "nebula" -} - -fn string_empty() -> String { - String::new() -} -fn is_string_empty(s: &str) -> bool { - s.is_empty() -} - -fn protocol_tcp() -> NebulaConfigStatsGraphiteProtocol { - NebulaConfigStatsGraphiteProtocol::Tcp -} -fn is_protocol_tcp(p: &NebulaConfigStatsGraphiteProtocol) -> bool { - matches!(p, NebulaConfigStatsGraphiteProtocol::Tcp) -} - -fn none() -> Option { - None -} -fn is_none(o: &Option) -> bool { - o.is_none() +#[derive(Deserialize, Clone)] +pub struct ConfigServerBind { + pub ip: IpAddr, + pub port: u16 } -fn default_workers() -> usize { 32 } \ No newline at end of file +#[derive(Deserialize, Clone)] +pub struct ConfigDatabase { + pub url: String +} \ No newline at end of file diff --git a/trifid-api/src/error.rs b/trifid-api/src/error.rs index 73017f9..c1f9cf6 100644 --- a/trifid-api/src/error.rs +++ b/trifid-api/src/error.rs @@ -1,72 +1,53 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. -// Copyright (C) 2023 c0repwn3r -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - +use std::fmt::{Display, Formatter}; use actix_web::error::{JsonPayloadError, PayloadError}; -use serde::{Deserialize, Serialize}; +use serde::Serialize; -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct APIErrorsResponse { - pub errors: Vec, -} -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct APIError { +#[derive(Serialize, Debug)] +pub struct APIErrorResponse { pub code: String, pub message: String, - #[serde(skip_serializing_if = "is_none")] - #[serde(default)] - pub path: Option, + pub path: Option } -fn is_none(o: &Option) -> bool { - o.is_none() +impl Display for APIErrorResponse { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } } -impl From<&JsonPayloadError> for APIError { +impl From<&JsonPayloadError> for APIErrorResponse { fn from(value: &JsonPayloadError) -> Self { match value { JsonPayloadError::OverflowKnownLength { length, limit } => { - APIError { + APIErrorResponse { code: "ERR_PAYLOAD_OVERFLOW_KNOWN_LENGTH".to_string(), message: format!("Payload size is bigger than allowed & content length header set. (length: {}, limit: {})", length, limit), - path: None + path: None, } }, JsonPayloadError::Overflow { limit } => { - APIError { + APIErrorResponse { code: "ERR_PAYLOAD_OVERFLOW".to_string(), message: format!("Payload size is bigger than allowed but no content-length header is set. (limit: {})", limit), - path: None + path: None, } }, JsonPayloadError::ContentType => { - APIError { + APIErrorResponse { code: "ERR_NOT_JSON".to_string(), message: "Content-Type header not set to expected application/json".to_string(), path: None, } }, JsonPayloadError::Deserialize(e) => { - APIError { + APIErrorResponse { code: "ERR_JSON_DESERIALIZE".to_string(), message: format!("Error deserializing JSON: {}", e), path: None, } }, JsonPayloadError::Serialize(e) => { - APIError { + APIErrorResponse { code: "ERR_JSON_SERIALIZE".to_string(), message: format!("Error serializing JSON: {}", e), path: None, @@ -76,7 +57,7 @@ impl From<&JsonPayloadError> for APIError { e.into() }, _ => { - APIError { + APIErrorResponse { code: "ERR_UNKNOWN_ERROR".to_string(), message: "An unknown error has occured".to_string(), path: None, @@ -86,10 +67,10 @@ impl From<&JsonPayloadError> for APIError { } } -impl From<&PayloadError> for APIError { +impl From<&PayloadError> for APIErrorResponse { fn from(value: &PayloadError) -> Self { match value { - PayloadError::Incomplete(e) => APIError { + PayloadError::Incomplete(e) => APIErrorResponse { code: "ERR_UNEXPECTED_EOF".to_string(), message: match e { None => "Payload reached EOF but was incomplete".to_string(), @@ -97,36 +78,36 @@ impl From<&PayloadError> for APIError { }, path: None, }, - PayloadError::EncodingCorrupted => APIError { + PayloadError::EncodingCorrupted => APIErrorResponse { code: "ERR_CORRUPTED_PAYLOAD".to_string(), message: "Payload content encoding corrupted".to_string(), path: None, }, - PayloadError::Overflow => APIError { + PayloadError::Overflow => APIErrorResponse { code: "ERR_PAYLOAD_OVERFLOW".to_string(), message: "Payload reached size limit".to_string(), path: None, }, - PayloadError::UnknownLength => APIError { + PayloadError::UnknownLength => APIErrorResponse { code: "ERR_PAYLOAD_UNKNOWN_LENGTH".to_string(), message: "Unable to determine payload length".to_string(), path: None, }, - PayloadError::Http2Payload(e) => APIError { + PayloadError::Http2Payload(e) => APIErrorResponse { code: "ERR_HTTP2_ERROR".to_string(), message: format!("HTTP/2 error: {}", e), path: None, }, - PayloadError::Io(e) => APIError { + PayloadError::Io(e) => APIErrorResponse { code: "ERR_IO_ERROR".to_string(), message: format!("I/O error: {}", e), path: None, }, - _ => APIError { + _ => APIErrorResponse { code: "ERR_UNKNOWN_ERROR".to_string(), message: "An unknown error has occured".to_string(), path: None, }, } } -} +} \ No newline at end of file diff --git a/trifid-api/src/macros.rs b/trifid-api/src/macros.rs new file mode 100644 index 0000000..5508dc1 --- /dev/null +++ b/trifid-api/src/macros.rs @@ -0,0 +1,63 @@ +#[macro_export] +macro_rules! err { + ($c:expr,$e:expr) => { + return $crate::response::JsonAPIResponse::Error($c, $e) + }; +} + +#[macro_export] +macro_rules! ok { + ($c:expr,$e:expr) => { + return $crate::response::JsonAPIResponse::Success($c, $e) + }; + ($e:expr) => { + return $crate::response::JsonAPIResponse::Success(actix_web::http::StatusCode::OK, $e) + }; +} + +#[macro_export] +macro_rules! internal_error { + ($e:expr) => {{ + log::error!("internal error: {}", $e); + $crate::err!(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR, $crate::make_err!("ERR_INTERNAL_ERROR", $e)); + }}; +} + +#[macro_export] +macro_rules! handle_error { + ($e:expr,$c:expr,$r:expr) => { + match $e { + Ok(r) => r, + Err(e) => { + log::error!("error: {}", e); + $crate::err!($c, $r) + } + } + }; + ($e:expr) => { + match $e { + Ok(r) => r, + Err(e) => { + $crate::internal_error!(e) + } + } + }; +} + +#[macro_export] +macro_rules! make_err { + ($c:expr,$m:expr,$p:expr) => { + $crate::error::APIErrorResponse { + code: $c.to_string(), + message: $m.to_string(), + path: Some($p.to_string()) + } + }; + ($c:expr,$m:expr) => { + $crate::error::APIErrorResponse { + code: $c.to_string(), + message: $m.to_string(), + path: None + } + }; +} \ No newline at end of file diff --git a/trifid-api/src/main.rs b/trifid-api/src/main.rs index c3923a1..5210f4a 100644 --- a/trifid-api/src/main.rs +++ b/trifid-api/src/main.rs @@ -1,126 +1,119 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. -// Copyright (C) 2023 c0repwn3r -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +use std::fs; +use std::path::PathBuf; +use actix_web::{App, Error, HttpResponse, HttpServer}; +use actix_web::middleware::Logger; +use actix_web::web::{Data, JsonConfig}; +use diesel::Connection; +use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; +use diesel_async::AsyncPgConnection; +use diesel_async::pooled_connection::AsyncDieselConnectionManager; +use diesel_async::pooled_connection::bb8::Pool; +use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; +use log::{error, info}; +use crate::config::Config; +use crate::error::APIErrorResponse; -use actix_request_identifier::RequestIdentifier; -use actix_web::{ - web::{Data, JsonConfig}, - App, HttpResponse, HttpServer, -}; -use log::{info, Level}; -use sea_orm::{ConnectOptions, Database, DatabaseConnection}; -use std::error::Error; -use std::time::Duration; -use actix_cors::Cors; -use crate::config::CONFIG; -use crate::error::{APIError, APIErrorsResponse}; -use crate::tokens::random_id_no_id; -use trifid_api_migration::{Migrator, MigratorTrait}; - -pub mod auth_tokens; -pub mod codegen; -pub mod config; -pub mod crypto; -pub mod cursor; pub mod error; -//pub mod legacy_keystore; // TODO- Remove -pub mod magic_link; -pub mod routes; -pub mod timers; -pub mod tokens; pub mod response; +pub mod macros; +pub mod config; +pub mod routes; +#[derive(Clone)] pub struct AppState { - pub conn: DatabaseConnection, + pub config: Config, + pub pool: bb8::Pool> } +pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); + #[actix_web::main] -async fn main() -> Result<(), Box> { - simple_logger::init_with_level(Level::Debug).unwrap(); +async fn main() { + env_logger::init(); + info!("Trifid API v{} starting up", env!("CARGO_PKG_VERSION")); - info!("Connecting to database at {}...", CONFIG.database.url); + let mut args = std::env::args(); + let config_path = match args.nth(1) { + Some(path) => path, + None => { + eprintln!("usage: trifid-api "); + std::process::exit(1); + } + }; - let mut opt = ConnectOptions::new(CONFIG.database.url.clone()); - opt.max_connections(CONFIG.database.max_connections) - .min_connections(CONFIG.database.min_connections) - .connect_timeout(Duration::from_secs(CONFIG.database.connect_timeout)) - .acquire_timeout(Duration::from_secs(CONFIG.database.acquire_timeout)) - .idle_timeout(Duration::from_secs(CONFIG.database.idle_timeout)) - .max_lifetime(Duration::from_secs(CONFIG.database.max_lifetime)) - .sqlx_logging(CONFIG.database.sqlx_logging) - .sqlx_logging_level(log::LevelFilter::Info); + let config_pathbuf = PathBuf::from(config_path); + info!("Loading config from {}", config_pathbuf.display()); - let db = Database::connect(opt).await?; + let config_str = match fs::read_to_string(&config_pathbuf) { + Ok(c_str) => c_str, + Err(e) => { + error!("Error loading configuration from {}: {}", config_pathbuf.display(), e); + std::process::exit(1); + } + }; - info!("Performing database migration..."); - Migrator::up(&db, None).await?; + let config: Config = match toml::from_str(&config_str) { + Ok(config) => config, + Err(e) => { + error!("Error parsing configuration in {}: {}", config_pathbuf.display(), e); + std::process::exit(1); + } + }; - let data = Data::new(AppState { conn: db }); + info!("Connecting to the database..."); - HttpServer::new(move || { + let pool_config = AsyncDieselConnectionManager::::new(&config.database.url); + let pool = match Pool::builder().build(pool_config).await { + Ok(pool) => pool, + Err(e) => { + error!("Error while creating database pool: {}", e); + std::process::exit(1); + } + }; + + info!("Running pending migrations..."); + + { // Lock block + let mut conn = match AsyncConnectionWrapper::::establish(&config.database.url) { + Ok(conn) => conn, + Err(e) => { + error!("Error acquiring connection from pool: {}", e); + std::process::exit(1); + } + }; + + match conn.run_pending_migrations(MIGRATIONS) { + Ok(_) => (), + Err(e) => { + error!("Failed to run pending migrations: {}", e) + } + } + } + + let local_config = config.clone(); + + let app_state = Data::new(AppState { + config, + pool + }); + + let server = HttpServer::new(move || { App::new() - .wrap(Cors::permissive()) - .app_data(data.clone()) - .app_data( - JsonConfig::default() - .content_type_required(false) - .error_handler(|err, _req| { - let api_error: APIError = (&err).into(); - actix_web::error::InternalError::from_response( - err, - HttpResponse::BadRequest().json(APIErrorsResponse { - errors: vec![api_error], - }), - ) - .into() - }), - ) - .wrap(RequestIdentifier::with_generator(random_id_no_id)) - .service(routes::v1::auth::magic_link::magic_link_request) - .service(routes::v1::signup::signup_request) - .service(routes::v1::auth::verify_magic_link::verify_magic_link_request) - .service(routes::v1::totp_authenticators::totp_authenticators_request) - .service(routes::v1::verify_totp_authenticators::verify_totp_authenticators_request) - .service(routes::v1::auth::totp::totp_request) - .service(routes::v1::networks::get_networks) - .service(routes::v1::organization::create_org_request) - .service(routes::v1::networks::get_network_request) - .service(routes::v1::roles::create_role_request) - .service(routes::v1::roles::get_roles) - .service(routes::v1::roles::get_role) - .service(routes::v1::roles::delete_role) - .service(routes::v1::roles::update_role_request) - .service(routes::v1::trifid::trifid_extensions) - .service(routes::v1::hosts::get_hosts) - .service(routes::v1::hosts::create_hosts_request) - .service(routes::v1::hosts::get_host) - .service(routes::v1::hosts::delete_host) - .service(routes::v1::hosts::edit_host) - .service(routes::v1::hosts::block_host) - .service(routes::v1::hosts::enroll_host) - .service(routes::v1::hosts::create_host_and_enrollment_code) - .service(routes::v2::enroll::enroll) - .service(routes::v1::dnclient::dnclient) - .service(routes::v2::whoami::whoami) - .service(routes::v1::hosts::get_host_overrides) - .service(routes::v1::hosts::update_host_overrides) - }) - .workers(CONFIG.server.workers) - .bind(CONFIG.server.bind)? - .run() - .await?; + .app_data(JsonConfig::default().error_handler(|err, _rq| { + Error::from({ + let err2: APIErrorResponse = (&err).into(); + actix_web::error::InternalError::from_response( + err, + HttpResponse::BadRequest().json(err2), + ) + }) + })) + .wrap(Logger::default()) + .wrap(actix_cors::Cors::permissive()) + .app_data(app_state.clone()) + }).bind((local_config.server.bind.ip, local_config.server.bind.port)).unwrap(); - Ok(()) + server.run().await.unwrap(); + + info!("Goodbye!"); } diff --git a/trifid-api/src/response.rs b/trifid-api/src/response.rs index 06e797e..c15bf66 100644 --- a/trifid-api/src/response.rs +++ b/trifid-api/src/response.rs @@ -1,49 +1,40 @@ -use std::fmt::{Display, Formatter}; -use actix_web::{HttpRequest, HttpResponse, Responder, ResponseError}; -use actix_web::body::EitherBody; -use actix_web::web::Json; -use log::error; -use sea_orm::DbErr; - -use crate::error::{APIError, APIErrorsResponse}; - -pub struct OkResponse(T); +use std::fmt::{Debug, Display, Formatter}; +use actix_web::body::BoxBody; +use actix_web::http::StatusCode; +use actix_web::{HttpRequest, HttpResponse, Responder}; +use actix_web::error::JsonPayloadError; +use serde::Serialize; +use crate::error::APIErrorResponse; #[derive(Debug)] -pub struct ErrResponse(APIErrorsResponse); - -impl Responder for OkResponse { - type Body = T::Body; - - fn respond_to(self, req: &HttpRequest) -> HttpResponse { - self.0.respond_to(req) - } -} -impl Responder for ErrResponse { - type Body = EitherBody; - - fn respond_to(self, req: &HttpRequest) -> HttpResponse { - Json(self.0).respond_to(req) - } +pub enum JsonAPIResponse { + Error(StatusCode, APIErrorResponse), + Success(StatusCode, T) } -impl From for ErrResponse { - fn from(value: DbErr) -> Self { - error!("database error: {}", value); - Self(APIErrorsResponse { errors: vec![ - APIError { - code: "ERR_DB_ERROR".to_string(), - message: "There was an error performing the database query. Please try again later.".to_string(), - path: None, - } - ] }) - } -} - -impl Display for ErrResponse { +impl Display for JsonAPIResponse { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) + write!(f, "{:?}", self) } } -impl ResponseError for ErrResponse {} \ No newline at end of file +impl Responder for JsonAPIResponse { + type Body = BoxBody; + + fn respond_to(self, _: &HttpRequest) -> HttpResponse { + match self { + JsonAPIResponse::Error(c, r) => { + match serde_json::to_string(&r) { + Ok(body) => HttpResponse::build(c).body(body), + Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err)) + } + } + JsonAPIResponse::Success(c, b) => { + match serde_json::to_string(&b) { + Ok(body) => HttpResponse::build(c).body(body), + Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err)) + } + } + } + } +} \ No newline at end of file diff --git a/trifid-api/src/routes/mod.rs b/trifid-api/src/routes/mod.rs index ae6adc7..5dd9fd0 100644 --- a/trifid-api/src/routes/mod.rs +++ b/trifid-api/src/routes/mod.rs @@ -1,2 +1 @@ -pub mod v1; -pub mod v2; +pub mod v1; \ No newline at end of file diff --git a/trifid-api/src/routes/v1/mod.rs b/trifid-api/src/routes/v1/mod.rs index 7e8f5a9..a4f0d8d 100644 --- a/trifid-api/src/routes/v1/mod.rs +++ b/trifid-api/src/routes/v1/mod.rs @@ -1,10 +1 @@ -pub mod auth; -pub mod dnclient; -pub mod hosts; -pub mod networks; -pub mod organization; -pub mod roles; -pub mod signup; -pub mod totp_authenticators; -pub mod trifid; -pub mod verify_totp_authenticators; +pub mod signup; \ No newline at end of file diff --git a/trifid-api/src/routes/v1/signup.rs b/trifid-api/src/routes/v1/signup.rs index babe7bb..e2fc73c 100644 --- a/trifid-api/src/routes/v1/signup.rs +++ b/trifid-api/src/routes/v1/signup.rs @@ -1,151 +1,21 @@ -// trifid-api, an open source reimplementation of the Defined Networking nebula management server. -// Copyright (C) 2023 c0repwn3r -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -//#POST /v1/signup t+parity:full t+type:reverse_engineered t+status:done t+features:definednetworking -// This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. -// This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. -// This endpoint requires the `definednetworking` extension to be enabled to be used. - -use crate::config::CONFIG; -use crate::error::{APIError, APIErrorsResponse}; -use crate::magic_link::send_magic_link; -use crate::timers::expires_in_seconds; -use crate::tokens::{random_id, random_token}; -use crate::AppState; use actix_web::web::{Data, Json}; -use actix_web::{post, HttpResponse}; -use log::error; -use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter}; use serde::{Deserialize, Serialize}; -use trifid_api_entities::entity::user; -use trifid_api_entities::entity::user::Entity as UserEntity; +use crate::AppState; +use crate::response::JsonAPIResponse; -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Deserialize)] pub struct SignupRequest { - pub email: String, + pub email: String } -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Debug)] pub struct SignupResponse { - pub data: Option, - pub metadata: SignupResponseMetadata, + pub data: Option<()>, + pub metadata: SignupResponseMetadata } -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct SignupResponseData {} -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Debug)] pub struct SignupResponseMetadata {} -#[post("/v1/signup")] -pub async fn signup_request(data: Data, req: Json) -> HttpResponse { - let user: Vec = match UserEntity::find() - .filter(user::Column::Email.eq(&req.email)) - .all(&data.conn) - .await - { - Ok(r) => r, - Err(e) => { - error!("database error: {}", e); - return HttpResponse::InternalServerError().json(APIErrorsResponse { - errors: vec![APIError { - code: "ERR_DB_ERROR".to_string(), - message: - "There was an error with the database request, please try again later." - .to_string(), - path: None, - }], - }); - } - }; - - if !user.is_empty() { - return HttpResponse::Unauthorized().json(APIErrorsResponse { - errors: vec![APIError { - code: "ERR_USER_EXISTS".to_string(), - message: "That user already exists.".to_string(), - path: None, - }], - }); - } - - let model = user::Model { - id: random_id("user"), - email: req.email.clone(), - }; - let id = model.id.clone(); - - let active_model = model.into_active_model(); - - match active_model.insert(&data.conn).await { - Ok(_) => (), - Err(e) => { - error!("database error: {}", e); - return HttpResponse::InternalServerError().json(APIErrorsResponse { - errors: vec![APIError { - code: "ERR_DB_ERROR".to_string(), - message: - "There was an error with the database request, please try again later." - .to_string(), - path: None, - }], - }); - } - } - - let model = trifid_api_entities::entity::magic_link::Model { - id: random_token("ml"), - user: id, - expires_on: expires_in_seconds(CONFIG.tokens.magic_link_expiry_time_seconds) as i64, - }; - - match send_magic_link(&model.id) { - Ok(_) => (), - Err(e) => { - error!("error sending magic link: {}", e); - return HttpResponse::InternalServerError().json(APIErrorsResponse { - errors: vec![APIError { - code: "ERR_ML_ERROR".to_string(), - message: - "There was an error sending the magic link email, please try again later." - .to_string(), - path: None, - }], - }); - } - } - - let active_model = model.into_active_model(); - - match active_model.insert(&data.conn).await { - Ok(_) => (), - Err(e) => { - error!("database error: {}", e); - return HttpResponse::InternalServerError().json(APIErrorsResponse { - errors: vec![APIError { - code: "ERR_DB_ERROR".to_string(), - message: - "There was an error with the database request, please try again later." - .to_string(), - path: None, - }], - }); - } - } - - HttpResponse::Ok().json(SignupResponse { - data: None, - metadata: SignupResponseMetadata {}, - }) -} +pub async fn signup_req(req: Json, state: Data) -> JsonAPIResponse { + todo!() +} \ No newline at end of file