Files
threshold/internal/host/plugin/host.go
T
ToddandJeff Mitchell 14cc97b645 Add authorize session for plugin based host sets. (#1559)
Added a new Endpoint struct at the top level host package level to capture host, set, and address chosen.
Temporarily add a host_plugin_host table to capture the hosts returned by the plugins.  This ensures the datawarehouse is able to query the table to decide what host was chosen.  The view used to update the datawarehouse dimension table provides rows with host set ids and hosts which are not in that host set.  This is ok since the function which updates the dimension table provides the host set and host id chosen so that relationship doesn't need to be captured in the view itself.

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-09-26 11:17:21 -04:00

77 lines
1.8 KiB
Go

package plugin
import (
"context"
"github.com/hashicorp/boundary/internal/host/plugin/store"
"github.com/hashicorp/boundary/internal/oplog"
"google.golang.org/protobuf/proto"
)
// A Host is a temporarily cached plugin based resource. The source of truth
// of the data contained here is provided by the service backing the plugin for
// this host. The plugin for this host can be found by looking at the plugin
// field for this host's host catalog.
type Host struct {
*store.Host
tableName string `gorm:"-"`
}
// newHost creates a new in memory Host assigned to catalogId with an address.
// Name and description are the only valid options. All other options are
// ignored.
func newHost(ctx context.Context, catalogId, address string, opt ...Option) *Host {
opts := getOpts(opt...)
h := &Host{
Host: &store.Host{
CatalogId: catalogId,
Name: opts.withName,
Description: opts.withDescription,
Address: address,
},
}
return h
}
// TableName returns the table name for the host set.
func (s *Host) TableName() string {
if s.tableName != "" {
return s.tableName
}
return "host_plugin_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 (s *Host) SetTableName(n string) {
s.tableName = n
}
func allocHost() *Host {
return &Host{
Host: &store.Host{},
}
}
func (s *Host) clone() *Host {
cp := proto.Clone(s.Host)
hs := &Host{
Host: cp.(*store.Host),
}
return hs
}
func (s *Host) oplog(op oplog.OpType) oplog.Metadata {
metadata := oplog.Metadata{
"resource-public-id": []string{s.PublicId},
"resource-type": []string{"plugin-host"},
"op-type": []string{op.String()},
}
if s.CatalogId != "" {
metadata["catalog-id"] = []string{s.CatalogId}
}
return metadata
}