first compiling version

This commit is contained in:
ston1th 2023-03-15 01:51:45 +01:00
commit 3d54199faa
27 changed files with 908 additions and 243 deletions

View file

@ -7,7 +7,6 @@ import (
"path/filepath"
"git.giftfish.de/ston1th/godrop/v2"
"git.giftfish.de/ston1th/keyctl/pkg/core"
"git.giftfish.de/ston1th/keyctl/pkg/store"
"github.com/go-logr/logr"
)
@ -19,9 +18,9 @@ type DB struct {
store store.Store
}
func NewPlain(log logr.Logger, cfg *core.Config) (db *DB, err error) {
func NewPlain(log logr.Logger, dir string) (db *DB, err error) {
db = &DB{log: log}
dbFile := filepath.Join(cfg.DataDir, storeFile)
dbFile := filepath.Join(dir, storeFile)
err = godrop.Unveil(dbFile, "rwc")
if err != nil {
return
@ -30,8 +29,8 @@ func NewPlain(log logr.Logger, cfg *core.Config) (db *DB, err error) {
return
}
func New(log logr.Logger, cfg *core.Config) (db *DB, err error) {
db, err = NewPlain(log, cfg)
func New(log logr.Logger, dir string) (db *DB, err error) {
db, err = NewPlain(log, dir)
if err != nil {
return
}

View file

@ -3,9 +3,7 @@
package db
import (
"sort"
"git.giftfish.de/ston1th/goacc/pkg/core"
"git.giftfish.de/ston1th/keyctl/pkg/core"
"git.giftfish.de/ston1th/keyctl/pkg/key"
)
@ -13,13 +11,12 @@ const keyPrefix = "key/"
func (db *DB) GetKeys() (keys core.Keys, err error) {
err = db.store.ForEachPrefix(keyPrefix, func(k string, _ []byte) error {
k, err := db.GetKey(k)
key, err := db.GetKey(k)
if err == nil {
keys = append(keys, k)
keys = append(keys, key)
}
return nil
})
sort.Sort(keys)
return
}

View file

@ -1,4 +1,4 @@
// Copyright (C) 2022 Marius Schellenberger
// Copyright (C) 2023 Marius Schellenberger
package db