-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathcredential_store.go
65 lines (57 loc) · 1.7 KB
/
credential_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
package static
import (
"github.com/hashicorp/boundary/internal/credential/static/store"
"github.com/hashicorp/boundary/internal/oplog"
"google.golang.org/protobuf/proto"
)
// A CredentialStore contains credentials. It is owned by a project.
type CredentialStore struct {
*store.CredentialStore
tableName string `gorm:"-"`
}
// NewCredentialStore creates a new in memory static CredentialStore assigned to projectId.
// Name and description are the only valid options. All other options are ignored.
func NewCredentialStore(projectId string, opt ...Option) (*CredentialStore, error) {
opts := getOpts(opt...)
cs := &CredentialStore{
CredentialStore: &store.CredentialStore{
ProjectId: projectId,
Name: opts.withName,
Description: opts.withDescription,
},
}
return cs, nil
}
func allocCredentialStore() *CredentialStore {
return &CredentialStore{
CredentialStore: &store.CredentialStore{},
}
}
func (cs *CredentialStore) clone() *CredentialStore {
cp := proto.Clone(cs.CredentialStore)
return &CredentialStore{
CredentialStore: cp.(*store.CredentialStore),
}
}
// TableName returns the table name.
func (cs *CredentialStore) TableName() string {
if cs.tableName != "" {
return cs.tableName
}
return "credential_static_store"
}
// SetTableName sets the table name.
func (cs *CredentialStore) SetTableName(n string) {
cs.tableName = n
}
func (cs *CredentialStore) oplog(op oplog.OpType) oplog.Metadata {
metadata := oplog.Metadata{
"resource-public-id": []string{cs.PublicId},
"resource-type": []string{"credential-static-store"},
"op-type": []string{op.String()},
}
if cs.ProjectId != "" {
metadata["project-id"] = []string{cs.ProjectId}
}
return metadata
}