2020-11-05 16:54:03 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-08-13 14:00:15 -04:00
|
|
|
package static
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-06 17:09:08 -04:00
|
|
|
"context"
|
|
|
|
|
|
2020-11-05 16:54:03 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
2020-08-13 14:00:15 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/host/static/store"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A HostSetMember represents the membership of a host in a host set.
|
|
|
|
|
type HostSetMember struct {
|
|
|
|
|
*store.HostSetMember
|
|
|
|
|
tableName string `gorm:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewHostSetMember creates a new in memory HostSetMember representing the
|
|
|
|
|
// membership of hostId in hostSetId.
|
2023-06-06 17:09:08 -04:00
|
|
|
func NewHostSetMember(ctx context.Context, hostSetId, hostId string, opt ...Option) (*HostSetMember, error) {
|
2020-12-09 10:11:38 -08:00
|
|
|
const op = "static.NewHostSetMember"
|
2020-08-13 14:00:15 -04:00
|
|
|
if hostSetId == "" {
|
2023-06-06 17:09:08 -04:00
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "no host set id")
|
2020-08-13 14:00:15 -04:00
|
|
|
}
|
|
|
|
|
if hostId == "" {
|
2023-06-06 17:09:08 -04:00
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "no host id")
|
2020-08-13 14:00:15 -04:00
|
|
|
}
|
|
|
|
|
member := &HostSetMember{
|
|
|
|
|
HostSetMember: &store.HostSetMember{
|
2020-08-17 11:00:41 -04:00
|
|
|
SetId: hostSetId,
|
|
|
|
|
HostId: hostId,
|
2020-08-13 14:00:15 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return member, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName returns the table name for the host set.
|
|
|
|
|
func (m *HostSetMember) TableName() string {
|
|
|
|
|
if m.tableName != "" {
|
|
|
|
|
return m.tableName
|
|
|
|
|
}
|
|
|
|
|
return "static_host_set_member"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetTableName sets the table name. If the caller attempts to
|
|
|
|
|
// set the name to "" the name will be reset to the default name.
|
|
|
|
|
func (m *HostSetMember) SetTableName(n string) {
|
|
|
|
|
m.tableName = n
|
|
|
|
|
}
|