feat: add Vault

Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru>
Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
This commit is contained in:
2025-07-21 17:16:10 +03:00
committed by dmitry
parent d85dca2195
commit 854de3865b
6 changed files with 261 additions and 13 deletions

View File

@@ -1,24 +1,26 @@
package microkv
package storage
import (
"code.uint32.ru/tiny/objstore/internal/filesystem"
"code.uint32.ru/tiny/objstore/internal/natsobj"
"code.uint32.ru/tiny/storage/internal/filesystem"
"code.uint32.ru/tiny/storage/internal/natsobj"
"code.uint32.ru/tiny/storage/internal/vault"
)
var (
_ Storage = (*natsobj.Storage)(nil)
_ Storage = (*filesystem.Storage)(nil)
_ Storage = (*vault.Storage)(nil)
)
// Storage is a very basic object store.
type Storage interface {
// Save puts file with name 'key' into the store. If a file with such name
// already exists it gets overwritten.
// Save puts object with name 'key' into the store.
// If a key already exists it gets overwritten.
Save(key string, data []byte) error
// Load returns contents of file named 'key'.
// Load returns contents of object named 'key'.
Load(key string) ([]byte, error)
// Delete removes file named 'key' from the store.
// If such file does not exist Delete returns nil.
// Delete removes object named 'key' from the store.
// If key does not exist Delete returns nil.
Delete(key string) error
// Close must be called when you're done working with Storage.
Close() error
@@ -36,3 +38,11 @@ func NewNats(bucket string, url string) (Storage, error) {
func NewFS(path string) (Storage, error) {
return filesystem.Open(path)
}
// NewVault connects to Vault at addr and uses path as base path for
// keys. Objects saved to Storage will be put at
// /path/key as new secrets.
// Bytes passed to storage will be base64 encoded and saved as string.
func NewVault(token string, path string, addr string) (Storage, error) {
return vault.Open(token, path, addr)
}