* Move static host migrations to higher number * Add wt_host_address domain type * Add base tables for host catalog, host set, and host * Reformat create trigger statements * Add subtype triggers for host catalog, host set, and host * Remove wt_host_address domain type * Rename columns in host_set_member * Add delete trigger functions for base types * Add delete after triggers to static host subtypes * Add protobufs for host base types
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package static
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
"github.com/hashicorp/boundary/internal/host/static/store"
|
|
)
|
|
|
|
// A Host contains a static address.
|
|
type Host struct {
|
|
*store.Host
|
|
tableName string `gorm:"-"`
|
|
}
|
|
|
|
// NewHost creates a new in memory Host for address assigned to catalogId.
|
|
// Name and description are the only valid options. All other options are
|
|
// ignored.
|
|
func NewHost(catalogId, address string, opt ...Option) (*Host, error) {
|
|
if catalogId == "" {
|
|
return nil, fmt.Errorf("new: static host: no catalog id: %w", db.ErrInvalidParameter)
|
|
}
|
|
if address == "" {
|
|
return nil, fmt.Errorf("new: static host: no address: %w", db.ErrInvalidParameter)
|
|
}
|
|
|
|
opts := getOpts(opt...)
|
|
host := &Host{
|
|
Host: &store.Host{
|
|
CatalogId: catalogId,
|
|
Address: address,
|
|
Name: opts.withName,
|
|
Description: opts.withDescription,
|
|
},
|
|
}
|
|
return host, nil
|
|
}
|
|
|
|
// TableName returns the table name for the host.
|
|
func (h *Host) TableName() string {
|
|
if h.tableName != "" {
|
|
return h.tableName
|
|
}
|
|
return "static_host"
|
|
}
|
|
|
|
// SetTableName sets the table name. If the caller attempts to
|
|
// set the name to "" the name will be reset to the default name.
|
|
func (h *Host) SetTableName(n string) {
|
|
h.tableName = n
|
|
}
|