mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 12:31:02 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83de01b349 | |||
| b4cf1e4d1c | |||
| 42dc598deb | |||
| ff169a7198 | |||
|
|
6c4f119bfa | ||
| 16b6075329 | |||
| 07808187d5 | |||
|
|
bc1b08d6f9 | ||
|
|
bd5c1e3abb | ||
|
|
57026e11aa | ||
|
|
d0fb560bb2 | ||
|
|
f2bc21e03a |
15
.github/workflows/ci.yaml
vendored
15
.github/workflows/ci.yaml
vendored
@@ -1,10 +1,19 @@
|
|||||||
name: build-and-test
|
name: build-and-test
|
||||||
on: [push, pull_request]
|
|
||||||
|
#on: [push, pull_request]
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: [1.21,'1.22']
|
version: ['1.23']
|
||||||
os: [ubuntu-latest, macos-latest]
|
os: [ubuntu-latest, macos-latest]
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -41,7 +50,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.21
|
go-version: 1.23
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
|||||||
4
.github/workflows/pushimage.yaml
vendored
4
.github/workflows/pushimage.yaml
vendored
@@ -22,13 +22,13 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
|
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: ghcr.io/tlinden/anydb:${{ github.ref_name}}
|
tags: ghcr.io/tlinden/anydb:${{ github.ref_name}}
|
||||||
|
|
||||||
- name: Build and push latest Docker image
|
- name: Build and push latest Docker image
|
||||||
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
|
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: ghcr.io/tlinden/anydb:latest
|
tags: ghcr.io/tlinden/anydb:latest
|
||||||
|
|||||||
65
.github/workflows/release.yaml
vendored
65
.github/workflows/release.yaml
vendored
@@ -1,8 +1,8 @@
|
|||||||
name: build-and-test
|
name: build-release
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "*"
|
- "v*.*.*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
@@ -10,12 +10,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.22.11
|
go-version: 1.23.5
|
||||||
|
|
||||||
- name: Build the executables
|
- name: Build the executables
|
||||||
run: ./mkrel.sh anydb ${{ github.ref_name}}
|
run: ./mkrel.sh anydb ${{ github.ref_name}}
|
||||||
@@ -30,3 +30,58 @@ jobs:
|
|||||||
tag: ${{ github.ref_name }}
|
tag: ${{ github.ref_name }}
|
||||||
file: ./releases/*
|
file: ./releases/*
|
||||||
file_glob: true
|
file_glob: true
|
||||||
|
|
||||||
|
- name: Build Changelog
|
||||||
|
id: github_release
|
||||||
|
uses: mikepenz/release-changelog-builder-action@v5
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
mode: "PR"
|
||||||
|
configurationJson: |
|
||||||
|
{
|
||||||
|
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
|
||||||
|
"pr_template": "- #{{TITLE}} (##{{NUMBER}}) by #{{AUTHOR}}\n#{{BODY}}",
|
||||||
|
"empty_template": "- no changes",
|
||||||
|
"categories": [
|
||||||
|
{
|
||||||
|
"title": "## New Features",
|
||||||
|
"labels": ["add", "feature"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Bug Fixes",
|
||||||
|
"labels": ["fix", "bug", "revert"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Documentation Enhancements",
|
||||||
|
"labels": ["doc"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Refactoring Efforts",
|
||||||
|
"labels": ["refactor"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Miscellaneus Changes",
|
||||||
|
"labels": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ignore_labels": [
|
||||||
|
"duplicate", "good first issue", "help wanted", "invalid", "question", "wontfix"
|
||||||
|
],
|
||||||
|
"label_extractor": [
|
||||||
|
{
|
||||||
|
"pattern": "(.) (.+)",
|
||||||
|
"target": "$1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern": "(.) (.+)",
|
||||||
|
"target": "$1",
|
||||||
|
"on_property": "title"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
body: ${{steps.github_release.outputs.changelog}}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
FROM golang:1.22-alpine as builder
|
FROM golang:1.23-alpine as builder
|
||||||
|
|
||||||
RUN apk update
|
RUN apk update
|
||||||
RUN apk upgrade
|
RUN apk upgrade
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
[](https://github.com/TLINDEN/anydb/releases/latest)
|
[](https://github.com/TLINDEN/anydb/releases/latest)
|
||||||
[](https://github.com/TLINDEN/anydb/blob/master/anydb.pod)
|
[](https://github.com/TLINDEN/anydb/blob/master/anydb.pod)
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> Version 0.1.3 introduced a [regression bug](https://github.com/TLINDEN/anydb/issues/19),
|
||||||
|
> which caused the encryption feature not to work correctly anymore.
|
||||||
|
> If you are using anydb 0.1.3, you are urgently advised to
|
||||||
|
> upgrade to 0.2.0
|
||||||
|
|
||||||
Anydb is a simple to use commandline tool to store anything you'd
|
Anydb is a simple to use commandline tool to store anything you'd
|
||||||
like, even binary files etc. It is a re-implementation of
|
like, even binary files etc. It is a re-implementation of
|
||||||
[skate](https://github.com/charmbracelet/skate) for the following
|
[skate](https://github.com/charmbracelet/skate) for the following
|
||||||
|
|||||||
36
anydb.1
36
anydb.1
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "ANYDB 1"
|
.IX Title "ANYDB 1"
|
||||||
.TH ANYDB 1 "2025-01-01" "1" "User Commands"
|
.TH ANYDB 1 "2025-02-10" "1" "User Commands"
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -608,19 +608,23 @@ required, the template provided applies to every matching entry
|
|||||||
separatley.
|
separatley.
|
||||||
.PP
|
.PP
|
||||||
The following template variables can be used:
|
The following template variables can be used:
|
||||||
.IP "\fBKey\fR \- string" 4
|
.IP "\fB.Key\fR \- string" 4
|
||||||
.IX Item "Key - string"
|
.IX Item ".Key - string"
|
||||||
.PD 0
|
.PD 0
|
||||||
.IP "\fBValue\fR \- string" 4
|
.IP "\fB.Value\fR \- string" 4
|
||||||
.IX Item "Value - string"
|
.IX Item ".Value - string"
|
||||||
.IP "\fBBin\fR \- []byte" 4
|
.IP "\fB.Bin\fR \- []byte" 4
|
||||||
.IX Item "Bin - []byte"
|
.IX Item ".Bin - []byte"
|
||||||
.IP "\fBCreated\fR \- time.Time" 4
|
.IP "\fB.Created\fR \- timestamp.Time" 4
|
||||||
.IX Item "Created - time.Time"
|
.IX Item ".Created - timestamp.Time"
|
||||||
.IP "\fBTags\fR \- []string" 4
|
.PD
|
||||||
.IX Item "Tags - []string"
|
To retrieve a string representation of the timestamp, use \f(CW\*(C`.Created.AsTime\*(C'\fR.
|
||||||
.IP "\fBEncrypted\fR bool" 4
|
If you need a unix timestamp since epoch, use \f(CW\*(C`.Created.Unix\*(C'\fR.
|
||||||
.IX Item "Encrypted bool"
|
.IP "\fB.Tags\fR \- []string" 4
|
||||||
|
.IX Item ".Tags - []string"
|
||||||
|
.PD 0
|
||||||
|
.IP "\fB.Encrypted\fR bool" 4
|
||||||
|
.IX Item ".Encrypted bool"
|
||||||
.PD
|
.PD
|
||||||
.PP
|
.PP
|
||||||
Prepend a single dot (\*(L".\*(R") before each variable name.
|
Prepend a single dot (\*(L".\*(R") before each variable name.
|
||||||
@@ -637,14 +641,14 @@ Format the list in a way so that is possible to evaluate it in a
|
|||||||
shell:
|
shell:
|
||||||
.PP
|
.PP
|
||||||
.Vb 2
|
.Vb 2
|
||||||
\& eval $(anydb get foo \-m template \-T "key=\*(Aq{{ .Key }}\*(Aq value=\*(Aq{{ .Value }}\*(Aq ts=\*(Aq{{ .Created}}\*(Aq")
|
\& eval $(anydb get foo \-m template \-T "key=\*(Aq{{ .Key }}\*(Aq value=\*(Aq{{ .Value }}\*(Aq ts=\*(Aq{{ .Created.AsTime}}\*(Aq")
|
||||||
\& echo "Key: $key, Value: $value"
|
\& echo "Key: $key, Value: $value, When: $ts"
|
||||||
.Ve
|
.Ve
|
||||||
.PP
|
.PP
|
||||||
Print the values in \s-1CSV\s0 format \s-1ONLY\s0 if they have some tag:
|
Print the values in \s-1CSV\s0 format \s-1ONLY\s0 if they have some tag:
|
||||||
.PP
|
.PP
|
||||||
.Vb 1
|
.Vb 1
|
||||||
\& anydb list \-m template \-T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created}}{{ end }}"
|
\& anydb list \-m template \-T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created.AsTime}}{{ end }}"
|
||||||
.Ve
|
.Ve
|
||||||
.SH "CONFIGURATION"
|
.SH "CONFIGURATION"
|
||||||
.IX Header "CONFIGURATION"
|
.IX Header "CONFIGURATION"
|
||||||
|
|||||||
21
anydb.pod
21
anydb.pod
@@ -448,17 +448,20 @@ The following template variables can be used:
|
|||||||
|
|
||||||
=over
|
=over
|
||||||
|
|
||||||
=item B<Key> - string
|
=item B<.Key> - string
|
||||||
|
|
||||||
=item B<Value> - string
|
=item B<.Value> - string
|
||||||
|
|
||||||
=item B<Bin> - []byte
|
=item B<.Bin> - []byte
|
||||||
|
|
||||||
=item B<Created> - time.Time
|
=item B<.Created> - timestamp.Time
|
||||||
|
|
||||||
=item B<Tags> - []string
|
To retrieve a string representation of the timestamp, use C<.Created.AsTime>.
|
||||||
|
If you need a unix timestamp since epoch, use C<.Created.Unix>.
|
||||||
|
|
||||||
=item B<Encrypted> bool
|
=item B<.Tags> - []string
|
||||||
|
|
||||||
|
=item B<.Encrypted> bool
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
@@ -473,12 +476,12 @@ Only show the keys of all entries:
|
|||||||
Format the list in a way so that is possible to evaluate it in a
|
Format the list in a way so that is possible to evaluate it in a
|
||||||
shell:
|
shell:
|
||||||
|
|
||||||
eval $(anydb get foo -m template -T "key='{{ .Key }}' value='{{ .Value }}' ts='{{ .Created}}'")
|
eval $(anydb get foo -m template -T "key='{{ .Key }}' value='{{ .Value }}' ts='{{ .Created.AsTime}}'")
|
||||||
echo "Key: $key, Value: $value"
|
echo "Key: $key, Value: $value, When: $ts"
|
||||||
|
|
||||||
Print the values in CSV format ONLY if they have some tag:
|
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 }}"
|
||||||
|
|
||||||
|
|
||||||
=head1 CONFIGURATION
|
=head1 CONFIGURATION
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ const (
|
|||||||
ArgonParallel uint8 = 2
|
ArgonParallel uint8 = 2
|
||||||
ArgonSaltLen int = 16
|
ArgonSaltLen int = 16
|
||||||
ArgonKeyLen uint32 = 32
|
ArgonKeyLen uint32 = 32
|
||||||
B64SaltLen int = 22
|
B64SaltLen int = 16 //22
|
||||||
)
|
)
|
||||||
|
|
||||||
type Key struct {
|
type Key struct {
|
||||||
@@ -84,7 +85,11 @@ func DeriveKey(password []byte, salt []byte) (*Key, error) {
|
|||||||
ArgonKeyLen,
|
ArgonKeyLen,
|
||||||
)
|
)
|
||||||
|
|
||||||
return &Key{Key: hash, Salt: salt}, nil
|
key := &Key{Key: hash, Salt: salt}
|
||||||
|
|
||||||
|
slog.Debug("derived key", "key", string(key.Key), "salt", string(key.Salt))
|
||||||
|
|
||||||
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a random chunk of given size
|
// Retrieve a random chunk of given size
|
||||||
@@ -124,10 +129,13 @@ func Encrypt(pass []byte, attr *DbAttr) error {
|
|||||||
|
|
||||||
cipher := aead.Seal(nonce, nonce, attr.Val, nil)
|
cipher := aead.Seal(nonce, nonce, attr.Val, nil)
|
||||||
|
|
||||||
attr.Val = append(attr.Val, key.Salt...)
|
attr.Val = key.Salt
|
||||||
attr.Val = append(attr.Val, cipher...)
|
attr.Val = append(attr.Val, cipher...)
|
||||||
|
|
||||||
attr.Encrypted = true
|
attr.Encrypted = true
|
||||||
|
attr.Preview = "<encrypted-content>"
|
||||||
|
|
||||||
|
slog.Debug("encrypted attr", "salt", string(key.Salt), "cipher", string(attr.Val))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -156,5 +164,12 @@ func Decrypt(pass []byte, cipherb []byte) ([]byte, error) {
|
|||||||
|
|
||||||
nonce, ciphertext := cipher[:aead.NonceSize()], cipher[aead.NonceSize():]
|
nonce, ciphertext := cipher[:aead.NonceSize()], cipher[aead.NonceSize():]
|
||||||
|
|
||||||
return aead.Open(nil, nonce, ciphertext, nil)
|
clear, err := aead.Open(nil, nonce, ciphertext, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Debug("decrypted attr", "salt", string(key.Salt), "clear", string(clear))
|
||||||
|
|
||||||
|
return clear, err
|
||||||
}
|
}
|
||||||
|
|||||||
20
app/db.go
20
app/db.go
@@ -20,6 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -84,6 +85,8 @@ func New(file string, bucket string, debug bool) (*DB, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Open() error {
|
func (db *DB) Open() error {
|
||||||
|
slog.Debug("opening DB", "dbfile", db.Dbfile)
|
||||||
|
|
||||||
if _, err := os.Stat(filepath.Dir(db.Dbfile)); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Dir(db.Dbfile)); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(filepath.Dir(db.Dbfile), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(db.Dbfile), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -128,11 +131,15 @@ func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened root bucket", "root", root)
|
||||||
|
|
||||||
bucket := root.Bucket([]byte("meta"))
|
bucket := root.Bucket([]byte("meta"))
|
||||||
if bucket == nil {
|
if bucket == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
databucket := root.Bucket([]byte("data"))
|
databucket := root.Bucket([]byte("data"))
|
||||||
if databucket == nil {
|
if databucket == nil {
|
||||||
return fmt.Errorf("failed to retrieve data sub bucket")
|
return fmt.Errorf("failed to retrieve data sub bucket")
|
||||||
@@ -215,6 +222,7 @@ func (db *DB) Set(attr *DbAttr) error {
|
|||||||
// check if the entry already exists and if yes, check if it has
|
// check if the entry already exists and if yes, check if it has
|
||||||
// any tags. if so, we initialize our update struct with these
|
// any tags. if so, we initialize our update struct with these
|
||||||
// tags unless it has new tags configured.
|
// tags unless it has new tags configured.
|
||||||
|
// FIXME: use Get()
|
||||||
err := db.DB.View(func(tx *bolt.Tx) error {
|
err := db.DB.View(func(tx *bolt.Tx) error {
|
||||||
root := tx.Bucket([]byte(db.Bucket))
|
root := tx.Bucket([]byte(db.Bucket))
|
||||||
if root == nil {
|
if root == nil {
|
||||||
@@ -226,6 +234,8 @@ func (db *DB) Set(attr *DbAttr) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
pbentry := bucket.Get([]byte(entry.Key))
|
pbentry := bucket.Get([]byte(entry.Key))
|
||||||
if pbentry == nil {
|
if pbentry == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -267,6 +277,8 @@ func (db *DB) Set(attr *DbAttr) error {
|
|||||||
return fmt.Errorf("failed to create DB meta sub bucket: %w", err)
|
return fmt.Errorf("failed to create DB meta sub bucket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened/created buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
// write meta data
|
// write meta data
|
||||||
err = bucket.Put([]byte(entry.Key), []byte(pbentry))
|
err = bucket.Put([]byte(entry.Key), []byte(pbentry))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -316,6 +328,8 @@ func (db *DB) Get(attr *DbAttr) (*DbEntry, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
// retrieve meta data
|
// retrieve meta data
|
||||||
pbentry := bucket.Get([]byte(attr.Key))
|
pbentry := bucket.Get([]byte(attr.Key))
|
||||||
if pbentry == nil {
|
if pbentry == nil {
|
||||||
@@ -369,6 +383,8 @@ func (db *DB) Del(attr *DbAttr) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "data", bucket)
|
||||||
|
|
||||||
return bucket.Delete([]byte(attr.Key))
|
return bucket.Delete([]byte(attr.Key))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -421,6 +437,8 @@ func (db *DB) Import(attr *DbAttr) (string, error) {
|
|||||||
return fmt.Errorf("failed to create DB meta sub bucket: %w", err)
|
return fmt.Errorf("failed to create DB meta sub bucket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
pbentry, err := proto.Marshal(entry)
|
pbentry, err := proto.Marshal(entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -528,6 +546,8 @@ func (db *DB) Getall(attr *DbAttr) (DbEntries, error) {
|
|||||||
return fmt.Errorf("failed to retrieve data sub bucket")
|
return fmt.Errorf("failed to retrieve data sub bucket")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("opened buckets", "root", root, "data", bucket)
|
||||||
|
|
||||||
// iterate over all db entries in meta sub bucket
|
// iterate over all db entries in meta sub bucket
|
||||||
err := bucket.ForEach(func(key, pbentry []byte) error {
|
err := bucket.ForEach(func(key, pbentry []byte) error {
|
||||||
var entry DbEntry
|
var entry DbEntry
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
"github.com/tlinden/anydb/common"
|
"github.com/tlinden/anydb/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string = "v0.1.3"
|
var Version string = "v0.2.0"
|
||||||
|
|
||||||
type BucketConfig struct {
|
type BucketConfig struct {
|
||||||
Encrypt bool
|
Encrypt bool
|
||||||
|
|||||||
22
cmd/anydb.go
22
cmd/anydb.go
@@ -411,12 +411,16 @@ TEMPLATES
|
|||||||
|
|
||||||
The following template variables can be used:
|
The following template variables can be used:
|
||||||
|
|
||||||
Key - string
|
.Key - string
|
||||||
Value - string
|
.Value - string
|
||||||
Bin - []byte
|
.Bin - []byte
|
||||||
Created - time.Time
|
.Created - timestamp.Time
|
||||||
Tags - []string
|
To retrieve a string representation of the timestamp, use
|
||||||
Encrypted bool
|
".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.
|
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:
|
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}}'")
|
eval $(anydb get foo -m template -T "key='{{ .Key }}' value='{{ .Value }}' ts='{{ .Created.AsTime}}'")
|
||||||
echo "Key: $key, Value: $value"
|
echo "Key: $key, Value: $value, When: $ts"
|
||||||
|
|
||||||
Print the values in CSV format ONLY if they have some tag:
|
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
|
CONFIGURATION
|
||||||
Anydb looks at the following locations for a configuration file, in that
|
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.Value = string(clear)
|
||||||
|
entry.Size = uint64(len(entry.Value))
|
||||||
entry.Encrypted = false
|
entry.Encrypted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
cmd/root.go
39
cmd/root.go
@@ -19,13 +19,15 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/alecthomas/repr"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/tlinden/anydb/app"
|
"github.com/tlinden/anydb/app"
|
||||||
"github.com/tlinden/anydb/cfg"
|
"github.com/tlinden/anydb/cfg"
|
||||||
|
"github.com/tlinden/yadu"
|
||||||
)
|
)
|
||||||
|
|
||||||
func completion(cmd *cobra.Command, mode string) error {
|
func completion(cmd *cobra.Command, mode string) error {
|
||||||
@@ -67,14 +69,6 @@ func Execute() {
|
|||||||
Short: "anydb",
|
Short: "anydb",
|
||||||
Long: `A personal key value store`,
|
Long: `A personal key value store`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
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
|
var configs []string
|
||||||
if configfile != "" {
|
if configfile != "" {
|
||||||
@@ -88,9 +82,34 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if conf.Debug {
|
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
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -139,8 +139,9 @@ Type "# using template output mode you can freely design how to print stuff"
|
|||||||
Enter
|
Enter
|
||||||
Type "# here, we print the values in CSV format ONLY if they have some tag"
|
Type "# here, we print the values in CSV format ONLY if they have some tag"
|
||||||
Enter
|
Enter
|
||||||
|
Type "# also note, that we're printing the creation timestamp as epoch"
|
||||||
Sleep 1s
|
Sleep 1s
|
||||||
Type `anydb ls -m template -T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created}}{{ end }}"`
|
Type `anydb ls -m template -T "{{ if .Tags }}{{ .Key }},{{ .Value }},{{ .Created.AsTime.Unix}}{{ end }}"`
|
||||||
Enter
|
Enter
|
||||||
Sleep 3s
|
Sleep 3s
|
||||||
|
|
||||||
|
|||||||
11
go.mod
11
go.mod
@@ -1,6 +1,8 @@
|
|||||||
module github.com/tlinden/anydb
|
module github.com/tlinden/anydb
|
||||||
|
|
||||||
go 1.22.1
|
go 1.23
|
||||||
|
|
||||||
|
toolchain go1.23.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/repr v0.4.0
|
github.com/alecthomas/repr v0.4.0
|
||||||
@@ -11,14 +13,15 @@ require (
|
|||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
github.com/rogpeppe/go-internal v1.13.1
|
github.com/rogpeppe/go-internal v1.13.1
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
go.etcd.io/bbolt v1.3.11
|
go.etcd.io/bbolt v1.4.0
|
||||||
golang.org/x/crypto v0.31.0
|
golang.org/x/crypto v0.31.0
|
||||||
golang.org/x/term v0.27.0
|
golang.org/x/term v0.27.0
|
||||||
google.golang.org/protobuf v1.36.4
|
google.golang.org/protobuf v1.36.5
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||||
|
github.com/fatih/color v1.16.0 // indirect
|
||||||
github.com/gofiber/fiber/v3 v3.0.0-beta.3 // indirect
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3 // indirect
|
||||||
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
|
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
@@ -28,9 +31,11 @@ require (
|
|||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.6 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
|
github.com/tlinden/yadu v0.1.3 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.55.0 // indirect
|
github.com/valyala/fasthttp v1.55.0 // indirect
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.29.0 // indirect
|
golang.org/x/sys v0.29.0 // indirect
|
||||||
golang.org/x/tools v0.22.0 // indirect
|
golang.org/x/tools v0.22.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
9
go.sum
9
go.sum
@@ -14,6 +14,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
|
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||||
|
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||||
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
|
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
|
||||||
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||||
github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=
|
github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=
|
||||||
@@ -70,6 +72,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
|
|||||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/tlinden/yadu v0.1.3 h1:5cRCUmj+l5yvlM2irtpFBIJwVV2DPEgYSaWvF19FtcY=
|
||||||
|
github.com/tlinden/yadu v0.1.3/go.mod h1:l3bRmHKL9zGAR6pnBHY2HRPxBecf7L74BoBgOOpTcUA=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
||||||
@@ -83,6 +87,8 @@ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3i
|
|||||||
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||||
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
|
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
|
||||||
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
|
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
|
||||||
|
go.etcd.io/bbolt v1.4.0 h1:TU77id3TnN/zKr7CO/uk+fBCwF2jGcMuw2B/FMAzYIk=
|
||||||
|
go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||||
@@ -108,6 +114,9 @@ google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/g
|
|||||||
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
|
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
|
||||||
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
|
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||||
|
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
23
main.go
23
main.go
@@ -19,6 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
@@ -27,9 +28,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
const NoLogsLevel = 100
|
||||||
|
slog.SetLogLoggerLevel(NoLogsLevel)
|
||||||
|
|
||||||
Main()
|
Main()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// if we're running on Windows AND if the user double clicked the
|
||||||
|
// exe file from explorer, we tell them and then wait until any
|
||||||
|
// key has been hit, which will make the cmd window disappear and
|
||||||
|
// thus give the user time to read it.
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
if mousetrap.StartedByExplorer() {
|
||||||
|
fmt.Println("Do no double click kleingebaeck.exe!")
|
||||||
|
fmt.Println("Please open a command shell and run it from there.")
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Print("Press any key to quit: ")
|
||||||
|
_, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Main() int {
|
func Main() int {
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
37
t/crypt.txtar
Normal file
37
t/crypt.txtar
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#
|
||||||
|
# Copyright © 2025 Thomas von Dein
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
# encrypt something
|
||||||
|
exec env ANYDB_PASSWORD=12345 anydb -f test.db set -e secret eshishinusan
|
||||||
|
|
||||||
|
# retrieve it
|
||||||
|
exec env ANYDB_PASSWORD=12345 anydb -f test.db get secret
|
||||||
|
stdout eshishinusan
|
||||||
|
|
||||||
|
# but has it really been encrypted?
|
||||||
|
! exec env ANYDB_PASSWORD=8d8d8 anydb -f test.db get secret
|
||||||
|
! stdout eshishinusan
|
||||||
|
stderr 'message authentication failed'
|
||||||
|
|
||||||
|
# what about the listing
|
||||||
|
exec anydb -f test.db ls -l
|
||||||
|
stdout 'encrypted-content'
|
||||||
|
! stdout eshishinusan
|
||||||
|
|
||||||
|
# and the export?
|
||||||
|
exec anydb -f test.db export -o -
|
||||||
|
! stdout eshishinusan
|
||||||
Reference in New Issue
Block a user