2026-01-28 11:05:07 -06:00
|
|
|
// Copyright IBM Corp. 2020, 2025
|
2020-07-17 16:20:56 -04:00
|
|
|
// 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"
|
2025-06-20 15:31:57 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
2020-06-29 08:18:57 -04:00
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-17 16:20:56 -04:00
|
|
|
const (
|
2020-08-10 15:17:15 -04:00
|
|
|
defaultAccountTableName = "auth_account"
|
2020-07-17 16:20:56 -04:00
|
|
|
)
|
|
|
|
|
|
2020-08-10 15:17:15 -04:00
|
|
|
// 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:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 10:02:32 -05:00
|
|
|
var (
|
|
|
|
|
_ Cloneable = (*authAccount)(nil)
|
|
|
|
|
_ db.VetForWriter = (*authAccount)(nil)
|
|
|
|
|
_ oplog.ReplayableMessage = (*authAccount)(nil)
|
|
|
|
|
)
|
2020-06-29 08:18:57 -04:00
|
|
|
|
2020-08-10 15:17:15 -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 {
|
2020-08-10 15:17:15 -04:00
|
|
|
cp := proto.Clone(a.Account)
|
|
|
|
|
return &authAccount{
|
|
|
|
|
Account: cp.(*authStore.Account),
|
2020-06-29 08:18:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VetForWrite implements db.VetForWrite() interface.
|
2020-08-10 15:17:15 -04:00
|
|
|
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 == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
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 {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.Wrap(ctx, err, op)
|
2020-06-29 08:18:57 -04:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 15:31:57 -04:00
|
|
|
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.
|
2020-08-10 15:17:15 -04:00
|
|
|
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.
|
2020-08-10 15:17:15 -04:00
|
|
|
func (a *authAccount) TableName() string {
|
2020-06-29 08:18:57 -04:00
|
|
|
if a.tableName != "" {
|
|
|
|
|
return a.tableName
|
|
|
|
|
}
|
2020-08-10 15:17:15 -04:00
|
|
|
return defaultAccountTableName
|
2020-06-29 08:18:57 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 16:20:56 -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.
|
2020-08-10 15:17:15 -04:00
|
|
|
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
|
|
|
}
|