Files
threshold/internal/host/static/host_set.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.5 KiB
Go
Raw Normal View History

2020-08-13 14:00:15 -04: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 (
"context"
"github.com/hashicorp/boundary/internal/db/timestamp"
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"
2020-08-20 13:56:52 -04:00
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/types/resource"
2020-08-20 13:56:52 -04:00
"google.golang.org/protobuf/proto"
2020-08-13 14:00:15 -04:00
)
// 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(ctx context.Context, catalogId string, opt ...Option) (*HostSet, error) {
2020-08-13 14:00:15 -04:00
if catalogId == "" {
return nil, errors.New(ctx, errors.InvalidParameter, "static.NewHostSet", "no catalog id")
2020-08-13 14:00:15 -04:00
}
opts := getOpts(opt...)
set := &HostSet{
HostSet: &store.HostSet{
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
}
2020-08-20 13:56:52 -04:00
// GetResourceType returns the resource type of the HostSet
func (s *HostSet) GetResourceType() resource.Type {
return resource.HostSet
}
2020-08-20 13:56:52 -04:00
func allocHostSet() *HostSet {
return &HostSet{
HostSet: &store.HostSet{},
}
}
func (s *HostSet) clone() *HostSet {
cp := proto.Clone(s.HostSet)
return &HostSet{
HostSet: cp.(*store.HostSet),
}
}
func (s *HostSet) oplog(op oplog.OpType) oplog.Metadata {
metadata := oplog.Metadata{
"resource-public-id": []string{s.PublicId},
"resource-type": []string{"static-host-set"},
"op-type": []string{op.String()},
}
if s.CatalogId != "" {
metadata["catalog-id"] = []string{s.CatalogId}
}
return metadata
}
2020-08-26 12:31:18 -04:00
func newHostSetForMembers(setId string, version uint32) *HostSet {
return &HostSet{
HostSet: &store.HostSet{
PublicId: setId,
Version: version + 1,
},
}
}
type deletedHostSet struct {
PublicId string `gorm:"primary_key"`
DeleteTime *timestamp.Timestamp
}
// TableName returns the tablename to override the default gorm table name
2024-01-04 12:51:21 -08:00
func (ds *deletedHostSet) TableName() string {
return "static_host_set_deleted"
}