-
Notifications
You must be signed in to change notification settings - Fork 289
/
credential.go
68 lines (59 loc) · 1.94 KB
/
credential.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
package target
import (
"fmt"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/target/store"
"google.golang.org/protobuf/proto"
)
// A StaticCredential is a CredentialSource that represents the relationship
// between a target and a static credential.
type StaticCredential struct {
*store.StaticCredential
tableName string `gorm:"-"`
}
// NewStaticCredential creates a new in memory StaticCredential
// representing the relationship between targetId and credentialId.
func NewStaticCredential(targetId, credentialId string, purpose credential.Purpose) (*StaticCredential, error) {
const op = "target.StaticCredential"
if targetId == "" {
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "no target id")
}
if credentialId == "" {
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "no credential id")
}
t := &StaticCredential{
StaticCredential: &store.StaticCredential{
TargetId: targetId,
CredentialId: credentialId,
CredentialPurpose: string(purpose),
},
}
return t, nil
}
func (t *StaticCredential) clone() *StaticCredential {
cp := proto.Clone(t.StaticCredential)
return &StaticCredential{
StaticCredential: cp.(*store.StaticCredential),
}
}
// TableName returns the table name.
func (t *StaticCredential) TableName() string {
if t.tableName != "" {
return t.tableName
}
return "target_static_credential"
}
// SetTableName sets the table name.
func (t *StaticCredential) SetTableName(n string) {
t.tableName = n
}
func (t *StaticCredential) oplog(op oplog.OpType) oplog.Metadata {
metadata := oplog.Metadata{
"resource-public-id": []string{fmt.Sprintf("%s:%s:%s", t.TargetId, t.CredentialId, t.CredentialPurpose)},
"resource-type": []string{"target-credential-static"},
"op-type": []string{op.String()},
}
return metadata
}