change location of dev db and bump version

This commit is contained in:
Joseph Montanaro 2023-05-06 21:59:24 -07:00
parent 94400ba7d5
commit e866a4a643
9 changed files with 30 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "creddy", "name": "creddy",
"version": "0.1.0", "version": "0.2.0",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",

View File

@ -1 +1 @@
DATABASE_URL=sqlite://creddy.db?mode=rwc DATABASE_URL=sqlite://C:/Users/Joe/AppData/Roaming/creddy/creddy.dev.db

15
src-tauri/Cargo.lock generated
View File

@ -60,7 +60,7 @@ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]] [[package]]
name = "app" name = "app"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"auto-launch", "auto-launch",
"aws-config", "aws-config",
@ -69,6 +69,7 @@ dependencies = [
"aws-types", "aws-types",
"clap", "clap",
"dirs 5.0.1", "dirs 5.0.1",
"is-terminal",
"netstat2", "netstat2",
"once_cell", "once_cell",
"serde", "serde",
@ -2015,6 +2016,18 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "is-terminal"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.5" version = "0.10.5"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "app" name = "app"
version = "0.1.0" version = "0.2.0"
description = "A Tauri App" description = "A Tauri App"
authors = ["you"] authors = ["you"]
license = "" license = ""
@ -35,6 +35,7 @@ strum_macros = "0.24"
auto-launch = "0.4.0" auto-launch = "0.4.0"
dirs = "5.0" dirs = "5.0"
clap = { version = "3.2.23", features = ["derive"] } clap = { version = "3.2.23", features = ["derive"] }
is-terminal = "0.4.7"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode

View File

@ -66,6 +66,7 @@ pub async fn connect_db() -> Result<SqlitePool, SetupError> {
.create_if_missing(true); .create_if_missing(true);
let pool_opts = SqlitePoolOptions::new(); let pool_opts = SqlitePoolOptions::new();
let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?; let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?;
sqlx::migrate!().run(&pool).await?;
Ok(pool) Ok(pool)
} }
@ -74,8 +75,6 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
APP.set(app.handle()).unwrap(); APP.set(app.handle()).unwrap();
let pool = connect_db().await?; let pool = connect_db().await?;
sqlx::migrate!().run(&pool).await?;
let conf = AppConfig::load(&pool).await?; let conf = AppConfig::load(&pool).await?;
let session = Session::load(&pool).await?; let session = Session::load(&pool).await?;
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?; let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;

View File

@ -2,6 +2,7 @@ use std::net::Ipv4Addr;
use std::path::PathBuf; use std::path::PathBuf;
use auto_launch::AutoLaunchBuilder; use auto_launch::AutoLaunchBuilder;
use is_terminal::IsTerminal;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use sqlx::SqlitePool; use sqlx::SqlitePool;
@ -90,16 +91,17 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> { pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
// debug_assertions doesn't always mean we are running in dev
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
return Ok(PathBuf::from("./creddy.db"));
}
let mut path = dirs::data_dir() let mut path = dirs::data_dir()
.ok_or(DataDirError::NotFound)?; .ok_or(DataDirError::NotFound)?;
path.push("Creddy");
std::fs::create_dir_all(&path)?; std::fs::create_dir_all(&path)?;
path.push("creddy.db"); if cfg!(debug_assertions) && std::io::stdout().is_terminal() {
path.push("creddy.dev.db");
}
else {
path.push("creddy.db");
}
Ok(path) Ok(path)
} }

View File

@ -59,16 +59,7 @@ impl Handler {
return Ok(()) return Ok(())
} }
let base = req_path == b"/creddy/base-credentials"; let base = req_path == b"/creddy/base-credentials";
if base {
if clients.len() != 1
|| clients[0].is_none()
|| clients[0].as_ref().unwrap().exe != std::env::current_exe()?
{
self.stream.write(b"HTTP/1.0 403 Access Denied\r\n\r\n").await?;
return Ok(())
}
}
let req = Request {id: self.request_id, clients, base}; let req = Request {id: self.request_id, clients, base};
self.app.emit_all("credentials-request", &req)?; self.app.emit_all("credentials-request", &req)?;
let starting_visibility = self.show_window()?; let starting_visibility = self.show_window()?;

View File

@ -8,7 +8,7 @@
}, },
"package": { "package": {
"productName": "creddy", "productName": "creddy",
"version": "0.1.0" "version": "0.2.0"
}, },
"tauri": { "tauri": {
"allowlist": { "allowlist": {

View File

@ -86,7 +86,7 @@
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg> <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
<span> <span>
WARNING: This application is requesting your base (long-lived) AWS credentials. WARNING: This application is requesting your base (long-lived) AWS credentials.
These crednetials are less secure than session credentials, since they don't expire automatically. These credentials are less secure than session credentials, since they don't expire automatically.
</span> </span>
</div> </div>
</div> </div>