tada
This commit is contained in:
parent
79130d39e8
commit
8cd61cf7d3
6 changed files with 46 additions and 34 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -260,9 +260,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.95"
|
version = "1.0.96"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
|
|
@ -585,9 +585,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.3"
|
version = "0.14.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"allocator-api2",
|
"allocator-api2",
|
||||||
|
|
@ -827,9 +827,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.153"
|
version = "0.2.154"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
|
|
@ -1449,9 +1449,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.5.6"
|
version = "0.5.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
|
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
|
|
@ -1579,7 +1579,6 @@ dependencies = [
|
||||||
"sha2",
|
"sha2",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"sqlx-mysql",
|
"sqlx-mysql",
|
||||||
"sqlx-postgres",
|
|
||||||
"sqlx-sqlite",
|
"sqlx-sqlite",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ json-patch = "1.2.0"
|
||||||
# utoipa = { version = "4.2.0", features = ["axum_extras"] }
|
# utoipa = { version = "4.2.0", features = ["axum_extras"] }
|
||||||
sqlx = { version = "0.7.4", features = [
|
sqlx = { version = "0.7.4", features = [
|
||||||
"sqlite",
|
"sqlite",
|
||||||
"postgres",
|
# "postgres",
|
||||||
"any",
|
"any",
|
||||||
"macros",
|
"macros",
|
||||||
"runtime-tokio",
|
"runtime-tokio",
|
||||||
|
|
|
||||||
6
migrations/20240428160456_init.sql
Normal file
6
migrations/20240428160456_init.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- Add migration script here
|
||||||
|
|
||||||
|
CREATE TABLE secret_engines (
|
||||||
|
mount_point TEXT PRIMARY KEY NOT NULL,
|
||||||
|
engine_type TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
@ -9,18 +9,18 @@ pub fn kv_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/:mount_path/config", get(get_config))
|
.route("/:mount_path/config", get(get_config))
|
||||||
.route("/:mount_path/config", post(post_config))
|
.route("/:mount_path/config", post(post_config))
|
||||||
.route("/:mount_path/data/:path", get(get_data))
|
.route("/:mount_path/data/*path", get(get_data))
|
||||||
.route("/:mount_path/data/:path/", get(get_data))
|
// .route("/:mount_path/data/*path/", get(get_data))
|
||||||
.route("/:mount_path/data/:path", get(post_data))
|
.route("/:mount_path/data/*path", post(post_data))
|
||||||
.route("/:mount_path/data/:path", delete(delete_data))
|
.route("/:mount_path/data/*path", delete(delete_data))
|
||||||
.route("/:mount_path/delete/:path", post(delete_path))
|
.route("/:mount_path/delete/*path", post(delete_path))
|
||||||
.route("/:mount_path/destroy/:path", post(destroy_path))
|
.route("/:mount_path/destroy/*path", post(destroy_path))
|
||||||
.route("/:mount_path/metadata/:path", get(get_meta))
|
.route("/:mount_path/metadata/*path", get(get_meta))
|
||||||
.route("/:mount_path/metadata/:path/", get(get_meta))
|
// .route("/:mount_path/metadata/*path/", get(get_meta))
|
||||||
.route("/:mount_path/metadata/:path", post(post_meta))
|
.route("/:mount_path/metadata/*path", post(post_meta))
|
||||||
.route("/:mount_path/metadata/:path", delete(delete_meta))
|
.route("/:mount_path/metadata/*path", delete(delete_meta))
|
||||||
.route("/:mount_path/subkeys/:path", get(get_subkeys))
|
.route("/:mount_path/subkeys/*path", get(get_subkeys))
|
||||||
.route("/:mount_path/undelete/:path", post(post_undelete))
|
.route("/:mount_path/undelete/*path", post(post_undelete))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_config() -> &'static str {
|
async fn get_config() -> &'static str {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
use axum::{
|
use axum::{extract::Request, http::StatusCode, routing::get, Router};
|
||||||
extract::Request, http::StatusCode, routing::get, Router
|
|
||||||
};
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use sqlx::{Any, Pool};
|
use sqlx::{Any, Pool};
|
||||||
use tokio::net::TcpListener;
|
|
||||||
use std::{env, net::SocketAddr, str::FromStr};
|
use std::{env, net::SocketAddr, str::FromStr};
|
||||||
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
use crate::storage::create_pool;
|
use crate::storage::create_pool;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,27 @@
|
||||||
use sqlx::{
|
use std::{fs::File, path::Path};
|
||||||
any::{install_default_drivers, AnyPoolOptions},
|
|
||||||
AnyPool,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn create_pool(connection_string: String) -> AnyPool {
|
use log::*;
|
||||||
|
use sqlx::{any::AnyPoolOptions, AnyPool};
|
||||||
|
|
||||||
|
pub async fn create_pool(db_url: String) -> AnyPool {
|
||||||
// TODO: Change to solely install applicable driver
|
// TODO: Change to solely install applicable driver
|
||||||
install_default_drivers();
|
sqlx::any::install_default_drivers();
|
||||||
|
|
||||||
|
// Create SQLite database file if it does not exist
|
||||||
|
if db_url.starts_with("sqlite:") {
|
||||||
|
let path = db_url.replace("sqlite:", "");
|
||||||
|
if !Path::new(&path).exists() {
|
||||||
|
warn!("Sqlite database does not exist, creating file {}", path);
|
||||||
|
File::create(&path).expect("Failed to create database file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let pool = AnyPoolOptions::new()
|
let pool = AnyPoolOptions::new()
|
||||||
.max_connections(5)
|
.max_connections(5)
|
||||||
.test_before_acquire(true)
|
.test_before_acquire(true)
|
||||||
.connect(&connection_string)
|
.connect(&db_url)
|
||||||
.await
|
.await
|
||||||
.expect(&connection_string);
|
.expect(&db_url);
|
||||||
|
|
||||||
pool
|
pool
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue