diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-20 14:47:39 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-20 14:47:39 +0100 |
commit | 9499c195230a7d5adaebd46892b373c86c5248c2 (patch) | |
tree | ff652e9959dc2f0349a4e5aed75e8837b452e45f /tool | |
parent | 730353601db9818d148c85bfe1ecb119abaab7cc (diff) | |
download | jellything-9499c195230a7d5adaebd46892b373c86c5248c2.tar jellything-9499c195230a7d5adaebd46892b373c86c5248c2.tar.bz2 jellything-9499c195230a7d5adaebd46892b373c86c5248c2.tar.zst |
seperate secrets config file
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/main.rs | 122 |
1 files changed, 50 insertions, 72 deletions
diff --git a/tool/src/main.rs b/tool/src/main.rs index c220a08..58559dc 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -6,16 +6,13 @@ pub mod migrate; use anyhow::anyhow; -use base64::Engine; use clap::{Parser, Subcommand, ValueEnum}; +use jellybase::{CONF, SECRETS}; use jellyclient::Instance; -use jellycommon::{ - config::GlobalConfig, user::CreateSessionParams, Node, NodeKind, NodePrivate, NodePublic, -}; -use log::{info, warn}; +use jellycommon::user::CreateSessionParams; +use log::{error, info}; use migrate::migrate; -use rand::random; -use std::{fmt::Debug, fs::File, io::Write, path::PathBuf}; +use std::{fmt::Debug, path::PathBuf}; #[derive(Parser)] struct Args { @@ -65,69 +62,49 @@ fn main() -> anyhow::Result<()> { .init(); let args = Args::parse(); - let config = args - .config - .or(std::env::var_os("JELLYTHING_CONFIG").map(|p| PathBuf::from(p))) - .map(|path| { - Ok::<_, anyhow::Error>(serde_yaml::from_reader::<_, GlobalConfig>(File::open( - path, - )?)?) - }) - .transpose()?; - match args.action { - Action::Init { - base_path: path, - brand, - hostname, - } => { - info!("creating new instance..."); - std::fs::create_dir_all(path.join("library"))?; - std::fs::create_dir_all(path.join("cache"))?; - std::fs::create_dir_all(path.join("assets"))?; - std::fs::create_dir_all(path.join("media"))?; - File::create_new(path.join("assets/front.htm"))? - .write_fmt(format_args!("<h1>My very own jellything instance</h1>"))?; + Action::Init { .. } => { + // info!("creating new instance..."); + // std::fs::create_dir_all(path.join("library"))?; + // std::fs::create_dir_all(path.join("cache"))?; + // std::fs::create_dir_all(path.join("assets"))?; + // std::fs::create_dir_all(path.join("media"))?; + // File::create_new(path.join("assets/front.htm"))? + // .write_fmt(format_args!("<h1>My very own jellything instance</h1>"))?; + + // // TODO: dont fill that + // serde_yaml::to_writer( + // File::create_new(path.join("config.yaml"))?, + // &GlobalConfig { + // brand: brand.clone(), + // hostname, + // slogan: "Creative slogan here".to_string(), + // asset_path: path.join("assets"), + // cache_path: path.join("cache"), + // library_path: path.join("library"), + // database_path: path.join("database"), + // temp_path: "/tmp".into(), - // TODO: dont fill that - serde_yaml::to_writer( - File::create_new(path.join("config.yaml"))?, - &GlobalConfig { - brand: brand.clone(), - hostname, - slogan: "Creative slogan here".to_string(), - asset_path: path.join("assets"), - cache_path: path.join("cache"), - library_path: path.join("library"), - database_path: path.join("database"), - temp_path: "/tmp".into(), - cookie_key: Some( - base64::engine::general_purpose::STANDARD - .encode([(); 32].map(|_| random())), - ), - session_key: Some( - base64::engine::general_purpose::STANDARD - .encode([(); 32].map(|_| random())), - ), - login_expire: 10, - ..Default::default() - }, - )?; - serde_json::to_writer( - File::create_new(path.join("library/directory.json"))?, - &Node { - public: NodePublic { - kind: Some(NodeKind::Collection), - title: Some("My Library".to_string()), - ..Default::default() - }, - private: NodePrivate { - ..Default::default() - }, - }, - )?; - info!("{brand:?} is ready!"); - warn!("please add an admin password to login."); + // login_expire: 10, + // ..Default::default() + // }, + // )?; + // serde_json::to_writer( + // File::create_new(path.join("library/directory.json"))?, + // &Node { + // public: NodePublic { + // kind: Some(NodeKind::Collection), + // title: Some("My Library".to_string()), + // ..Default::default() + // }, + // private: NodePrivate { + // ..Default::default() + // }, + // }, + // )?; + // info!("{brand:?} is ready!"); + // warn!("please add an admin password to login."); + error!("init is currently disabled"); Ok(()) } a @ Action::Migrate { .. } => migrate(a), @@ -136,18 +113,19 @@ fn main() -> anyhow::Result<()> { .build() .unwrap() .block_on(async move { - let config = config.ok_or(anyhow!("this action requires the config"))?; - let inst = Instance::new(hostname.unwrap_or(config.hostname.clone()), !no_tls); + let inst = Instance::new(hostname.unwrap_or(CONF.hostname.clone()), !no_tls); info!("login"); let session = inst .login(CreateSessionParams { drop_permissions: None, expire: None, - password: config + password: SECRETS .admin_password + .clone() .ok_or(anyhow!("admin account required"))?, - username: config + username: CONF .admin_username + .clone() .ok_or(anyhow!("admin account required"))?, }) .await?; |