summaryrefslogtreecommitdiff
path: root/vendor/github.com/99designs/keyring/array.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
committermo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
commit20ef0d92694465ac86b550df139e8366a0a2b4fa (patch)
tree3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/99designs/keyring/array.go
parent44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff)
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/99designs/keyring/array.go')
-rw-r--r--vendor/github.com/99designs/keyring/array.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/keyring/array.go b/vendor/github.com/99designs/keyring/array.go
new file mode 100644
index 0000000..3179cb5
--- /dev/null
+++ b/vendor/github.com/99designs/keyring/array.go
@@ -0,0 +1,54 @@
+package keyring
+
+// ArrayKeyring is a mock/non-secure backend that meets the Keyring interface.
+// It is intended to be used to aid unit testing of code that relies on the package.
+// NOTE: Do not use in production code.
+type ArrayKeyring struct {
+ items map[string]Item
+}
+
+// NewArrayKeyring returns an ArrayKeyring, optionally constructed with an initial slice
+// of items.
+func NewArrayKeyring(initial []Item) *ArrayKeyring {
+ kr := &ArrayKeyring{}
+ for _, i := range initial {
+ _ = kr.Set(i)
+ }
+ return kr
+}
+
+// Get returns an Item matching Key.
+func (k *ArrayKeyring) Get(key string) (Item, error) {
+ if i, ok := k.items[key]; ok {
+ return i, nil
+ }
+ return Item{}, ErrKeyNotFound
+}
+
+// Set will store an item on the mock Keyring.
+func (k *ArrayKeyring) Set(i Item) error {
+ if k.items == nil {
+ k.items = map[string]Item{}
+ }
+ k.items[i.Key] = i
+ return nil
+}
+
+// Remove will delete an Item from the Keyring.
+func (k *ArrayKeyring) Remove(key string) error {
+ delete(k.items, key)
+ return nil
+}
+
+// Keys provides a slice of all Item keys on the Keyring.
+func (k *ArrayKeyring) Keys() ([]string, error) {
+ var keys = []string{}
+ for key := range k.items {
+ keys = append(keys, key)
+ }
+ return keys, nil
+}
+
+func (k *ArrayKeyring) GetMetadata(_ string) (Metadata, error) {
+ return Metadata{}, ErrMetadataNeedsCredentials
+}