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

+15 -16
View File
@@ -5,12 +5,12 @@ package plugin
import (
"context"
"encoding/json"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/host/plugin/store"
"github.com/hashicorp/boundary/internal/oplog"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
)
// A HostCatalog contains plugin host sets. It is owned by
@@ -19,7 +19,7 @@ type HostCatalog struct {
*store.HostCatalog
tableName string `gorm:"-"`
secrets map[string]interface{} `gorm:"-"`
secrets *structpb.Struct `gorm:"-"`
}
// NewHostCatalog creates a new in memory HostCatalog assigned to a scopeId
@@ -28,23 +28,22 @@ type HostCatalog struct {
func NewHostCatalog(ctx context.Context, scopeId, pluginId string, opt ...Option) (*HostCatalog, error) {
const op = "plugin.NewHostCatalog"
opts := getOpts(opt...)
attrs, err := proto.Marshal(opts.withAttributes)
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithCode(errors.InvalidParameter))
}
hc := &HostCatalog{
HostCatalog: &store.HostCatalog{
ScopeId: scopeId,
PluginId: pluginId,
Name: opts.withName,
Description: opts.withDescription,
Attributes: attrs,
},
secrets: opts.withSecrets,
}
if opts.withAttributes != nil {
attrs, err := json.Marshal(opts.withAttributes)
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithCode(errors.InvalidParameter))
}
hc.Attributes = attrs
}
return hc, nil
}
@@ -58,16 +57,16 @@ func allocHostCatalog() *HostCatalog {
// secret. The secret shallow copied.
func (c *HostCatalog) clone() *HostCatalog {
cp := proto.Clone(c.HostCatalog)
newSecret := proto.Clone(c.secrets)
hc := &HostCatalog{
HostCatalog: cp.(*store.HostCatalog),
secrets: newSecret.(*structpb.Struct),
}
if c.secrets != nil {
newSecret := make(map[string]interface{}, len(c.secrets))
for k, v := range c.secrets {
newSecret[k] = v
}
hc.secrets = newSecret
// proto.Clone will convert slices with length and capacity of 0 to nil.
// Fix this since gorm treats empty slices differently than nil.
if c.Attributes != nil && len(c.Attributes) == 0 && hc.Attributes == nil {
hc.Attributes = []byte{}
}
return hc
}