mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 12:31:02 +01:00
Fixes and additions: (#20)
- fix encryption bug #19, which was a regression - added encryption unit test - added debug logging here and there Co-authored-by: Thomas von Dein <tom@vondein.org>
This commit is contained in:
22
cmd/anydb.go
22
cmd/anydb.go
@@ -411,12 +411,16 @@ TEMPLATES
|
||||
|
||||
The following template variables can be used:
|
||||
|
||||
Key - string
|
||||
Value - string
|
||||
Bin - []byte
|
||||
Created - time.Time
|
||||
Tags - []string
|
||||
Encrypted bool
|
||||
.Key - string
|
||||
.Value - string
|
||||
.Bin - []byte
|
||||
.Created - timestamp.Time
|
||||
To retrieve a string representation of the timestamp, use
|
||||
".Created.AsTime". If you need a unix timestamp since epoch, use
|
||||
".Created.Unix".
|
||||
|
||||
.Tags - []string
|
||||
.Encrypted bool
|
||||
|
||||
Prepend a single dot (".") before each variable name.
|
||||
|
||||
@@ -428,12 +432,12 @@ TEMPLATES
|
||||
|
||||
Format the list in a way so that is possible to evaluate it in a shell:
|
||||
|
||||
eval $(anydb get foo -m template -T "key='{{ .Key }}' value='{{ .Value }}' ts='{{ .Created}}'")
|
||||
echo "Key: $key, Value: $value"
|
||||
eval $(anydb get foo -m template -T "key='{{ .Key }}' value='{{ .Value }}' ts='{{ .Created.AsTime}}'")
|
||||
echo "Key: $key, Value: $value, When: $ts"
|
||||
|
||||
Print the values in CSV format ONLY if they have some tag:
|
||||
|
||||
anydb list -m template -T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created}}{{ end }}"
|
||||
anydb list -m template -T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created.AsTime}}{{ end }}"
|
||||
|
||||
CONFIGURATION
|
||||
Anydb looks at the following locations for a configuration file, in that
|
||||
|
||||
@@ -124,6 +124,7 @@ func Get(conf *cfg.Config) *cobra.Command {
|
||||
}
|
||||
|
||||
entry.Value = string(clear)
|
||||
entry.Size = uint64(len(entry.Value))
|
||||
entry.Encrypted = false
|
||||
}
|
||||
|
||||
|
||||
39
cmd/root.go
39
cmd/root.go
@@ -19,13 +19,15 @@ package cmd
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tlinden/anydb/app"
|
||||
"github.com/tlinden/anydb/cfg"
|
||||
"github.com/tlinden/yadu"
|
||||
)
|
||||
|
||||
func completion(cmd *cobra.Command, mode string) error {
|
||||
@@ -67,14 +69,6 @@ func Execute() {
|
||||
Short: "anydb",
|
||||
Long: `A personal key value store`,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
dbfile := app.GetDbFile(conf.Dbfile)
|
||||
|
||||
db, err := app.New(dbfile, conf.Dbbucket, conf.Debug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.DB = db
|
||||
|
||||
var configs []string
|
||||
if configfile != "" {
|
||||
@@ -88,9 +82,34 @@ func Execute() {
|
||||
}
|
||||
|
||||
if conf.Debug {
|
||||
repr.Println(conf)
|
||||
buildInfo, _ := debug.ReadBuildInfo()
|
||||
opts := &yadu.Options{
|
||||
Level: slog.LevelDebug,
|
||||
AddSource: true,
|
||||
}
|
||||
|
||||
slog.SetLogLoggerLevel(slog.LevelDebug)
|
||||
|
||||
handler := yadu.NewHandler(os.Stdout, opts)
|
||||
debuglogger := slog.New(handler).With(
|
||||
slog.Group("program_info",
|
||||
slog.Int("pid", os.Getpid()),
|
||||
slog.String("go_version", buildInfo.GoVersion),
|
||||
),
|
||||
)
|
||||
slog.SetDefault(debuglogger)
|
||||
|
||||
slog.Debug("parsed config", "conf", conf)
|
||||
}
|
||||
|
||||
dbfile := app.GetDbFile(conf.Dbfile)
|
||||
|
||||
db, err := app.New(dbfile, conf.Dbbucket, conf.Debug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.DB = db
|
||||
return nil
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user