/
store.go
235 lines (192 loc) · 5.16 KB
/
store.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package mockstore
import (
"context"
"fmt"
"github.com/gopasspw/gopass/pkg/backend"
"github.com/gopasspw/gopass/pkg/backend/crypto/plain"
"github.com/gopasspw/gopass/pkg/backend/rcs/noop"
"github.com/gopasspw/gopass/pkg/backend/storage/kv/inmem"
"github.com/gopasspw/gopass/pkg/store"
"github.com/gopasspw/gopass/pkg/store/secret"
"github.com/gopasspw/gopass/pkg/tree"
)
// MockStore is an mocked store
type MockStore struct {
alias string
storage backend.Storage
}
// New creates a new mock store
func New(alias string) *MockStore {
return &MockStore{
alias: alias,
storage: inmem.New(),
}
}
// String implements fmt.Stringer
func (m *MockStore) String() string {
return "mockstore"
}
// GetTemplate returns nothing
func (m *MockStore) GetTemplate(context.Context, string) ([]byte, error) {
return []byte{}, nil
}
// HasTemplate returns false
func (m *MockStore) HasTemplate(context.Context, string) bool {
return false
}
// ListTemplates returns nothing
func (m *MockStore) ListTemplates(context.Context, string) []string {
return nil
}
// LookupTemplate returns nothing
func (m *MockStore) LookupTemplate(context.Context, string) ([]byte, bool) {
return []byte{}, false
}
// RemoveTemplate does nothing
func (m *MockStore) RemoveTemplate(context.Context, string) error {
return nil
}
// SetTemplate does nothing
func (m *MockStore) SetTemplate(context.Context, string, []byte) error {
return nil
}
// TemplateTree does nothing
func (m *MockStore) TemplateTree(context.Context) (tree.Tree, error) {
return nil, nil
}
// AddRecipient does nothing
func (m *MockStore) AddRecipient(context.Context, string) error {
return nil
}
// GetRecipients does nothing
func (m *MockStore) GetRecipients(context.Context, string) ([]string, error) {
return nil, nil
}
// RemoveRecipient does nothing
func (m *MockStore) RemoveRecipient(context.Context, string) error {
return nil
}
// SaveRecipients does nothing
func (m *MockStore) SaveRecipients(context.Context) error {
return nil
}
// Recipients does nothing
func (m *MockStore) Recipients(context.Context) []string {
return nil
}
// ImportMissingPublicKeys does nothing
func (m *MockStore) ImportMissingPublicKeys(context.Context) error {
return nil
}
// ExportMissingPublicKeys does nothing
func (m *MockStore) ExportMissingPublicKeys(context.Context, []string) (bool, error) {
return false, nil
}
// Fsck does nothing
func (m *MockStore) Fsck(context.Context, string) error {
return nil
}
// Path does nothing
func (m *MockStore) Path() string {
return ""
}
// URL does nothing
func (m *MockStore) URL() string {
return "mockstore://"
}
// RCS does nothing
func (m *MockStore) RCS() backend.RCS {
return noop.New()
}
// Crypto does nothing
func (m *MockStore) Crypto() backend.Crypto {
return plain.New()
}
// Storage does nothing
func (m *MockStore) Storage() backend.Storage {
return m.storage
}
// GitInit does nothing
func (m *MockStore) GitInit(context.Context, string, string) error {
return nil
}
// Alias does nothing
func (m *MockStore) Alias() string {
return m.alias
}
// Copy does nothing
func (m *MockStore) Copy(ctx context.Context, from string, to string) error {
content, _ := m.storage.Get(ctx, from)
m.storage.Set(ctx, to, content)
return nil
}
// Delete does nothing
func (m *MockStore) Delete(ctx context.Context, name string) error {
return m.storage.Delete(ctx, name)
}
// Equals does nothing
func (m *MockStore) Equals(other store.Store) bool {
return false
}
// Exists does nothing
func (m *MockStore) Exists(ctx context.Context, name string) bool {
return m.storage.Exists(ctx, name)
}
// Get does nothing
func (m *MockStore) Get(ctx context.Context, name string) (store.Secret, error) {
content, err := m.storage.Get(ctx, name)
if err != nil {
return nil, err
}
return secret.Parse(content)
}
// GetRevision does nothing
func (m *MockStore) GetRevision(context.Context, string, string) (store.Secret, error) {
return nil, fmt.Errorf("not supported")
}
// Init does nothing
func (m *MockStore) Init(context.Context, string, ...string) error {
return nil
}
// Initialized does nothing
func (m *MockStore) Initialized(context.Context) bool {
return true
}
// IsDir does nothing
func (m *MockStore) IsDir(ctx context.Context, name string) bool {
return m.storage.IsDir(ctx, name)
}
// List does nothing
func (m *MockStore) List(context.Context, string) ([]string, error) {
return nil, nil
}
// ListRevisions does nothing
func (m *MockStore) ListRevisions(context.Context, string) ([]backend.Revision, error) {
return nil, nil
}
// Move does nothing
func (m *MockStore) Move(ctx context.Context, from string, to string) error {
content, _ := m.storage.Get(ctx, from)
m.storage.Set(ctx, to, content)
return m.storage.Delete(ctx, from)
}
// Set does nothing
func (m *MockStore) Set(ctx context.Context, name string, sec store.Secret) error {
buf, err := sec.Bytes()
if err != nil {
return err
}
return m.storage.Set(ctx, name, buf)
}
// Prune does nothing
func (m *MockStore) Prune(context.Context, string) error {
return fmt.Errorf("not supported")
}
// Valid does nothing
func (m *MockStore) Valid() bool {
return true
}
// MountPoints does nothing
func (m *MockStore) MountPoints() []string {
return nil
}