feat(host): Add host plugin related schemas and tests (#1475)

* feat(host): Add host plugin related schemas and tests

This adds the schema files for host plugins, plugin based catalogs and
plugin based sets.  This also adds the protos and tests which utilize
gorm to ensure the schemas enforce the constraints we expect.

Along with this change was a migration which moved catalog names to the
base type table so we can ensure all catalogs in a single scope,
regardless of subtype, have a unique name.

* Updated plugin schemas to do the following:
- Add plugin_executable table
- plugin table now also has scope_id and name w/ uniqueness constraints
- host_plugin no longer has id_prefix column
- host_plugin separates name and plugin_name
- plugin_version table renamed version to symantic_version column.

* Fix typo in delete_plugin_subtype trigger.  Add update test for host plugins.

* Update id prefixes. Fix public_id typos in protos and plugin_executable name in sql diagrams.

* Created internal/plugin and moved base plugin structs to it and moved host plugin subdirectory to it.

* Created internal/plugin and moved base plugin structs to it and moved host plugin subdirectory to it.

* Add first pass at enums for OS and Arch supported by plugin executables.

* Capitalizing the const enums for OS and Architectures.

* Add comments to sql files.

* Reviewer comments.

Remove unsupported OSes and Archs from SQL and go constants.
Add missing tests.

* Be more permissive in the values the db accepts.

The go logic can restrict which values it will allow getting populated into the db.

* Removing constraints on which values can be placed inside operating_system and architecture columns.

* Updating test helper functions to only create a single catalog or set.

* Move files to new migration version.

* Fixing job/plugin test.

* Update table names, named a number of constraints, remove plugin version and executable tables.

* Add constraints for plugin name and id prefix.

* Rename constraint, remove unhelpful comment block.

* Adding semantic version to plugin_host and set attributes to not null.

* Remove semantic versioning from all locations.

* Remove semantic_version from plugin_host table comment.

* Fix op copy/paste error. Don't use deprecated errors methods. Update constraint names.  Add docs.

* Apply suggestions from code review

Fixing constraint names.

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
This commit is contained in:
Todd KnightandMichael Gaffney authored and GitHub committed 2021-09-08 10:06:38 -07:00
1 parent 71cba858e3
commit db9e1106a9
39 files changed
+3987 -4

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
// Package plugin contains other packages related to the different plugin
// types and any helpers related to working with non type specific plugins.
package plugin
+4
View File
@@ -0,0 +1,4 @@
// Package host provides a plugin type used to interface with boundary's host
// related resources. Additionally it provides a repository for performing
// CRUDL and custom operations on this plugin type.
package host
+19
View File
@@ -0,0 +1,19 @@
package host
import (
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
)
// PublicId prefixes for the resources in the plugin package.
const (
PluginPrefix = "plgh"
)
func newPluginId() (string, error) {
id, err := db.NewPublicId(PluginPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "plugin.newPluginId")
}
return id, nil
}
@@ -0,0 +1,85 @@
package host
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
func TestHostPlugin_ImmutableFields(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
w := db.New(conn)
ts := timestamp.Timestamp{Timestamp: &timestamppb.Timestamp{Seconds: 0, Nanos: 0}}
plg := TestPlugin(t, conn, "test", "prefix")
newPlugin := plg
tests := []struct {
name string
update *Plugin
fieldMask []string
}{
{
name: "public_id",
update: func() *Plugin {
c := newPlugin.testClonePlugin()
c.PublicId = "hc_thisIsNotAValidId"
return c
}(),
fieldMask: []string{"PublicId"},
},
{
name: "create time",
update: func() *Plugin {
c := newPlugin.testClonePlugin()
c.CreateTime = &ts
return c
}(),
fieldMask: []string{"CreateTime"},
},
{
name: "pluginName",
update: func() *Plugin {
c := newPlugin.testClonePlugin()
c.PluginName = "different pluginName"
return c
}(),
fieldMask: []string{"PluginName"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orig := newPlugin.testClonePlugin()
err := w.LookupById(context.Background(), orig)
require.NoError(err)
rowsUpdated, err := w.Update(context.Background(), tt.update, tt.fieldMask, nil, db.WithSkipVetForWrite(true))
require.Error(err)
assert.Equal(0, rowsUpdated)
after := newPlugin.testClonePlugin()
err = w.LookupById(context.Background(), after)
require.NoError(err)
assert.True(proto.Equal(orig, after))
})
}
}
func (c *Plugin) testClonePlugin() *Plugin {
cp := proto.Clone(c.Plugin)
return &Plugin{
Plugin: cp.(*store.Plugin),
}
}
+50
View File
@@ -0,0 +1,50 @@
package host
// getOpts - iterate the inbound Options and return a struct
func getOpts(opt ...Option) options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// Option - how Options are passed as arguments.
type Option func(*options)
// options = how options are represented
type options struct {
withName string
withDescription string
withLimit int
}
func getDefaultOptions() options {
return options{
withDescription: "",
withName: "",
}
}
// WithDescription provides an optional description.
func WithDescription(desc string) Option {
return func(o *options) {
o.withDescription = desc
}
}
// WithName provides an optional name.
func WithName(name string) Option {
return func(o *options) {
o.withName = name
}
}
// 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 WithLimit(l int) Option {
return func(o *options) {
o.withLimit = l
}
}
+29
View File
@@ -0,0 +1,29 @@
package host
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_GetOpts(t *testing.T) {
t.Parallel()
t.Run("WithName", func(t *testing.T) {
opts := getOpts(WithName("test"))
testOpts := getDefaultOptions()
testOpts.withName = "test"
assert.Equal(t, opts, testOpts)
})
t.Run("WithDescription", func(t *testing.T) {
opts := getOpts(WithDescription("test desc"))
testOpts := getDefaultOptions()
testOpts.withDescription = "test desc"
assert.Equal(t, opts, testOpts)
})
t.Run("WithLimit", func(t *testing.T) {
opts := getOpts(WithLimit(5))
testOpts := getDefaultOptions()
testOpts.withLimit = 5
assert.Equal(t, opts, testOpts)
})
}
+43
View File
@@ -0,0 +1,43 @@
package host
import (
"github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/hashicorp/boundary/internal/types/scope"
)
// A Plugin enables additional logic to be used by boundary.
// It is owned by a scope.
type Plugin struct {
*store.Plugin
tableName string `gorm:"-"`
}
// NewPlugin creates a new in memory Plugin assigned to the global scope.
// Name, Description are the only allowed option. All other options are ignored.
func NewPlugin(pluginName, idPrefix string, opt ...Option) *Plugin {
opts := getOpts(opt...)
p := &Plugin{
Plugin: &store.Plugin{
PluginName: pluginName,
IdPrefix: idPrefix,
ScopeId: scope.Global.String(),
Name: opts.withName,
Description: opts.withDescription,
},
}
return p
}
// TableName returns the table name for the host plugin.
func (c *Plugin) TableName() string {
if c.tableName != "" {
return c.tableName
}
return "plugin_host"
}
// SetTableName sets the table name. If the caller attempts to
// set the name to "" the name will be reset to the default name.
func (c *Plugin) SetTableName(n string) {
c.tableName = n
}
+275
View File
@@ -0,0 +1,275 @@
package host
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/host/store"
)
func TestPlugin_Create(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
type args struct {
pluginName string
idPrefix string
semVer string
opts []Option
}
tests := []struct {
name string
args args
want *Plugin
wantErr bool
}{
{
name: "blank-pluginName",
args: args{
idPrefix: "prefix",
},
want: &Plugin{
Plugin: &store.Plugin{
IdPrefix: "prefix",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "blank-idPrefix",
args: args{
pluginName: "plugin name",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "plugin name",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "idprefix-capitalized",
args: args{
pluginName: "idprefixcapitalized",
idPrefix: "IdPrefixCapitalized",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "idprefixcapitalized",
IdPrefix: "IdPrefixCapitalized",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "idprefix-space",
args: args{
pluginName: "idprefix space",
idPrefix: "idprefix space",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "idprefix space",
IdPrefix: "idprefix space",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "pluginName-capitalized",
args: args{
pluginName: "PluginNameCapitalized",
idPrefix: "pluginnamecapitalized",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "PluginNameCapitalized",
IdPrefix: "pluginnamecapitalized",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "valid-no-options",
args: args{
pluginName: "validnooptions",
idPrefix: "validnooptions",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "validnooptions",
IdPrefix: "validnooptions",
ScopeId: scope.Global.String(),
},
},
},
{
name: "valid-with-description",
args: args{
pluginName: "validwithdescription",
idPrefix: "validwithdescription",
opts: []Option{
WithDescription("description"),
},
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "validwithdescription",
IdPrefix: "validwithdescription",
ScopeId: scope.Global.String(),
Description: "description",
},
},
},
{
name: "valid-pluginName-name-option",
args: args{
pluginName: "validpluginnamenameoption",
idPrefix: "validpluginnamenameoption",
opts: []Option{
WithName("valid-pluginName-name-option"),
WithDescription("description"),
},
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "validpluginnamenameoption",
IdPrefix: "validpluginnamenameoption",
ScopeId: scope.Global.String(),
Name: "valid-pluginName-name-option",
Description: "description",
},
},
},
// This must be run after the "valid-no-options" test
{
name: "duplicate-pluginName",
args: args{
pluginName: "validnooptions",
idPrefix: "duplicatepluginname",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "validnooptions",
IdPrefix: "duplicatepluginname",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
{
name: "duplicate-idPrefix",
args: args{
pluginName: "duplicateidprefix",
idPrefix: "validnooptions",
},
want: &Plugin{
Plugin: &store.Plugin{
PluginName: "duplicateidprefix",
IdPrefix: "validnooptions",
ScopeId: scope.Global.String(),
},
},
wantErr: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got := NewPlugin(tt.args.pluginName, tt.args.idPrefix, tt.args.opts...)
require.NotNil(t, got)
require.Emptyf(t, got.PublicId, "PublicId set")
id, err := newPluginId()
require.NoError(t, err)
got.PublicId = id
tt.want.PublicId = id
assert.Equal(t, tt.want, got)
w := db.New(conn)
err = w.Create(context.Background(), got)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestPlugin_Update(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
w := db.New(conn)
ctx := context.Background()
plg := TestPlugin(t, conn, "delete-plugin", "prefix")
assert.Equal(t, uint32(1), plg.Version)
plg.Name = "New"
plg.Description = "Description"
rowCount, err := w.Update(ctx, plg, []string{"Name", "Description"}, nil)
require.NoError(t, err)
assert.Equal(t, 1, rowCount)
assert.Equal(t, uint32(2), plg.Version)
assert.Equal(t, "New", plg.Name)
assert.Equal(t, "Description", plg.Description)
}
func TestPlugin_Delete(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
w := db.New(conn)
ctx := context.Background()
plg := TestPlugin(t, conn, "delete-plugin", "prefix")
deleted, err := w.Delete(ctx, plg)
require.NoError(t, err)
require.Equal(t, 1, deleted)
}
func TestPlugin_SetTableName(t *testing.T) {
defaultTableName := "plugin_host"
tests := []struct {
name string
initialName string
setNameTo string
want string
}{
{
name: "new-pluginName",
initialName: "",
setNameTo: "new-pluginName",
want: "new-pluginName",
},
{
name: "reset to default",
initialName: "initial",
setNameTo: "",
want: defaultTableName,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
def := NewPlugin("", "prefix")
require.Equal(defaultTableName, def.TableName())
s := &Plugin{
Plugin: &store.Plugin{},
tableName: tt.initialName,
}
s.SetTableName(tt.setNameTo)
assert.Equal(tt.want, s.TableName())
})
}
}
+267
View File
@@ -0,0 +1,267 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.15.8
// source: controller/storage/plugin/host/store/v1/plugin.proto
// Package store provides protobufs for storing types in the host package.
package store
import (
timestamp "github.com/hashicorp/boundary/internal/db/timestamp"
_ "github.com/hashicorp/boundary/sdk/pbs/controller/protooptions"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Plugin struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// public_id is a surrogate key suitable for use in a public API.
// @inject_tag: `gorm:"primary_key"`
PublicId string `protobuf:"bytes,10,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty" gorm:"primary_key"`
// The create_time is set by the database.
// @inject_tag: `gorm:"default:current_timestamp"`
CreateTime *timestamp.Timestamp `protobuf:"bytes,20,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"`
// The update_time is set by the database.
// @inject_tag: `gorm:"default:current_timestamp"`
UpdateTime *timestamp.Timestamp `protobuf:"bytes,30,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"`
// name is optional. If set, it must be unique within scope_id.
// @inject_tag: `gorm:"default:null"`
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
// description is optional.
// @inject_tag: `gorm:"default:null"`
Description string `protobuf:"bytes,50,opt,name=description,proto3" json:"description,omitempty" gorm:"default:null"`
// The scope_id of the owning scope and must be set.
// @inject_tag: `gorm:"not_null"`
ScopeId string `protobuf:"bytes,60,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty" gorm:"not_null"`
// @inject_tag: `gorm:"default:null"`
Version uint32 `protobuf:"varint,70,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"`
// plugin_name is required. The value must be unique across all host plugins
// @inject_tag: `gorm:"default:null"`
PluginName string `protobuf:"bytes,80,opt,name=plugin_name,json=pluginName,proto3" json:"plugin_name,omitempty" gorm:"default:null"`
// id_prefix is required. The value must be unique across all host plugins
// @inject_tag: `gorm:"default:null"`
IdPrefix string `protobuf:"bytes,90,opt,name=id_prefix,json=idPrefix,proto3" json:"id_prefix,omitempty" gorm:"default:null"`
}
func (x *Plugin) Reset() {
*x = Plugin{}
if protoimpl.UnsafeEnabled {
mi := &file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Plugin) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Plugin) ProtoMessage() {}
func (x *Plugin) ProtoReflect() protoreflect.Message {
mi := &file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Plugin.ProtoReflect.Descriptor instead.
func (*Plugin) Descriptor() ([]byte, []int) {
return file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescGZIP(), []int{0}
}
func (x *Plugin) GetPublicId() string {
if x != nil {
return x.PublicId
}
return ""
}
func (x *Plugin) GetCreateTime() *timestamp.Timestamp {
if x != nil {
return x.CreateTime
}
return nil
}
func (x *Plugin) GetUpdateTime() *timestamp.Timestamp {
if x != nil {
return x.UpdateTime
}
return nil
}
func (x *Plugin) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Plugin) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *Plugin) GetScopeId() string {
if x != nil {
return x.ScopeId
}
return ""
}
func (x *Plugin) GetVersion() uint32 {
if x != nil {
return x.Version
}
return 0
}
func (x *Plugin) GetPluginName() string {
if x != nil {
return x.PluginName
}
return ""
}
func (x *Plugin) GetIdPrefix() string {
if x != nil {
return x.IdPrefix
}
return ""
}
var File_controller_storage_plugin_host_store_v1_plugin_proto protoreflect.FileDescriptor
var file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc = []byte{
0x0a, 0x34, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, 0x6f,
0x72, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x68, 0x6f, 0x73, 0x74,
0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x27, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c,
0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x1a,
0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, 0x6f, 0x72,
0x61, 0x67, 0x65, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2f, 0x76, 0x31,
0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x1a, 0x2a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x63, 0x75, 0x73,
0x74, 0x6f, 0x6d, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9a, 0x03, 0x0a,
0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69,
0x63, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c,
0x69, 0x63, 0x49, 0x64, 0x12, 0x4b, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74,
0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74,
0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d,
0x65, 0x12, 0x4b, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65,
0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x24,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x10, 0xc2, 0xdd,
0x29, 0x0c, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x40, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x18, 0x32, 0x20, 0x01, 0x28, 0x09, 0x42, 0x1e, 0xc2, 0xdd, 0x29, 0x1a, 0x0a,
0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x64, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f,
0x69, 0x64, 0x18, 0x3c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x49,
0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x46, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x70,
0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x50, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0a, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09,
0x69, 0x64, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x5a, 0x20, 0x01, 0x28, 0x09, 0x52,
0x08, 0x69, 0x64, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74,
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72,
0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72,
0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x68, 0x6f, 0x73, 0x74, 0x2f,
0x73, 0x74, 0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescOnce sync.Once
file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData = file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc
)
func file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescGZIP() []byte {
file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescOnce.Do(func() {
file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData)
})
return file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData
}
var file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes = []interface{}{
(*Plugin)(nil), // 0: controller.storage.plugin.host.store.v1.Plugin
(*timestamp.Timestamp)(nil), // 1: controller.storage.timestamp.v1.Timestamp
}
var file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs = []int32{
1, // 0: controller.storage.plugin.host.store.v1.Plugin.create_time:type_name -> controller.storage.timestamp.v1.Timestamp
1, // 1: controller.storage.plugin.host.store.v1.Plugin.update_time:type_name -> controller.storage.timestamp.v1.Timestamp
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_controller_storage_plugin_host_store_v1_plugin_proto_init() }
func file_controller_storage_plugin_host_store_v1_plugin_proto_init() {
if File_controller_storage_plugin_host_store_v1_plugin_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Plugin); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes,
DependencyIndexes: file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs,
MessageInfos: file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes,
}.Build()
File_controller_storage_plugin_host_store_v1_plugin_proto = out.File
file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc = nil
file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes = nil
file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs = nil
}
+22
View File
@@ -0,0 +1,22 @@
package host
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/require"
)
func TestPlugin(t *testing.T, conn *gorm.DB, name string, prefix string) *Plugin {
t.Helper()
p := NewPlugin(name, prefix)
id, err := newPluginId()
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
return p
}
+18
View File
@@ -0,0 +1,18 @@
package host
import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_TestPlugins(t *testing.T) {
assert, require := assert.New(t), require.New(t)
conn, _ := db.TestSetup(t, "postgres")
plg := TestPlugin(t, conn, "test", "prefix")
require.NotNil(plg)
assert.NotEmpty(plg.GetPublicId())
}
+72
View File
@@ -0,0 +1,72 @@
package plugin
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
func TestPlugin_ImmutableFields(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
w := db.New(conn)
plg := testPlugin(t, conn, "test")
newPlugin := plg
tests := []struct {
name string
update *plugin
fieldMask []string
}{
{
name: "public_id",
update: func() *plugin {
c := newPlugin.testClonePlugin()
c.PublicId = "pi_thisIsNotAValidId"
return c
}(),
fieldMask: []string{"PublicId"},
},
{
name: "scope",
update: func() *plugin {
c := newPlugin.testClonePlugin()
c.ScopeId = "o_1234567890"
return c
}(),
fieldMask: []string{"ScopeId"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orig := newPlugin.testClonePlugin()
err := w.LookupById(context.Background(), orig)
require.NoError(err)
rowsUpdated, err := w.Update(context.Background(), tt.update, tt.fieldMask, nil, db.WithSkipVetForWrite(true))
require.Error(err)
assert.Equal(0, rowsUpdated)
after := newPlugin.testClonePlugin()
err = w.LookupById(context.Background(), after)
require.NoError(err)
assert.True(proto.Equal(orig, after))
})
}
}
func (c *plugin) testClonePlugin() *plugin {
cp := proto.Clone(c.Plugin)
return &plugin{
Plugin: cp.(*store.Plugin),
}
}
+182
View File
@@ -0,0 +1,182 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.15.8
// source: controller/storage/plugin/store/v1/plugin.proto
// Package store provides protobufs for storing types in the host package.
package store
import (
_ "github.com/hashicorp/boundary/internal/db/timestamp"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a typeless plugin. In practice this should never be used directly.
// This is included for testing purposes only.
type Plugin struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// public_id is a surrogate key suitable for use in a public API.
// @inject_tag: `gorm:"primary_key"`
PublicId string `protobuf:"bytes,10,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty" gorm:"primary_key"`
// The scope_id of the owning scope and must be set.
// @inject_tag: `gorm:"not_null"`
ScopeId string `protobuf:"bytes,20,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty" gorm:"not_null"`
// name is optional. If set, it must be unique within scope_id.
// @inject_tag: `gorm:"default:null"`
Name string `protobuf:"bytes,30,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
}
func (x *Plugin) Reset() {
*x = Plugin{}
if protoimpl.UnsafeEnabled {
mi := &file_controller_storage_plugin_store_v1_plugin_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Plugin) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Plugin) ProtoMessage() {}
func (x *Plugin) ProtoReflect() protoreflect.Message {
mi := &file_controller_storage_plugin_store_v1_plugin_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Plugin.ProtoReflect.Descriptor instead.
func (*Plugin) Descriptor() ([]byte, []int) {
return file_controller_storage_plugin_store_v1_plugin_proto_rawDescGZIP(), []int{0}
}
func (x *Plugin) GetPublicId() string {
if x != nil {
return x.PublicId
}
return ""
}
func (x *Plugin) GetScopeId() string {
if x != nil {
return x.ScopeId
}
return ""
}
func (x *Plugin) GetName() string {
if x != nil {
return x.Name
}
return ""
}
var File_controller_storage_plugin_store_v1_plugin_proto protoreflect.FileDescriptor
var file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = []byte{
0x0a, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, 0x6f,
0x72, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x72,
0x65, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74,
0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x73, 0x74, 0x6f,
0x72, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
0x72, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74,
0x61, 0x6d, 0x70, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x54, 0x0a, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e,
0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x19, 0x0a,
0x08, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x3b, 0x5a, 0x39,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69,
0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x73, 0x74,
0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (
file_controller_storage_plugin_store_v1_plugin_proto_rawDescOnce sync.Once
file_controller_storage_plugin_store_v1_plugin_proto_rawDescData = file_controller_storage_plugin_store_v1_plugin_proto_rawDesc
)
func file_controller_storage_plugin_store_v1_plugin_proto_rawDescGZIP() []byte {
file_controller_storage_plugin_store_v1_plugin_proto_rawDescOnce.Do(func() {
file_controller_storage_plugin_store_v1_plugin_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_storage_plugin_store_v1_plugin_proto_rawDescData)
})
return file_controller_storage_plugin_store_v1_plugin_proto_rawDescData
}
var file_controller_storage_plugin_store_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_controller_storage_plugin_store_v1_plugin_proto_goTypes = []interface{}{
(*Plugin)(nil), // 0: controller.storage.plugin.store.v1.Plugin
}
var file_controller_storage_plugin_store_v1_plugin_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_controller_storage_plugin_store_v1_plugin_proto_init() }
func file_controller_storage_plugin_store_v1_plugin_proto_init() {
if File_controller_storage_plugin_store_v1_plugin_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_controller_storage_plugin_store_v1_plugin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Plugin); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_controller_storage_plugin_store_v1_plugin_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_controller_storage_plugin_store_v1_plugin_proto_goTypes,
DependencyIndexes: file_controller_storage_plugin_store_v1_plugin_proto_depIdxs,
MessageInfos: file_controller_storage_plugin_store_v1_plugin_proto_msgTypes,
}.Build()
File_controller_storage_plugin_store_v1_plugin_proto = out.File
file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = nil
file_controller_storage_plugin_store_v1_plugin_proto_goTypes = nil
file_controller_storage_plugin_store_v1_plugin_proto_depIdxs = nil
}
+55
View File
@@ -0,0 +1,55 @@
package plugin
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/require"
)
// A typeless plugin used for tests.
type plugin struct {
*store.Plugin
tableName string `gorm:"-"`
}
// newPlugin is used in tests and creates a typeless plugin in the global scope.
func newPlugin(name string) *plugin {
p := &plugin{
Plugin: &store.Plugin{
ScopeId: scope.Global.String(),
Name: name,
},
}
return p
}
// TableName returns the table name for the host plugin.
func (c *plugin) TableName() string {
if c.tableName != "" {
return c.tableName
}
return "plugin"
}
// SetTableName sets the table name. If the caller attempts to
// set the name to "" the name will be reset to the default name.
func (c *plugin) SetTableName(n string) {
c.tableName = n
}
func testPlugin(t *testing.T, conn *gorm.DB, name string) *plugin {
t.Helper()
p := newPlugin(name)
id, err := db.NewPublicId("plg")
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
return p
}
+18
View File
@@ -0,0 +1,18 @@
package plugin
import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_testPlugin(t *testing.T) {
assert, require := assert.New(t), require.New(t)
conn, _ := db.TestSetup(t, "postgres")
plg := testPlugin(t, conn, "test")
require.NotNil(plg)
assert.NotEmpty(plg.GetPublicId())
}