Documentation ¶
Overview ¶
Package plugin provides a plugin host catalog, and plugin host set resource which are used to interact with a host plugin as well as a repository to perform CRUDL and custom actions on these resource types.
Package plugin provides a plugin host catalog, and plugin host set resource which are used to interact with a host plugin as well as a repository to perform CRUDL and custom actions on these resources.
Index ¶
- Constants
- func RegisterJobs(ctx context.Context, scheduler *scheduler.Scheduler, r db.Reader, w db.Writer, ...) error
- func TestRunSetSync(t testing.TB, conn *db.DB, kmsCache *kms.Kms, ...)
- type Host
- type HostCatalog
- func NewHostCatalog(ctx context.Context, projectId, pluginId string, opt ...Option) (*HostCatalog, error)
- func TestCatalog(t testing.TB, conn *db.DB, projectId, pluginId string, opt ...Option) *HostCatalog
- func TestCatalogs(t testing.TB, conn *db.DB, projectId, pluginId string, count int) []*HostCatalog
- type HostCatalogSecret
- type HostSet
- type HostSetMember
- type Option
- func WithAttributes(attrs *structpb.Struct) Option
- func WithDescription(desc string) Option
- func WithExternalName(externalName string) Option
- func WithLimit(l int) Option
- func WithName(name string) Option
- func WithPreferredEndpoints(with []string) Option
- func WithPublicId(with string) Option
- func WithSecrets(secrets *structpb.Struct) Option
- func WithSecretsHmac(secretsHmac []byte) Option
- func WithSetIds(with []string) Option
- func WithSyncIntervalSeconds(with int32) Option
- type OrphanedHostCleanupJob
- func (r *OrphanedHostCleanupJob) Description() string
- func (r *OrphanedHostCleanupJob) Name() string
- func (r *OrphanedHostCleanupJob) NextRunIn(_ context.Context) (time.Duration, error)
- func (r *OrphanedHostCleanupJob) Run(ctx context.Context) error
- func (r *OrphanedHostCleanupJob) Status() scheduler.JobStatus
- type Repository
- func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, _ ...Option) (*HostCatalog, *plg.Plugin, error)
- func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet, _ ...Option) (*HostSet, *plugin.Plugin, error)
- func (r *Repository) DeleteCatalog(ctx context.Context, id string, _ ...Option) (int, error)
- func (r *Repository) DeleteSet(ctx context.Context, projectId string, publicId string, _ ...Option) (int, error)
- func (r *Repository) Endpoints(ctx context.Context, setIds []string) ([]*host.Endpoint, error)
- func (r *Repository) ListCatalogs(ctx context.Context, projectIds []string, opt ...host.Option) ([]*HostCatalog, []*plg.Plugin, error)
- func (r *Repository) ListHostsByCatalogId(ctx context.Context, catalogId string, opt ...Option) ([]*Host, *plugin.Plugin, error)
- func (r *Repository) ListHostsBySetIds(ctx context.Context, setIds []string, opt ...Option) ([]*Host, error)
- func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...host.Option) ([]*HostSet, *plugin.Plugin, error)
- func (r *Repository) LookupCatalog(ctx context.Context, id string, _ ...Option) (*HostCatalog, *plg.Plugin, error)
- func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, *plugin.Plugin, error)
- func (r *Repository) LookupSet(ctx context.Context, publicId string, _ ...host.Option) (*HostSet, *plugin.Plugin, error)
- func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, ...) (*HostCatalog, *plg.Plugin, int, error)
- func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet, version uint32, ...) (*HostSet, []*Host, *plugin.Plugin, int, error)
- type SetSyncJob
Constants ¶
const (
Subtype = subtypes.Subtype("plugin")
)
PublicId prefixes for the resources in the plugin package.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Host ¶
type Host struct { *store.Host PluginId string `gorm:"-"` SetIds []string `gorm:"-"` // contains filtered or unexported fields }
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.
func NewHost ¶
NewHost creates a new in memory Host assigned to catalogId with an address. Supported options: WithName, WithDescription, WithIpAddresses, WithDnsNames, WithPluginId, WithPublicId. Others ignored.
func TestExternalHosts ¶
func TestExternalHosts(t testing.TB, catalog *HostCatalog, setIds []string, count int) ([]*plgpb.ListHostsResponseHost, []*Host)
func TestHost ¶
TestHost creates a plugin host in the provided DB in the catalog with the provided catalog id. The catalog must have been created previously. The test will fail if any errors are encountered.
func (*Host) GetAddress ¶
For compatibility with the general Host type
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 Secrets *structpb.Struct `gorm:"-"` // contains filtered or unexported fields }
A HostCatalog contains plugin host sets. It is owned by a project.
func NewHostCatalog ¶
func NewHostCatalog(ctx context.Context, projectId, pluginId string, opt ...Option) (*HostCatalog, error)
NewHostCatalog creates a new in memory HostCatalog assigned to a projectId and pluginId. Name and description are the only valid options. All other options are ignored.
func TestCatalog ¶
TestCatalog creates a plugin host catalogs to the provided DB with the provided project id. If any errors are encountered during the creation of the host catalog, the test will fail.
func TestCatalogs ¶
TestCatalogs creates count number of static host catalogs to the provided DB with the provided project 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 HostCatalogSecret ¶
type HostCatalogSecret struct { *store.HostCatalogSecret // contains filtered or unexported fields }
HostCatalogSecret contains the encrypted secret for a host catalog. It is owned by a HostCatalog.
func (*HostCatalogSecret) SetTableName ¶
func (c *HostCatalogSecret) 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 (*HostCatalogSecret) TableName ¶
func (c *HostCatalogSecret) TableName() string
TableName returns the table name for the host catalog.
type HostSet ¶
type HostSet struct { *store.HostSet PluginId string `gorm:"-"` HostIds []string `gorm:"-"` PreferredEndpoints []string `gorm:"-"` // contains filtered or unexported fields }
A HostSet is a collection of hosts from the set's catalog.
func NewHostSet ¶
NewHostSet creates a new in memory HostSet assigned to catalogId. Attributes, name, description, and preferred endpoints are the only valid options. All other options are ignored.
func TestSet ¶
func TestSet(t testing.TB, conn *db.DB, kmsCache *kms.Kms, sched *scheduler.Scheduler, hc *HostCatalog, plgm map[string]plgpb.HostPluginServiceClient, opt ...Option) *HostSet
TestSet creates a plugin 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(ctx context.Context, setId, hostId string, opt ...Option) (*HostSetMember, error)
NewHostSetMember creates a new in memory HostSetMember representing the membership of hostId in hostSetId.
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 WithAttributes ¶
WithAttributes provides an optional attributes field.
func WithDescription ¶
WithDescription provides an optional description.
func WithExternalName ¶ added in v0.13.0
WithExternalName provides an optional external name for the plugin host.
func WithLimit ¶
WithLimit provides an option to provide a limit. Intentionally allowing negative integers. If WithLimit < 0, then unlimited results are returned. If WithLimit == 0, then default limits are used for results.
func WithPreferredEndpoints ¶
WithPreferredEndpoints provides an optional preferred endpoints field.
func WithPublicId ¶
WithPublicId provides an optional public id.
func WithSecrets ¶
WithSecrets provides an optional secrets field.
func WithSecretsHmac ¶
WithSecretsHmac provides an optional HMAC of secrets. Used for testing.
func WithSetIds ¶
WithSetIds provides the ability to restrict lookups to particular matching sets.
func WithSyncIntervalSeconds ¶
WithSyncIntervalSeconds provides an optional sync interval, in seconds
type OrphanedHostCleanupJob ¶
type OrphanedHostCleanupJob struct {
// contains filtered or unexported fields
}
OrphanedHostCleanupJob is the recurring job that syncs hosts from sets that are. The OrphanedHostCleanupJob is not thread safe, an attempt to Run the job concurrently will result in an JobAlreadyRunning error.
func (*OrphanedHostCleanupJob) Description ¶
func (r *OrphanedHostCleanupJob) Description() string
Description is the human readable description of the job.
func (*OrphanedHostCleanupJob) Name ¶
func (r *OrphanedHostCleanupJob) Name() string
Name is the unique name of the job.
func (*OrphanedHostCleanupJob) NextRunIn ¶
NextRunIn returns the default run frequency of the cleanup job.
func (*OrphanedHostCleanupJob) Run ¶
func (r *OrphanedHostCleanupJob) Run(ctx context.Context) error
Run queries the plugin host repo hosts with no memberships, it then deletes those hosts. Can not be run in parallel, if Run is invoked while already running an error with code JobAlreadyRunning will be returned.
func (*OrphanedHostCleanupJob) Status ¶
func (r *OrphanedHostCleanupJob) Status() scheduler.JobStatus
Status returns the current status of the set sync job. Total is the total number of sets that are to be synced. Completed is the number of sets already synced.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
A Repository stores and retrieves the persistent types in the plugin package. It is not safe to use a repository concurrently.
func NewRepository ¶
func NewRepository(ctx context.Context, r db.Reader, w db.Writer, kms *kms.Kms, sched *scheduler.Scheduler, plgm map[string]plgpb.HostPluginServiceClient, opt ...host.Option) (*Repository, error)
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) CreateCatalog ¶
func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, _ ...Option) (*HostCatalog, *plg.Plugin, error)
CreateCatalog inserts c into the repository and returns a new HostCatalog containing the catalog's PublicId. c must contain a valid ProjectID and PluginID. c must not contain a PublicId. The PublicId is generated and assigned by this method. opt is ignored.
c.Secret, c.Name and c.Description are optional. If c.Name is set, it must be unique within c.ProjectId. If c.Secret is set, it will be stored encrypted but not included in the returned *HostCatalog.
Both c.CreateTime and c.UpdateTime are ignored.
func (*Repository) CreateSet ¶
func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet, _ ...Option) (*HostSet, *plugin.Plugin, 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 catalog 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, projectId string, publicId string, _ ...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) Endpoints ¶
Endpoints provides all the endpoints available for a given set id. An error is returned if the set, related catalog, or related plugin are unable to be retrieved. If a host does not contain an addressible endpoint it is not included in the resulting slice of endpoints.
func (*Repository) ListCatalogs ¶
func (r *Repository) ListCatalogs(ctx context.Context, projectIds []string, opt ...host.Option) ([]*HostCatalog, []*plg.Plugin, error)
ListCatalogs returns a slice of HostCatalogs for the project IDs. WithLimit is the only option supported.
func (*Repository) ListHostsByCatalogId ¶
func (r *Repository) ListHostsByCatalogId(ctx context.Context, catalogId string, opt ...Option) ([]*Host, *plugin.Plugin, error)
ListHostsByCatalogId returns a slice of Hosts for the catalogId. WithLimit is the only option supported.
func (*Repository) ListHostsBySetIds ¶
func (r *Repository) ListHostsBySetIds(ctx context.Context, setIds []string, opt ...Option) ([]*Host, error)
ListHostsBySetId returns a slice of Hosts for the given set IDs. WithLimit is the only option supported.
func (*Repository) ListSets ¶
func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...host.Option) ([]*HostSet, *plugin.Plugin, 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, _ ...Option) (*HostCatalog, *plg.Plugin, error)
LookupCatalog returns the HostCatalog for id. Returns nil, nil if no HostCatalog is found for id.
func (*Repository) LookupHost ¶
func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, *plugin.Plugin, error)
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, _ ...host.Option) (*HostSet, *plugin.Plugin, error)
LookupSet will look up a host set in the repository and return the host set, as well as host IDs that match. If the host set is not found, it will return nil, nil, nil. No options are currently supported.
func (*Repository) UpdateCatalog ¶
func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, _ ...Option) (*HostCatalog, *plg.Plugin, 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. c.Name, c.Description, and c.Attributes can be updated; if c.Secrets is present, its contents are sent to the plugin (along with any other changes, see below) before the update is sent to the database.
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. Note that this does not apply to c.Attributes - a null c.Attributes is a no-op for modifications. Rather, if fields need to be reset, its field in c.Attributes should individually set to null.
Updates are sent to OnUpdateCatalog with a full copy of both the current catalog, and the state of the new catalog should it be updated, along with any secrets included in the new request. This request may alter the returned persisted state. Update of the record in the database is aborted if this call fails.
func (*Repository) UpdateSet ¶
func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet, version uint32, fieldMask []string, opt ...Option) (*HostSet, []*Host, *plugin.Plugin, int, error)
UpdateSet updates the repository for host set entry s with the values populated, for the fields listed in fieldMask. It returns a new HostSet containing the updated values, the hosts in the set, and a count of the number of records updated. s is not changed.
s must contain a valid PublicId and CatalogId. Name, Description, Attributes, and PreferredEndpoints can be updated. Name must be unique among all sets associated with a single catalog.
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 fieldMask. Note that this does not apply to s.Attributes - a null s.Attributes is a no-op for modifications. Rather, if fields need to be reset, its field in c.Attributes should individually set to null.
Updates are sent to OnUpdateSet with a full copy of both the current set, the state of the new set should it be updated, along with its parent host catalog and persisted state (can include secrets). This is a stateless call and does not affect the final record written, but some plugins may perform some actions on this call. Update of the record in the database is aborted if this call fails.
type SetSyncJob ¶
type SetSyncJob struct {
// contains filtered or unexported fields
}
SetSyncJob is the recurring job that syncs hosts from sets that are. The SetSyncJob is not thread safe, an attempt to Run the job concurrently will result in an JobAlreadyRunning error.
func (*SetSyncJob) Description ¶
func (r *SetSyncJob) Description() string
Description is the human readable description of the job.
func (*SetSyncJob) NextRunIn ¶
NextRunIn queries the plugin host set db to determine when the next set should be synced.
func (*SetSyncJob) Run ¶
func (r *SetSyncJob) Run(ctx context.Context) error
Run queries the plugin host repo for sets that need to be synced, it then creates a plugin client and syncs each set. Can not be run in parallel, if Run is invoked while already running an error with code JobAlreadyRunning will be returned.
func (*SetSyncJob) Status ¶
func (r *SetSyncJob) Status() scheduler.JobStatus
Status returns the current status of the set sync job. Total is the total number of sets that are to be synced. Completed is the number of sets already synced.