-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.go
53 lines (46 loc) · 1.58 KB
/
key.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
package gcpcab
import (
"context"
"errors"
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/sdk/logical"
)
var (
ErrKeyNotFound = errors.New("Config Key Name not found")
)
// Key represents a key from the storage backend.
type ConfigSpec struct {
Restricted bool `json:"restricted"`
TargetServiceAccount string `json:"target_service_account"`
Project string `json:"project"`
Scopes []string `json:"scopes"`
Delegates []string `json:"delegates"`
Duration int `json:"duration"`
Bindings AccessBoundary `json:downscoped_options`
RawToken bool `json:raw_token`
}
// Key retrieves the named key from the storage backend, or an error if one does
// not exist.
func (b *backend) CABKey(ctx context.Context, s logical.Storage, name string) (*ConfigSpec, error) {
entry, err := s.Get(ctx, "cab/config/"+name)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("failed to retrieve issuer config %q: {{err}}", name), err)
}
if entry == nil {
return nil, ErrKeyNotFound
}
var result ConfigSpec
if err := entry.DecodeJSON(&result); err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("failed to decode entry for %q: {{err}}", name), err)
}
return &result, nil
}
// Keys returns the list of keys
func (b *backend) CABKeys(ctx context.Context, s logical.Storage) ([]string, error) {
entries, err := s.List(ctx, "cab/config/")
if err != nil {
return nil, errwrap.Wrapf("failed to list keys: {{err}}", err)
}
return entries, nil
}