mirror of
https://github.com/sbrow/envr.git
synced 2025-12-29 23:47:39 -05:00
feat: Added age support.
This commit is contained in:
36
envr
36
envr
@@ -34,29 +34,51 @@ def "main import" [
|
|||||||
$"file '($file)' imported successfull!"
|
$"file '($file)' imported successfull!"
|
||||||
}
|
}
|
||||||
|
|
||||||
const db_path = '/home/spencer/.envr/data.db'
|
const db_path = '/home/spencer/.envr/data.age'
|
||||||
|
|
||||||
# Create or load the database
|
# Create or load the database
|
||||||
def "open db" [] {
|
def "open db" [] {
|
||||||
if (not ($db_path | path exists)) {
|
if (not ($db_path | path exists)) {
|
||||||
init-db
|
create-db
|
||||||
|
} else {
|
||||||
|
# Open the db
|
||||||
|
let dec = mktemp -p ~/.envr;
|
||||||
|
age -d -i ((main config show).priv_key | path expand) $db_path | save -f $dec
|
||||||
|
stor import -f $dec
|
||||||
|
rm $dec
|
||||||
}
|
}
|
||||||
stor import -f $db_path
|
|
||||||
|
stor open
|
||||||
}
|
}
|
||||||
|
|
||||||
def "init-db" []: nothing -> table {
|
def "create-db" []: nothing -> any {
|
||||||
sqlite3 $db_path 'create table envr_env_files (
|
let dec = mktemp -p ~/.envr;
|
||||||
|
|
||||||
|
sqlite3 $dec 'create table envr_env_files (
|
||||||
path text primary key not null
|
path text primary key not null
|
||||||
, dir text not null
|
, dir text not null
|
||||||
, remotes text -- JSON
|
, remotes text -- JSON
|
||||||
, sha256 text not null
|
, sha256 text not null
|
||||||
, contents text not null
|
, contents text not null
|
||||||
);'
|
);'
|
||||||
|
|
||||||
|
let pub_key = ((main config show).pub_key | path expand);
|
||||||
|
age -R $pub_key $dec | save -f $db_path
|
||||||
|
|
||||||
|
stor import -f $dec
|
||||||
|
rm $dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
def "close db" [] {
|
def "close db" [] {
|
||||||
stor export --file-name $'($db_path).new'
|
let dec = mktemp -p ~/.envr;
|
||||||
mv $'($db_path).new' $db_path
|
|
||||||
|
stor export --file-name $dec;
|
||||||
|
|
||||||
|
# Encrypt the file
|
||||||
|
let pub_key = ((main config show).pub_key | path expand);
|
||||||
|
age -R $pub_key $dec | save -f $db_path
|
||||||
|
|
||||||
|
rm $dec
|
||||||
}
|
}
|
||||||
|
|
||||||
# Supported config formats
|
# Supported config formats
|
||||||
|
|||||||
Reference in New Issue
Block a user