Files
threshold/internal/iam/account.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.2 KiB
Go
Raw Normal View History

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2020-06-29 08:18:57 -04:00
package iam
import (
"context"
2020-08-10 17:15:02 -04:00
authStore "github.com/hashicorp/boundary/internal/auth/store"
"github.com/hashicorp/boundary/internal/db"
2020-11-05 16:54:03 -05:00
"github.com/hashicorp/boundary/internal/errors"
2020-08-10 17:15:02 -04:00
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/types/resource"
2020-06-29 08:18:57 -04:00
"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
2020-06-29 08:18:57 -04:00
tableName string `gorm:"-"`
}
var (
_ Cloneable = (*authAccount)(nil)
_ db.VetForWriter = (*authAccount)(nil)
_ oplog.ReplayableMessage = (*authAccount)(nil)
)
2020-06-29 08:18:57 -04:00
func allocAccount() authAccount {
return authAccount{
Account: &authStore.Account{},
2020-06-29 08:18:57 -04:00
}
}
// Clone creates a clone of the auth account.
2022-10-25 18:29:38 -05:00
func (a *authAccount) Clone() any {
cp := proto.Clone(a.Account)
return &authAccount{
Account: cp.(*authStore.Account),
2020-06-29 08:18:57 -04:00
}
}
// VetForWrite implements db.VetForWrite() interface.
func (a *authAccount) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, opt ...db.Option) error {
2020-12-23 11:00:00 -08:00
const op = "iam.(authAccount).VetForWrite"
2020-06-29 08:18:57 -04:00
if a.PublicId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing public id")
2020-06-29 08:18:57 -04:00
}
if err := validateScopeForWrite(ctx, r, a, opType, opt...); err != nil {
return errors.Wrap(ctx, err, op)
2020-06-29 08:18:57 -04:00
}
return nil
}
func (a *authAccount) getResourceType() resource.Type {
return resource.Account
2020-06-29 08:18:57 -04:00
}
// GetScope returns the scope for the auth account.
func (a *authAccount) GetScope(ctx context.Context, r db.Reader) (*Scope, error) {
2020-06-29 08:18:57 -04:00
return LookupScope(ctx, r, a)
}
// TableName returns the tablename to override the default gorm table name.
func (a *authAccount) TableName() string {
2020-06-29 08:18:57 -04:00
if a.tableName != "" {
return a.tableName
}
return defaultAccountTableName
2020-06-29 08:18:57 -04:00
}
// 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) {
2020-07-23 17:58:41 -04:00
a.tableName = n
2020-06-29 08:18:57 -04:00
}