Skip to content

Commit

Permalink
Fix secret creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Lloyd committed Jan 22, 2024
1 parent 7a058c1 commit 27f3298
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
13 changes: 4 additions & 9 deletions src/command/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ pub async fn handle_create(
) -> Result<()> {
let app = App::new(config_dir, true).await?;

let mut value = String::new();
std::io::stdin().read_to_string(&mut value).unwrap();

if value.is_empty() {
let value_from_editor = edit_text(b"", Some(&name))?;
value = std::str::from_utf8(&value_from_editor)?.to_string();
if value.is_empty() {
bail!("Canceled")
}
let value_bytes = edit_text(b"", Some(&name))?;
if value_bytes.is_empty() {
bail!("Canceled")
}
let value = std::str::from_utf8(&value_bytes)?.to_string();

let sec = ClearSecret::new(&name, &value, description);
let encrypted = sec.to_encrypted(&app.master_key)?;
Expand Down
15 changes: 10 additions & 5 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
use std::path::{Path, PathBuf};
use std::{
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
};

use anyhow::{bail, Result};
use sqlx::{migrate::MigrateDatabase, sqlite::SqlitePool, Sqlite};

pub async fn init(config_dir: &Path) -> Result<SqlitePool> {
let db_url = db_url(config_dir)?;
let db_path = db_path(config_dir);

println!("Creating database {}", db_path.to_string_lossy());

println!(
"Creating database {}",
db_path(config_dir).to_string_lossy()
);
match Sqlite::create_database(&db_url).await {
Ok(_) => println!("Create db success"),
Err(error) => bail!("error: {}", error),
}

let perms = std::fs::Permissions::from_mode(0o600);
std::fs::set_permissions(db_path, perms)?;

let db = connect(config_dir).await?;
sqlx::migrate!().run(&db).await?;
Ok(db)
Expand Down

0 comments on commit 27f3298

Please sign in to comment.