plugin

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2022 License: MPL-2.0 Imports: 43 Imported by: 0

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

View Source
const (
	HostCatalogPrefix = "hc"
	HostSetPrefix     = "hs"
	HostPrefix        = "h"

	Subtype = subtypes.Subtype("plugin")
)

PublicId prefixes for the resources in the plugin package.

Variables

This section is empty.

Functions

func NewLoopbackPlugin

func NewLoopbackPlugin() plgpb.HostPluginServiceServer

NewLoopbackPlugin returns a new loopback plugin

func RegisterJobs

func RegisterJobs(ctx context.Context, scheduler *scheduler.Scheduler, r db.Reader, w db.Writer, kms *kms.Kms, plgm map[string]plgpb.HostPluginServiceClient) error

RegisterJobs registers plugin host related jobs with the provided scheduler.

func TestRunSetSync

func TestRunSetSync(t *testing.T, conn *db.DB, kmsCache *kms.Kms, plgm map[string]plgpb.HostPluginServiceClient)

TestRunSetSync runs the set sync job a single time.

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

func NewHost(ctx context.Context, catalogId, externalId string, opt ...Option) *Host

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.T, catalog *HostCatalog, setIds []string, count int) ([]*plgpb.ListHostsResponseHost, []*Host)

func TestHost

func TestHost(t *testing.T, conn *db.DB, catId, externId string, opt ...Option) *Host

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

func (h *Host) GetAddress() string

For compatibility with the general Host type

func (*Host) GetSetIds added in v0.7.5

func (h *Host) GetSetIds() []string

GetSetIds returns host set ids

func (*Host) SetTableName

func (s *Host) 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 (*Host) TableName

func (s *Host) TableName() string

TableName returns the table name for the host set.

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 scope.

func NewHostCatalog

func NewHostCatalog(ctx context.Context, scopeId, pluginId string, opt ...Option) (*HostCatalog, error)

NewHostCatalog creates a new in memory HostCatalog assigned to a scopeId and pluginId. Name and description are the only valid options. All other options are ignored.

func TestCatalog

func TestCatalog(t *testing.T, conn *db.DB, scopeId, pluginId string, opt ...Option) *HostCatalog

TestCatalog creates a plugin 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 TestCatalogs

func TestCatalogs(t *testing.T, conn *db.DB, scopeId, pluginId string, count int) []*HostCatalog

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 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

func NewHostSet(ctx context.Context, catalogId string, opt ...Option) (*HostSet, error)

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.T, 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

func (s *HostSet) 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 (*HostSet) TableName

func (s *HostSet) TableName() string

TableName returns the table name for the host set.

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

func TestSetMembers(t *testing.T, conn *db.DB, setId string, hosts []*Host) []*HostSetMember

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.

func (*HostSetMember) VetForWrite

func (m *HostSetMember) VetForWrite(ctx context.Context, _ db.Reader, _ db.OpType, _ ...db.Option) error

VetForWrite implements db.VetForWrite() interface for host set members.

type Option

type Option func(*options)

Option - how Options are passed as arguments.

func WithAttributes

func WithAttributes(attrs *structpb.Struct) Option

WithAttributes provides an optional attributes field.

func WithDescription

func WithDescription(desc string) Option

WithDescription provides an optional description.

func WithLimit

func WithLimit(l int) Option

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 WithName

func WithName(name string) Option

WithName provides an optional name.

func WithPreferredEndpoints

func WithPreferredEndpoints(with []string) Option

WithPreferredEndpoints provides an optional preferred endpoints field.

func WithPublicId

func WithPublicId(with string) Option

WithPublicId provides an optional public id.

func WithSecrets

func WithSecrets(secrets *structpb.Struct) Option

WithSecrets provides an optional secrets field.

func WithSecretsHmac

func WithSecretsHmac(secretsHmac []byte) Option

WithSecretsHmac provides an optional HMAC of secrets. Used for testing.

func WithSetIds

func WithSetIds(with []string) Option

WithSetIds provides the ability to restrict lookups to particular matching sets.

func WithSyncIntervalSeconds

func WithSyncIntervalSeconds(with int32) Option

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

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

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(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, *hostplugin.Plugin, error)

CreateCatalog inserts c into the repository and returns a new HostCatalog containing the catalog's PublicId. c must contain a valid ScopeID 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.ScopeID. 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, scopeId string, s *HostSet, _ ...Option) (*HostSet, *hostplugin.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

func (r *Repository) DeleteCatalog(ctx context.Context, id string, _ ...Option) (int, error)

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, scopeId 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

func (r *Repository) Endpoints(ctx context.Context, setIds []string) ([]*host.Endpoint, error)

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, scopeIds []string, opt ...host.Option) ([]*HostCatalog, []*hostplugin.Plugin, error)

ListCatalogs returns a slice of HostCatalogs for the scope IDs. WithLimit is the only option supported.

func (*Repository) ListHostsByCatalogId

func (r *Repository) ListHostsByCatalogId(ctx context.Context, catalogId string, opt ...Option) ([]*Host, *hostplugin.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, *hostplugin.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, *hostplugin.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, *hostplugin.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, *hostplugin.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, *hostplugin.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, scopeId string, s *HostSet, version uint32, fieldMask []string, opt ...Option) (*HostSet, []*Host, *hostplugin.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) Name

func (r *SetSyncJob) Name() string

Name is the unique name of the job.

func (*SetSyncJob) NextRunIn

func (r *SetSyncJob) NextRunIn(ctx context.Context) (time.Duration, error)

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.

type TestPluginServer

TestPluginServer provides a host plugin service server where each method can be overwritten for tests.

func (TestPluginServer) ListHosts

func (TestPluginServer) OnCreateCatalog

func (TestPluginServer) OnCreateSet

func (TestPluginServer) OnDeleteCatalog

func (TestPluginServer) OnDeleteSet

func (TestPluginServer) OnUpdateCatalog

func (TestPluginServer) OnUpdateSet

type WrappingPluginClient

type WrappingPluginClient struct {
	Server plgpb.HostPluginServiceServer
}

WrappingPluginClient provides a wrapper around a Server implementation that can be used when loading a plugin in-memory

func (*WrappingPluginClient) ListHosts

func (*WrappingPluginClient) OnCreateCatalog

func (*WrappingPluginClient) OnCreateSet

func (*WrappingPluginClient) OnDeleteCatalog

func (*WrappingPluginClient) OnDeleteSet

func (*WrappingPluginClient) OnUpdateCatalog

func (*WrappingPluginClient) OnUpdateSet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL