97e24d0d41
* Add record migration * Add database functions for inserting history No real tests yet :( I would like to avoid running postgres lol * Add index handler, use UUIDs not strings * Fix a bunch of tests, remove Option<Uuid> * Add tests, all passing * Working upload sync * Record downloading works * Sync download works * Don't waste requests * Use a page size for uploads, make it variable later * Aaaaaand they're encrypted now too * Add cek * Allow reading tail across hosts * Revert "Allow reading tail across hosts" Not like that This reverts commit 7b0c72e7e050c358172f9b53cbd21b9e44cf4931. * Handle multiple shards properly * format * Format and make clippy happy * use some fancy types (#1098) * use some fancy types * fmt * Goodbye horrible tuple * Update atuin-server-postgres/migrations/20230623070418_records.sql Co-authored-by: Conrad Ludgate <conradludgate@gmail.com> * fmt * Sort tests too because time sucks * fix features --------- Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
73 lines
2.4 KiB
Rust
73 lines
2.4 KiB
Rust
use std::{io::prelude::*, path::PathBuf};
|
|
|
|
use config::{Config, Environment, File as ConfigFile, FileFormat};
|
|
use eyre::{eyre, Result};
|
|
use fs_err::{create_dir_all, File};
|
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct Settings<DbSettings> {
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub path: String,
|
|
pub open_registration: bool,
|
|
pub max_history_length: usize,
|
|
pub max_record_size: usize,
|
|
pub page_size: i64,
|
|
pub register_webhook_url: Option<String>,
|
|
pub register_webhook_username: String,
|
|
|
|
#[serde(flatten)]
|
|
pub db_settings: DbSettings,
|
|
}
|
|
|
|
impl<DbSettings: DeserializeOwned> Settings<DbSettings> {
|
|
pub fn new() -> Result<Self> {
|
|
let mut config_file = if let Ok(p) = std::env::var("ATUIN_CONFIG_DIR") {
|
|
PathBuf::from(p)
|
|
} else {
|
|
let mut config_file = PathBuf::new();
|
|
let config_dir = atuin_common::utils::config_dir();
|
|
config_file.push(config_dir);
|
|
config_file
|
|
};
|
|
|
|
config_file.push("server.toml");
|
|
|
|
// create the config file if it does not exist
|
|
let mut config_builder = Config::builder()
|
|
.set_default("host", "127.0.0.1")?
|
|
.set_default("port", 8888)?
|
|
.set_default("open_registration", false)?
|
|
.set_default("max_history_length", 8192)?
|
|
.set_default("max_record_size", 1024 * 1024 * 1024)? // pretty chonky
|
|
.set_default("path", "")?
|
|
.set_default("register_webhook_username", "")?
|
|
.set_default("page_size", 1100)?
|
|
.add_source(
|
|
Environment::with_prefix("atuin")
|
|
.prefix_separator("_")
|
|
.separator("__"),
|
|
);
|
|
|
|
config_builder = if config_file.exists() {
|
|
config_builder.add_source(ConfigFile::new(
|
|
config_file.to_str().unwrap(),
|
|
FileFormat::Toml,
|
|
))
|
|
} else {
|
|
let example_config = include_bytes!("../server.toml");
|
|
create_dir_all(config_file.parent().unwrap())?;
|
|
let mut file = File::create(config_file)?;
|
|
file.write_all(example_config)?;
|
|
|
|
config_builder
|
|
};
|
|
|
|
let config = config_builder.build()?;
|
|
|
|
config
|
|
.try_deserialize()
|
|
.map_err(|e| eyre!("failed to deserialize: {}", e))
|
|
}
|
|
}
|