Documentation ¶
Overview ¶
Package static provides a host, a host catalog, and a host set suitable for hosts with a static address.
A host catalog contains a collection of hosts with static addresses. These hosts can be grouped into host sets allowing them to be used in a target. Hosts and host sets are owned by a single host catalog. If a host catalog is deleted, all hosts and host sets owned by it are also deleted. A host set contains references to zero or more hosts but does not own them. Deleting a host set does not effect any of the hosts it referenced. A host set can only reference hosts from the host catalog that owns it. Host addresses must be unique within a host catalog.
Repository ¶
A repository provides methods for creating, updating, retrieving, and deleting host catalogs, host sets, and hosts. A new repository should be created for each transaction. For example:
var wrapper wrapping.Wrapper ... init wrapper... // db implements both the reader and writer interfaces. db, _ := db.Open(db.Postgres, url) var repo *static.Repository repo, _ = static.NewRepository(db, db, wrapper) catalog, _ := repo.LookupCatalog(ctx, catalogId) catalog.Name = "new name" repo, _ = static.NewRepository(db, db, wrapper) catalog, _ := repo.UpdateCatalog(ctx, catalog, []string{"Name"})
Index ¶
- Constants
- type Host
- type HostCatalog
- type HostSet
- type HostSetMember
- type Option
- type Repository
- func (r *Repository) AddSetMembers(ctx context.Context, scopeId string, setId string, version uint32, ...) ([]*Host, error)
- func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...Option) (*HostCatalog, error)
- func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, opt ...Option) (*Host, error)
- func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, opt ...Option) (*HostSet, error)
- func (r *Repository) DeleteCatalog(ctx context.Context, id string, opt ...Option) (int, error)
- func (r *Repository) DeleteHost(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error)
- func (r *Repository) DeleteSet(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error)
- func (r *Repository) DeleteSetMembers(ctx context.Context, scopeId string, setId string, version uint32, ...) (int, error)
- func (r *Repository) ListCatalogs(ctx context.Context, scopeIds []string, opt ...Option) ([]*HostCatalog, error)
- func (r *Repository) ListHosts(ctx context.Context, catalogId string, opt ...Option) ([]*Host, error)
- func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...Option) ([]*HostSet, error)
- func (r *Repository) LookupCatalog(ctx context.Context, id string, opt ...Option) (*HostCatalog, error)
- func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, error)
- func (r *Repository) LookupSet(ctx context.Context, publicId string, opt ...Option) (*HostSet, []*Host, error)
- func (r *Repository) SetSetMembers(ctx context.Context, scopeId string, setId string, version uint32, ...) ([]*Host, int, error)
- func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, ...) (*HostCatalog, int, error)
- func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, version uint32, ...) (*Host, int, error)
- func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet, version uint32, ...) (*HostSet, []*Host, int, error)
Examples ¶
Constants ¶
const ( MinHostAddressLength = 3 MaxHostAddressLength = 255 )
const ( HostCatalogPrefix = "hcst" HostSetPrefix = "hsst" HostPrefix = "hst" Subtype = subtypes.Subtype("static") )
PublicId prefixes for the resources in the static package.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Host ¶
A Host contains a static address.
func NewHost ¶
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.
Example ¶
package main import ( "fmt" "github.com/hashicorp/boundary/internal/host/static" ) func main() { catalogPublicId := "hcst_1234" host, _ := static.NewHost(catalogPublicId, static.WithAddress("127.0.0.1")) fmt.Println(host.Address) }
Output: 127.0.0.1
func TestHosts ¶
TestHosts creates count number of static hosts to the provided DB with the provided catalog id. The catalog must have been created previously. If any errors are encountered during the creation of the host, the test will fail.
func (*Host) SetTableName ¶
SetTableName sets the table name. If the caller attempts to set the name to "" the name will be reset to the default name.
type HostCatalog ¶
type HostCatalog struct { *store.HostCatalog // contains filtered or unexported fields }
A HostCatalog contains static hosts and static host sets. It is owned by a scope.
func NewHostCatalog ¶
func NewHostCatalog(scopeId string, opt ...Option) (*HostCatalog, error)
NewHostCatalog creates a new in memory HostCatalog assigned to scopeId. Name and description are the only valid options. All other options are ignored.
Example ¶
package main import ( "fmt" "github.com/hashicorp/boundary/internal/host/static" ) func main() { projectPublicId := "p_1234" catalog, _ := static.NewHostCatalog(projectPublicId, static.WithName("my catalog")) fmt.Println(catalog.Name) }
Output: my catalog
func TestCatalogs ¶
TestCatalogs creates count number of static host catalogs to the provided DB with the provided scope id. If any errors are encountered during the creation of the host catalog, the test will fail.
func (*HostCatalog) SetTableName ¶
func (c *HostCatalog) SetTableName(n string)
SetTableName sets the table name. If the caller attempts to set the name to "" the name will be reset to the default name.
func (*HostCatalog) TableName ¶
func (c *HostCatalog) TableName() string
TableName returns the table name for the host catalog.
type HostSet ¶
A HostSet is a collection of hosts from the set's catalog.
func NewHostSet ¶
NewHostSet creates a new in memory HostSet assigned to catalogId. Name and description are the only valid options. All other options are ignored.
Example ¶
package main import ( "fmt" "github.com/hashicorp/boundary/internal/host/static" ) func main() { catalogPublicId := "hcst_1234" set, _ := static.NewHostSet(catalogPublicId, static.WithName("my host set")) fmt.Println(set.Name) }
Output: my host set
func TestSets ¶
TestSets creates count number of static host sets in the provided DB with the provided catalog id. The catalog must have been created previously. The test will fail if any errors are encountered.
func (*HostSet) SetTableName ¶
SetTableName sets the table name. If the caller attempts to set the name to "" the name will be reset to the default name.
type HostSetMember ¶
type HostSetMember struct { *store.HostSetMember // contains filtered or unexported fields }
A HostSetMember represents the membership of a host in a host set.
func NewHostSetMember ¶
func NewHostSetMember(hostSetId, hostId string, opt ...Option) (*HostSetMember, error)
NewHostSetMember creates a new in memory HostSetMember representing the membership of hostId in hostSetId.
Example ¶
package main import ( "fmt" "github.com/hashicorp/boundary/internal/host/static" ) func main() { setPublicId := "hsst_11111" hostPublicId := "hst_22222" member, _ := static.NewHostSetMember(setPublicId, hostPublicId) fmt.Println(member.SetId) fmt.Println(member.HostId) }
Output:
func TestSetMembers ¶
TestSetMembers adds hosts to the specified setId in the provided DB. The set and hosts must have been created previously and belong to the same catalog. The test will fail if any errors are encountered.
func (*HostSetMember) SetTableName ¶
func (m *HostSetMember) SetTableName(n string)
SetTableName sets the table name. If the caller attempts to set the name to "" the name will be reset to the default name.
func (*HostSetMember) TableName ¶
func (m *HostSetMember) TableName() string
TableName returns the table name for the host set.
type Option ¶
type Option func(*options)
Option - how Options are passed as arguments.
func WithAddress ¶
WithAddress provides an optional address.
func WithDescription ¶
WithDescription provides an optional description.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
A Repository stores and retrieves the persistent types in the static package. It is not safe to use a repository concurrently.
func NewRepository ¶
NewRepository creates a new Repository. The returned repository should only be used for one transaction and it is not safe for concurrent go routines to access it. WithLimit option is used as a repo wide default limit applied to all ListX methods.
func (*Repository) AddSetMembers ¶
func (r *Repository) AddSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) ([]*Host, error)
AddSetMembers adds hostIds to setId in the repository. It returns a slice of all hosts in setId. A host must belong to the same catalog as the set to be added. The version must match the current version of the setId in the repository.
func (*Repository) CreateCatalog ¶
func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...Option) (*HostCatalog, error)
CreateCatalog inserts c into the repository and returns a new HostCatalog containing the catalog's PublicId. c is not changed. c must contain a valid ScopeID. c must not contain a PublicId. The PublicId is generated and assigned by this method. opt is ignored.
Both c.Name and c.Description are optional. If c.Name is set, it must be unique within c.ScopeID.
Both c.CreateTime and c.UpdateTime are ignored.
func (*Repository) CreateHost ¶
func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, opt ...Option) (*Host, error)
CreateHost inserts h into the repository and returns a new Host containing the host's PublicId. h is not changed. h must contain a valid CatalogId. h must not contain a PublicId. The PublicId is generated and assigned by this method. opt is ignored.
h must contain a valid Address.
Both h.Name and h.Description are optional. If h.Name is set, it must be unique within h.CatalogId.
func (*Repository) CreateSet ¶
func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, opt ...Option) (*HostSet, error)
CreateSet inserts s into the repository and returns a new HostSet containing the host set's PublicId. s is not changed. s must contain a valid CatalogId. s must not contain a PublicId. The PublicId is generated and assigned by this method. opt is ignored.
Both s.Name and s.Description are optional. If s.Name is set, it must be unique within s.CatalogId.
func (*Repository) DeleteCatalog ¶
DeleteCatalog deletes id from the repository returning a count of the number of records deleted.
func (*Repository) DeleteHost ¶
func (r *Repository) DeleteHost(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error)
DeleteHost deletes the host for the provided id from the repository returning a count of the number of records deleted. All options are ignored.
func (*Repository) DeleteSet ¶
func (r *Repository) DeleteSet(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error)
DeleteSet deletes the host set for the provided id from the repository returning a count of the number of records deleted. All options are ignored.
func (*Repository) DeleteSetMembers ¶
func (r *Repository) DeleteSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) (int, error)
DeleteSetMembers deletes hostIds from setId in the repository. It returns the number of hosts deleted from the set. The version must match the current version of the setId in the repository.
func (*Repository) ListCatalogs ¶
func (r *Repository) ListCatalogs(ctx context.Context, scopeIds []string, opt ...Option) ([]*HostCatalog, error)
ListCatalogs returns a slice of HostCatalogs for the scope IDs. WithLimit is the only option supported.
func (*Repository) ListHosts ¶
func (r *Repository) ListHosts(ctx context.Context, catalogId string, opt ...Option) ([]*Host, error)
ListHosts returns a slice of Hosts for the catalogId. WithLimit is the only option supported.
func (*Repository) ListSets ¶
func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...Option) ([]*HostSet, error)
ListSets returns a slice of HostSets for the catalogId. WithLimit is the only option supported.
func (*Repository) LookupCatalog ¶
func (r *Repository) LookupCatalog(ctx context.Context, id string, opt ...Option) (*HostCatalog, error)
LookupCatalog returns the HostCatalog for id. Returns nil, nil if no HostCatalog is found for id.
func (*Repository) LookupHost ¶
LookupHost will look up a host in the repository. If the host is not found, it will return nil, nil. All options are ignored.
func (*Repository) LookupSet ¶
func (r *Repository) LookupSet(ctx context.Context, publicId string, opt ...Option) (*HostSet, []*Host, error)
LookupSet will look up a host set in the repository and return the host set and the hosts assigned to the host set. If the host set is not found, it will return nil, nil, nil. The WithLimit option can be used to limit the number of hosts returned. All other options are ignored.
func (*Repository) SetSetMembers ¶
func (r *Repository) SetSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) ([]*Host, int, error)
SetSetMembers replaces the hosts in setId with hostIds in the repository. It returns a slice of all hosts in setId and a count of hosts added or deleted. A host must belong to the same catalog as the set to be added. The version must match the current version of the setId in the repository. If hostIds is empty, all hosts will be removed setId.
func (*Repository) UpdateCatalog ¶
func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, opt ...Option) (*HostCatalog, int, error)
UpdateCatalog updates the repository entry for c.PublicId with the values in c for the fields listed in fieldMask. It returns a new HostCatalog containing the updated values and a count of the number of records updated. c is not changed.
c must contain a valid PublicId. Only c.Name and c.Description can be updated. If c.Name is set to a non-empty string, it must be unique within c.ScopeID.
An attribute of c will be set to NULL in the database if the attribute in c is the zero value and it is included in fieldMask.
func (*Repository) UpdateHost ¶
func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, version uint32, fieldMaskPaths []string, opt ...Option) (*Host, int, error)
UpdateHost updates the repository entry for h.PublicId with the values in h for the fields listed in fieldMaskPaths. It returns a new Host containing the updated values and a count of the number of records updated. h is not changed.
h must contain a valid PublicId. Only h.Name, h.Description, and h.Address can be updated. If h.Name is set to a non-empty string, it must be unique within h.CatalogId. If h.Address is set, it must contain a valid address.
An attribute of h will be set to NULL in the database if the attribute in h is the zero value and it is included in fieldMaskPaths.
func (*Repository) UpdateSet ¶
func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet, version uint32, fieldMaskPaths []string, opt ...Option) (*HostSet, []*Host, int, error)
UpdateSet updates the repository entry for s.PublicId with the values in s for the fields listed in fieldMaskPaths. It returns a new HostSet containing the updated values, the hosts assigned to the host set, and a count of the number of records updated. s is not changed.
s must contain a valid PublicId. Only s.Name and s.Description can be updated. If s.Name is set to a non-empty string, it must be unique within s.CatalogId.
An attribute of s will be set to NULL in the database if the attribute in s is the zero value and it is included in fieldMaskPaths.
The WithLimit option can be used to limit the number of hosts returned. All other options are ignored.