Add repository and functions around plugin host set membership (#1629)
Co-authored-by: Todd <T.Alan.Knight@gmail.com>
This commit is contained in:
1 parent
b1a72bd445
commit
b64761f38f
23 files changed
+1392
-286
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/host/plugin/store"
|
||||
"github.com/hashicorp/boundary/internal/oplog"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -16,14 +17,15 @@ import (
|
||||
// field for this host's host catalog.
|
||||
type Host struct {
|
||||
*store.Host
|
||||
PluginId string `gorm:"-"`
|
||||
tableName string `gorm:"-"`
|
||||
PluginId string `gorm:"-"`
|
||||
SetIds []string `gorm:"-"`
|
||||
tableName string `gorm:"-"`
|
||||
}
|
||||
|
||||
// newHost creates a new in memory Host assigned to catalogId with an address.
|
||||
// Supported options: WithName, WithDescription, WithIpAddresses, WithDnsNames,
|
||||
// WithPluginId. Others ignored.
|
||||
func newHost(ctx context.Context, catalogId, externalId string, opt ...Option) *Host {
|
||||
func NewHost(ctx context.Context, catalogId, externalId string, opt ...Option) *Host {
|
||||
opts := getOpts(opt...)
|
||||
|
||||
h := &Host{
|
||||
@@ -74,10 +76,31 @@ func allocHost() *Host {
|
||||
|
||||
func (h *Host) clone() *Host {
|
||||
cp := proto.Clone(h.Host)
|
||||
return &Host{
|
||||
nh := &Host{
|
||||
PluginId: h.PluginId,
|
||||
Host: cp.(*store.Host),
|
||||
}
|
||||
switch {
|
||||
case h.SetIds == nil:
|
||||
case len(h.SetIds) == 0:
|
||||
nh.SetIds = make([]string, 0)
|
||||
default:
|
||||
nh.SetIds = make([]string, len(h.SetIds))
|
||||
copy(nh.SetIds, h.SetIds)
|
||||
}
|
||||
return nh
|
||||
}
|
||||
|
||||
func (h *Host) oplog(op oplog.OpType) oplog.Metadata {
|
||||
metadata := oplog.Metadata{
|
||||
"resource-public-id": []string{h.PublicId},
|
||||
"resource-type": []string{"plugin-host"},
|
||||
"op-type": []string{op.String()},
|
||||
}
|
||||
if h.CatalogId != "" {
|
||||
metadata["catalog-id"] = []string{h.CatalogId}
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
// hostAgg is a view that aggregates the host's value objects in to
|
||||
@@ -93,6 +116,7 @@ type hostAgg struct {
|
||||
UpdateTime *timestamp.Timestamp
|
||||
IpAddresses string
|
||||
DnsNames string
|
||||
SetIds string
|
||||
}
|
||||
|
||||
func (agg *hostAgg) toHost(ctx context.Context) (*Host, error) {
|
||||
@@ -118,12 +142,17 @@ func (agg *hostAgg) toHost(ctx context.Context) (*Host, error) {
|
||||
sort.Strings(h.DnsNames)
|
||||
}
|
||||
|
||||
if agg.SetIds != "" {
|
||||
h.SetIds = strings.Split(agg.SetIds, aggregateDelimiter)
|
||||
sort.Strings(h.SetIds)
|
||||
}
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
// TableName returns the table name for gorm
|
||||
func (agg *hostAgg) TableName() string {
|
||||
return "host_plugin_host_with_value_obj"
|
||||
return "host_plugin_host_with_value_obj_and_set_memberships"
|
||||
}
|
||||
|
||||
func (agg *hostAgg) GetPublicId() string {
|
||||
|
||||
Reference in new issue
Block a user