forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
39 lines (32 loc) · 939 Bytes
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package logical
import (
"fmt"
"github.com/hashicorp/vault/helper/jsonutil"
)
// Storage is the way that logical backends are able read/write data.
type Storage interface {
List(prefix string) ([]string, error)
Get(string) (*StorageEntry, error)
Put(*StorageEntry) error
Delete(string) error
}
// StorageEntry is the entry for an item in a Storage implementation.
type StorageEntry struct {
Key string
Value []byte
}
// DecodeJSON decodes the 'Value' present in StorageEntry.
func (e *StorageEntry) DecodeJSON(out interface{}) error {
return jsonutil.DecodeJSON(e.Value, out)
}
// StorageEntryJSON creates a StorageEntry with a JSON-encoded value.
func StorageEntryJSON(k string, v interface{}) (*StorageEntry, error) {
encodedBytes, err := jsonutil.EncodeJSON(v)
if err != nil {
return nil, fmt.Errorf("failed to encode storage entry: %v", err)
}
return &StorageEntry{
Key: k,
Value: encodedBytes,
}, nil
}