2020-08-13 14:00:15 -04:00
|
|
|
package static
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/host/static/store"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A HostSet is a collection of hosts from the set's catalog.
|
|
|
|
|
type HostSet struct {
|
|
|
|
|
*store.HostSet
|
|
|
|
|
tableName string `gorm:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewHostSet creates a new in memory HostSet assigned to catalogId.
|
|
|
|
|
// Name and description are the only valid options. All other options are
|
|
|
|
|
// ignored.
|
|
|
|
|
func NewHostSet(catalogId string, opt ...Option) (*HostSet, error) {
|
|
|
|
|
if catalogId == "" {
|
|
|
|
|
return nil, fmt.Errorf("new: static host set: no catalog id: %w", db.ErrInvalidParameter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opts := getOpts(opt...)
|
|
|
|
|
set := &HostSet{
|
|
|
|
|
HostSet: &store.HostSet{
|
2020-08-17 11:00:41 -04:00
|
|
|
CatalogId: catalogId,
|
|
|
|
|
Name: opts.withName,
|
|
|
|
|
Description: opts.withDescription,
|
2020-08-13 14:00:15 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return set, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName returns the table name for the host set.
|
|
|
|
|
func (s *HostSet) TableName() string {
|
|
|
|
|
if s.tableName != "" {
|
|
|
|
|
return s.tableName
|
|
|
|
|
}
|
|
|
|
|
return "static_host_set"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetTableName sets the table name. If the caller attempts to
|
|
|
|
|
// set the name to "" the name will be reset to the default name.
|
|
|
|
|
func (s *HostSet) SetTableName(n string) {
|
|
|
|
|
s.tableName = n
|
|
|
|
|
}
|