-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathaccount.go
79 lines (67 loc) · 2.15 KB
/
account.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
package iam
import (
"context"
authStore "github.com/hashicorp/boundary/internal/auth/store"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/types/scope"
"google.golang.org/protobuf/proto"
)
const (
defaultAccountTableName = "auth_account"
)
// authAccount is from the auth subsystem and iam is only allowed to: lookup and
// update auth accounts. That's why there is no "new" factory for Accounts.
type authAccount struct {
*authStore.Account
tableName string `gorm:"-"`
}
var (
_ Cloneable = (*authAccount)(nil)
_ db.VetForWriter = (*authAccount)(nil)
_ oplog.ReplayableMessage = (*authAccount)(nil)
)
func allocAccount() authAccount {
return authAccount{
Account: &authStore.Account{},
}
}
// Clone creates a clone of the auth account.
func (a *authAccount) Clone() any {
cp := proto.Clone(a.Account)
return &authAccount{
Account: cp.(*authStore.Account),
}
}
// VetForWrite implements db.VetForWrite() interface.
func (a *authAccount) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, opt ...db.Option) error {
const op = "iam.(authAccount).VetForWrite"
if a.PublicId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing public id")
}
if err := validateScopeForWrite(ctx, r, a, opType, opt...); err != nil {
return errors.Wrap(ctx, err, op)
}
return nil
}
func (a *authAccount) validScopeTypes() []scope.Type {
return []scope.Type{scope.Global, scope.Org}
}
// GetScope returns the scope for the auth account.
func (a *authAccount) GetScope(ctx context.Context, r db.Reader) (*Scope, error) {
return LookupScope(ctx, r, a)
}
// TableName returns the tablename to override the default gorm table name.
func (a *authAccount) TableName() string {
if a.tableName != "" {
return a.tableName
}
return defaultAccountTableName
}
// SetTableName sets the tablename and satisfies the ReplayableMessage
// interface. If the caller attempts to set the name to "" the name will be
// reset to the default name.
func (a *authAccount) SetTableName(n string) {
a.tableName = n
}