Placeholder Plugin Providers for Repos and added testPlugin struct (#1532)

* Create minimalistic plugin map and test plugin.

* Pass secrets and attributes to the plugin when creating catalogs or sets.  Add tests for CreateSet and CreateCatalog repo methods.

* make fmt and extract out getPrivateCatalog and getCatalog helper methods.

* Exporting TestPluginServer so it can be used in the handlers.

* Keep separate persisted data from host catalogs lookups which facilitate passing it onto the plugins.

* Add TODO to merge get Catalog and get Persisted data.

* Adding tests for unimplemented being returned by the plugin.

* Use GetFields() instead of AsMap() to confirm attributes should be populated. Make clone consistent between catalog and sets.

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
This commit is contained in:
ToddandJeff Mitchell authored and GitHub committed 2021-09-21 09:18:49 -07:00
1 parent ea939a4445
commit bbfef2802f
30 files changed
+669 -227

No files matched your search

+11 -10
View File
@@ -2,7 +2,6 @@ package plugin
import (
"context"
"encoding/json"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/host/plugin/store"
@@ -22,23 +21,21 @@ type HostSet struct {
func NewHostSet(ctx context.Context, catalogId string, opt ...Option) (*HostSet, error) {
const op = "plugin.NewHostSet"
opts := getOpts(opt...)
attrs, err := proto.Marshal(opts.withAttributes)
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithCode(errors.InvalidParameter))
}
set := &HostSet{
HostSet: &store.HostSet{
CatalogId: catalogId,
Name: opts.withName,
Description: opts.withDescription,
Attributes: attrs,
PreferredEndpoints: opts.withPreferredEndpoints,
},
}
if opts.withAttributes != nil {
attrs, err := json.Marshal(opts.withAttributes)
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithCode(errors.InvalidParameter))
}
set.Attributes = attrs
}
return set, nil
}
@@ -64,9 +61,13 @@ func allocHostSet() *HostSet {
func (s *HostSet) clone() *HostSet {
cp := proto.Clone(s.HostSet)
return &HostSet{
hs := &HostSet{
HostSet: cp.(*store.HostSet),
}
if s.Attributes != nil && len(s.Attributes) == 0 && hs.Attributes == nil {
hs.Attributes = []byte{}
}
return hs
}
func (s *HostSet) oplog(op oplog.OpType) oplog.Metadata {