mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
feat(config): Added data path.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"db_path": "~/.envr/data.age",
|
||||
"keys": [
|
||||
{
|
||||
"private": "/home/spencer/.ssh/id_ed25519",
|
||||
"public": "/home/spencer/.ssh/id_ed25519.pub"
|
||||
"private": "~/.ssh/id_ed25519",
|
||||
"public": "~/.ssh/id_ed25519.pub"
|
||||
}
|
||||
],
|
||||
"scan": {
|
||||
@@ -17,4 +18,4 @@
|
||||
"~"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
db_path: []const u8 = "~/.envr/data.age",
|
||||
|
||||
/// Keys that are available for encryption
|
||||
keys: []const SSHKeyPair = &.{
|
||||
.from_pub_path("~/.ssh/id_ed25519.pub"),
|
||||
@@ -120,11 +122,7 @@ test "loading the default config from disk matches expected values" {
|
||||
test "saving to a new file upserts the file" {
|
||||
const io = std.testing.io;
|
||||
|
||||
var cfg: @This() = .{
|
||||
.keys = &.{
|
||||
.from_pub_path("~/.ssh/id_ed25519.pub"),
|
||||
},
|
||||
};
|
||||
var cfg: @This() = .{};
|
||||
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
@@ -148,6 +146,7 @@ test "saving to a new file upserts the file" {
|
||||
|
||||
const want =
|
||||
\\{
|
||||
\\ "db_path": "~/.envr/data.age",
|
||||
\\ "keys": [
|
||||
\\ {
|
||||
\\ "private": "~/.ssh/id_ed25519",
|
||||
@@ -175,11 +174,7 @@ test "saving to a new file upserts the file" {
|
||||
test "saving to an existing file updates the file" {
|
||||
const io = std.testing.io;
|
||||
|
||||
var cfg: @This() = .{
|
||||
.keys = &.{
|
||||
.from_pub_path("~/.ssh/id_ed25519.pub"),
|
||||
},
|
||||
};
|
||||
var cfg: @This() = .{};
|
||||
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
@@ -201,6 +196,7 @@ test "saving to an existing file updates the file" {
|
||||
|
||||
const want =
|
||||
\\{
|
||||
\\ "db_path": "~/.envr/data.age",
|
||||
\\ "keys": [
|
||||
\\ {
|
||||
\\ "private": "~/.ssh/id_ed25519",
|
||||
|
||||
@@ -23,8 +23,11 @@ pub fn open(
|
||||
gpa: std.mem.Allocator,
|
||||
opts: OpenOptions,
|
||||
) !@This() {
|
||||
// TODO: Read from config?
|
||||
const db_path = try std.fs.path.join(gpa, &.{ opts.home, ".envr", "data.age" });
|
||||
// FIXME: cheating here
|
||||
const db_path = try std.fs.path.join(gpa, &.{
|
||||
opts.home,
|
||||
opts.config.db_path[2..],
|
||||
});
|
||||
defer gpa.free(db_path);
|
||||
|
||||
var db = try new(opts.config);
|
||||
@@ -257,8 +260,10 @@ test "Closing a fresh database does not create a file" {
|
||||
const tmp = try std.fs.path.join(gpa, &.{ tmp_dir_path, "tmp" });
|
||||
defer gpa.free(tmp);
|
||||
|
||||
// TODO: Pass testing keys
|
||||
var db: @This() = try .open(io, gpa, .{ .home = home, .tmp = tmp });
|
||||
|
||||
// TODO: Get rid of direct access
|
||||
const db_path = try std.fs.path.join(gpa, &.{ home, ".envr", "data.age" });
|
||||
defer gpa.free(db_path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user