merged commit for plugin rework, storage bucket sql and proto, storage bucket secret rewrapping, storage bucket repository

This commit is contained in:
Danielle Miu authored and Timothy Messier committed 2023-05-31 12:18:13 +00:00
1 parent 38723f8112
commit a4a14fc7fc
66 files changed
+2332 -980

No files matched your search

-7
View File
@@ -1,7 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// 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
@@ -1,79 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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")
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"},
},
}
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),
}
}
-246
View File
@@ -1,246 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.30.0
// protoc (unknown)
// 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"`
}
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
}
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,
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, 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, 0xdc, 0x02, 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, 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
}
-24
View File
@@ -1,24 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/stretchr/testify/require"
)
func TestPlugin(t testing.TB, conn *db.DB, name string) *Plugin {
t.Helper()
p := NewPlugin(WithName(name))
id, err := newPluginId()
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
return p
}
-21
View File
@@ -1,21 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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")
require.NotNil(plg)
assert.NotEmpty(plg.GetPublicId())
}
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"github.com/hashicorp/boundary/internal/db"
+15 -11
View File
@@ -8,42 +8,46 @@ import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
func TestPlugin_ImmutableFields(t *testing.T) {
func TestHostPlugin_ImmutableFields(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
w := db.New(conn)
plg := testPlugin(t, conn, "test")
ts := timestamp.Timestamp{Timestamp: &timestamppb.Timestamp{Seconds: 0, Nanos: 0}}
plg := TestPlugin(t, conn, "test")
newPlugin := plg
tests := []struct {
name string
update *plugin
update *Plugin
fieldMask []string
}{
{
name: "public_id",
update: func() *plugin {
update: func() *Plugin {
c := newPlugin.testClonePlugin()
c.PublicId = "pi_thisIsNotAValidId"
c.PublicId = "hc_thisIsNotAValidId"
return c
}(),
fieldMask: []string{"PublicId"},
},
{
name: "scope",
update: func() *plugin {
name: "create time",
update: func() *Plugin {
c := newPlugin.testClonePlugin()
c.ScopeId = "o_1234567890"
c.CreateTime = &ts
return c
}(),
fieldMask: []string{"ScopeId"},
fieldMask: []string{"CreateTime"},
},
}
for _, tt := range tests {
@@ -67,9 +71,9 @@ func TestPlugin_ImmutableFields(t *testing.T) {
}
}
func (c *plugin) testClonePlugin() *plugin {
func (c *Plugin) testClonePlugin() *Plugin {
cp := proto.Clone(c.Plugin)
return &plugin{
return &Plugin{
Plugin: cp.(*store.Plugin),
}
}
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) options {
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"testing"
@@ -1,15 +1,48 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"google.golang.org/protobuf/proto"
)
type PluginType int
const (
PluginTypeUnknown PluginType = 0
PluginTypeHost PluginType = 1
PluginTypeStorage PluginType = 2
)
type pluginHostSupported struct {
PublicId string `gorm:"primary_key"`
}
func (*pluginHostSupported) isPluginSupported() {}
func (*pluginHostSupported) TableName() string {
return "plugin_host_supported"
}
type pluginStorageSupported struct {
PublicId string `gorm:"primary_key"`
}
func (*pluginStorageSupported) isPluginSupported() {}
func (*pluginStorageSupported) TableName() string {
return "plugin_storage_supported"
}
// pluginSupportedTable is a special type created just to insert
// plugin flags in a safe way. the only structs that implement
// this should be above. new plugins should be added above.
type pluginSupportedTable interface {
isPluginSupported()
}
// A Plugin enables additional logic to be used by boundary.
// It is owned by a scope.
type Plugin struct {
@@ -36,7 +69,7 @@ func (c *Plugin) TableName() string {
if c.tableName != "" {
return c.tableName
}
return "plugin_host"
return "plugin"
}
// SetTableName sets the table name. If the caller attempts to
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"context"
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/hashicorp/boundary/internal/plugin/store"
)
func TestPlugin_Create(t *testing.T) {
@@ -121,7 +121,7 @@ func TestPlugin_Delete(t *testing.T) {
}
func TestPlugin_SetTableName(t *testing.T) {
defaultTableName := "plugin_host"
defaultTableName := "plugin"
tests := []struct {
name string
initialName string
@@ -1,12 +1,15 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"context"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/util"
)
// A Repository stores and retrieves the persistent types in the host
@@ -24,15 +27,15 @@ type Repository struct {
// 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 NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) {
func NewRepository(ctx context.Context, r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) {
const op = "static.NewRepository"
switch {
case r == nil:
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "db.Reader")
case w == nil:
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "db.Writer")
case kms == nil:
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "kms")
case util.IsNil(r):
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil db.Reader")
case util.IsNil(w):
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil db.Writer")
case util.IsNil(kms):
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil kms")
}
opts := GetOpts(opt...)
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"context"
@@ -17,27 +17,26 @@ import (
// CreatePlugin inserts p into the repository and returns a new
// Plugin containing the plugin's PublicId. p is not changed. p must
// contain a valid ScopeID. p must not contain a PublicId. The PublicId is
// generated and assigned by this method. opt is ignored.
// generated and assigned by this method, unless supplied by WithPublicId
//
// Both p.Name and p.Description are optional. If p.Name is set, it must be
// unique within p.ScopeID.
//
// Both p.CreateTime and c.UpdateTime are ignored.
// p.CreateTime, p.UpdateTime, and p.Version are ignored and populated on creation.
//
// Supported options: WithPublicId
func (r *Repository) CreatePlugin(ctx context.Context, p *Plugin, opt ...Option) (*Plugin, error) {
const op = "host.(Repository).CreatePlugin"
if p == nil {
const op = "plugin.(Repository).CreatePlugin"
switch {
case p == nil:
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil Plugin")
}
if p.Plugin == nil {
case p.Plugin == nil:
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil embedded Plugin")
}
if p.ScopeId == "" {
case p.ScopeId == "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "no scope id")
}
if p.ScopeId != scope.Global.String() {
case p.ScopeId != scope.Global.String():
return nil, errors.New(ctx, errors.InvalidParameter, op, "scope id is not 'global'")
}
if p.PublicId != "" {
case p.PublicId != "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "public id not empty")
}
p = p.clone()
@@ -73,7 +72,7 @@ func (r *Repository) CreatePlugin(ctx context.Context, p *Plugin, opt ...Option)
db.WithOplog(oplogWrapper, metadata),
)
if err != nil {
return errors.Wrap(ctx, err, op)
return err
}
return nil
},
@@ -91,7 +90,7 @@ func (r *Repository) CreatePlugin(ctx context.Context, p *Plugin, opt ...Option)
// LookupPlugin returns the Plugin for id. Returns nil, nil if no
// Plugin is found for id.
func (r *Repository) LookupPlugin(ctx context.Context, id string, _ ...Option) (*Plugin, error) {
const op = "host.(Repository).LookupPlugin"
const op = "plugin.(Repository).LookupPlugin"
if id == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "no public id")
}
@@ -109,7 +108,7 @@ func (r *Repository) LookupPlugin(ctx context.Context, id string, _ ...Option) (
// LookupPluginByName returns the Plugin for a given name. Returns nil, nil if no
// Plugin is found with that plugin name.
func (r *Repository) LookupPluginByName(ctx context.Context, name string, _ ...Option) (*Plugin, error) {
const op = "host.(Repository).LookupPluginByName"
const op = "plugin.(Repository).LookupPluginByName"
if name == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "no plugin name")
}
@@ -126,7 +125,7 @@ func (r *Repository) LookupPluginByName(ctx context.Context, name string, _ ...O
// ListPlugins returns a slice of Plugins for the scope IDs. WithLimit is the only option supported.
func (r *Repository) ListPlugins(ctx context.Context, scopeIds []string, opt ...Option) ([]*Plugin, error) {
const op = "host.(Repository).ListPlugins"
const op = "plugin.(Repository).ListPlugins"
if len(scopeIds) == 0 {
return nil, errors.New(ctx, errors.InvalidParameter, op, "no scope id")
}
@@ -143,3 +142,34 @@ func (r *Repository) ListPlugins(ctx context.Context, scopeIds []string, opt ...
}
return plugins, nil
}
// AddSupportFlag adds a flag in the database for the current plugin to specify that it is capable
// of that type's functions
func (r *Repository) AddSupportFlag(ctx context.Context, plugin *Plugin, flag PluginType) error {
const op = "plugin.(Repository).AddSupportFlag"
var p pluginSupportedTable
switch flag {
case PluginTypeHost:
p = &pluginHostSupported{
PublicId: plugin.GetPublicId(),
}
case PluginTypeStorage:
p = &pluginStorageSupported{
PublicId: plugin.GetPublicId(),
}
default:
return errors.New(ctx, errors.InvalidParameter, op, "plugin type does not exist")
}
if err := r.writer.Create(ctx, p, db.WithOnConflict(
&db.OnConflict{
Target: db.Columns{"public_id"},
Action: db.DoNothing(true),
},
)); err != nil {
return errors.Wrap(ctx, err, op)
}
return nil
}
@@ -1,10 +1,11 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"context"
"fmt"
"strings"
"testing"
@@ -12,7 +13,7 @@ import (
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -24,25 +25,54 @@ func TestRepository_CreatePlugin(t *testing.T) {
wrapper := db.TestWrapper(t)
iam.TestRepo(t, conn, wrapper)
kmsCache := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(rw, rw, kmsCache)
ctx := context.Background()
repo, err := NewRepository(ctx, rw, rw, kmsCache)
assert.NoError(t, err)
assert.NotNil(t, repo)
tests := []struct {
name string
in *Plugin
opts []Option
want *Plugin
wantIsErr errors.Code
name string
in *Plugin
opts []Option
want *Plugin
wantErr string
}{
{
name: "nil-plugin",
wantIsErr: errors.InvalidParameter,
name: "nil-plugin",
wantErr: "nil Plugin",
},
{
name: "nil-embedded-plugin",
in: &Plugin{},
wantIsErr: errors.InvalidParameter,
name: "nil-embedded-plugin",
in: &Plugin{},
wantErr: "nil embedded Plugin",
},
{
name: "no-scope-id",
in: &Plugin{
Plugin: &store.Plugin{
ScopeId: "",
},
},
wantErr: "no scope id",
},
{
name: "non-global-scope",
in: &Plugin{
Plugin: &store.Plugin{
ScopeId: "o_1234567890",
},
},
wantErr: "scope id is not 'global'",
},
{
name: "public-id-not-empty",
in: &Plugin{
Plugin: &store.Plugin{
PublicId: "biscuit",
ScopeId: "global",
},
},
wantErr: "public id not empty",
},
{
name: "valid-with-name",
@@ -74,15 +104,6 @@ func TestRepository_CreatePlugin(t *testing.T) {
},
},
},
{
name: "non-global-scope",
in: &Plugin{
Plugin: &store.Plugin{
ScopeId: "o_1234567890",
},
},
wantIsErr: errors.InvalidParameter,
},
}
for _, tt := range tests {
@@ -90,8 +111,8 @@ func TestRepository_CreatePlugin(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
got, err := repo.CreatePlugin(context.Background(), tt.in, tt.opts...)
if tt.wantIsErr != 0 {
assert.Truef(errors.Match(errors.T(tt.wantIsErr), err), "want err: %q got: %q", tt.wantIsErr, err)
if tt.wantErr != "" {
assert.ErrorContains(err, tt.wantErr)
assert.Nil(got)
return
}
@@ -110,7 +131,8 @@ func TestRepository_CreatePlugin(t *testing.T) {
t.Run("invalid-duplicate-names", func(t *testing.T) {
assert := assert.New(t)
kms := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(rw, rw, kms)
ctx := context.Background()
repo, err := NewRepository(ctx, rw, rw, kms)
assert.NoError(err)
assert.NotNil(repo)
in := &Plugin{
@@ -181,7 +203,8 @@ func TestRepository_LookupPlugin(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
kms := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(rw, rw, kms)
ctx := context.Background()
repo, err := NewRepository(ctx, rw, rw, kms)
assert.NoError(err)
assert.NotNil(repo)
@@ -213,7 +236,7 @@ func TestRepository_LookupPluginByName(t *testing.T) {
name string
pluginName string
want *Plugin
wantErr errors.Code
wantErr string
}{
{
name: "found",
@@ -229,7 +252,7 @@ func TestRepository_LookupPluginByName(t *testing.T) {
name: "emptyname",
pluginName: "",
want: nil,
wantErr: errors.InvalidParameter,
wantErr: "no plugin name",
},
}
@@ -238,13 +261,15 @@ func TestRepository_LookupPluginByName(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
kms := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(rw, rw, kms)
ctx := context.Background()
repo, err := NewRepository(ctx, rw, rw, kms)
assert.NoError(err)
assert.NotNil(repo)
got, err := repo.LookupPluginByName(context.Background(), tt.pluginName)
if tt.wantErr != 0 {
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
if tt.wantErr != "" {
assert.ErrorContains(err, tt.wantErr)
assert.Nil(got)
return
}
assert.NoError(err)
@@ -259,3 +284,126 @@ func TestRepository_LookupPluginByName(t *testing.T) {
})
}
}
func TestRepository_AddSupportFlag(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
rw := db.New(conn)
wrapper := db.TestWrapper(t)
tests := []struct {
name string
pluginName string
table string
flag PluginType
flagExists bool
forceErr bool
err string
}{
{
name: "flag doesn't exist and is added",
pluginName: "test1",
table: "plugin_host_supported",
flag: PluginTypeHost,
flagExists: false,
forceErr: false,
err: "",
},
{
name: "flag exists and is unchanged",
pluginName: "test2",
table: "plugin_host_supported",
flag: PluginTypeHost,
flagExists: true,
forceErr: false,
err: "",
},
{
name: "err thrown and is handled",
pluginName: "test3",
table: "plugin_host_supported",
flag: PluginTypeHost,
flagExists: false,
forceErr: true,
err: "wt_plugin_id_check constraint failed",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ctx := context.Background()
// require.Contains(pluginTypeDbMap, tt.flag)
plg := TestPlugin(t, conn, tt.pluginName, WithHostFlag(tt.flagExists))
// check to make sure the start state is as expected
rows, err := rw.Query(ctx, fmt.Sprintf("select public_id from %s where public_id = ?;", tt.table), []any{plg.PublicId})
require.NoError(err)
rowCount := 0
var plgid string
for rows.Next() {
rowCount++
require.NoError(rows.Scan(&plgid))
}
if tt.flagExists {
assert.Equal(1, rowCount)
assert.Equal(plg.PublicId, plgid)
} else {
assert.Equal(0, rowCount)
assert.Equal("", plgid)
}
// create the plugin repo
kms := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(ctx, rw, rw, kms)
assert.NoError(err)
assert.NotNil(repo)
if tt.forceErr {
plg.PublicId = "biscuit"
}
// do the thing
err = repo.AddSupportFlag(ctx, plg, tt.flag)
if tt.err != "" {
require.ErrorContains(err, tt.err)
return
}
require.NoError(err)
// check to make sure the end state is as expected
rows, err = rw.Query(ctx, fmt.Sprintf("select public_id from %s where public_id = ?;", tt.table), []any{plg.PublicId})
require.NoError(err)
rowCount = 0
for rows.Next() {
rowCount++
}
assert.Equal(1, rowCount)
})
}
// this needs it's own test becaues of the setup required for above tests
t.Run("plugin type unknown", func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ctx := context.Background()
plg := TestPlugin(t, conn, "test12345")
// create the plugin repo
kms := kms.TestKms(t, conn, wrapper)
repo, err := NewRepository(ctx, rw, rw, kms)
assert.NoError(err)
assert.NotNil(repo)
// do the thing
err = repo.AddSupportFlag(ctx, plg, PluginTypeUnknown)
require.ErrorContains(err, "plugin type does not exist: parameter violation")
})
}
@@ -1,16 +1,16 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package host
package plugin
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
)
@@ -28,10 +28,10 @@ func TestRepository_New(t *testing.T) {
}
tests := []struct {
name string
args args
want *Repository
wantIsErr errors.Code
name string
args args
want *Repository
wantErr string
}{
{
name: "valid",
@@ -69,8 +69,8 @@ func TestRepository_New(t *testing.T) {
w: rw,
kms: kmsCache,
},
want: nil,
wantIsErr: errors.InvalidParameter,
want: nil,
wantErr: "nil db.Reader",
},
{
name: "nil-writer",
@@ -79,8 +79,8 @@ func TestRepository_New(t *testing.T) {
w: nil,
kms: kmsCache,
},
want: nil,
wantIsErr: errors.InvalidParameter,
want: nil,
wantErr: "nil db.Writer",
},
{
name: "nil-kms",
@@ -89,8 +89,8 @@ func TestRepository_New(t *testing.T) {
w: rw,
kms: nil,
},
want: nil,
wantIsErr: errors.InvalidParameter,
want: nil,
wantErr: "nil kms",
},
{
name: "all-nils",
@@ -99,17 +99,18 @@ func TestRepository_New(t *testing.T) {
w: nil,
kms: nil,
},
want: nil,
wantIsErr: errors.InvalidParameter,
want: nil,
wantErr: "nil db.Reader", // the first param in the switch
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := NewRepository(tt.args.r, tt.args.w, tt.args.kms, tt.args.opts...)
if tt.wantIsErr != 0 {
assert.Truef(errors.Match(errors.T(tt.wantIsErr), err), "want err: %q got: %q", tt.wantIsErr, err)
ctx := context.Background()
got, err := NewRepository(ctx, tt.args.r, tt.args.w, tt.args.kms, tt.args.opts...)
if tt.wantErr != "" {
assert.ErrorContains(err, tt.wantErr)
assert.Nil(got)
return
}
+83 -18
View File
@@ -12,6 +12,8 @@
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"
@@ -25,8 +27,6 @@ const (
_ = 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
@@ -41,6 +41,17 @@ type Plugin struct {
// 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"`
// description is optional.
// @inject_tag: `gorm:"default:null"`
Description string `protobuf:"bytes,40,opt,name=description,proto3" json:"description,omitempty" gorm:"default:null"`
// The create_time is set by the database.
// @inject_tag: `gorm:"default:current_timestamp"`
CreateTime *timestamp.Timestamp `protobuf:"bytes,50,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,60,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"`
// @inject_tag: `gorm:"default:null"`
Version uint32 `protobuf:"varint,70,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"`
}
func (x *Plugin) Reset() {
@@ -96,6 +107,34 @@ func (x *Plugin) GetName() string {
return ""
}
func (x *Plugin) GetDescription() string {
if x != nil {
return x.Description
}
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) GetVersion() uint32 {
if x != nil {
return x.Version
}
return 0
}
var File_controller_storage_plugin_store_v1_plugin_proto protoreflect.FileDescriptor
var file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = []byte{
@@ -104,16 +143,39 @@ var file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = []byte{
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, 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,
0x72, 0x65, 0x2e, 0x76, 0x31, 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, 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, 0xdc, 0x02, 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, 0x24, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x1e, 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, 0x28, 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, 0x4b, 0x0a,
0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x32, 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, 0x3c, 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, 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, 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 (
@@ -130,14 +192,17 @@ func file_controller_storage_plugin_store_v1_plugin_proto_rawDescGZIP() []byte {
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
(*Plugin)(nil), // 0: controller.storage.plugin.store.v1.Plugin
(*timestamp.Timestamp)(nil), // 1: controller.storage.timestamp.v1.Timestamp
}
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
1, // 0: controller.storage.plugin.store.v1.Plugin.create_time:type_name -> controller.storage.timestamp.v1.Timestamp
1, // 1: controller.storage.plugin.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_store_v1_plugin_proto_init() }
+63 -3
View File
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/require"
@@ -44,14 +45,73 @@ func (c *plugin) SetTableName(n string) {
c.tableName = n
}
func testPlugin(t testing.TB, conn *db.DB, name string) *plugin {
// getTestOpts - iterate the inbound TestOptions and return a struct
func getTestOpts(opt ...TestOption) testOptions {
opts := getDefaultTestOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// TestOption - how Options are passed as arguments
type TestOption func(*testOptions)
// options = how options are represented
type testOptions struct {
withHostFlag bool
withStorageFlag bool
}
func getDefaultTestOptions() testOptions {
return testOptions{
withHostFlag: true,
withStorageFlag: false,
}
}
// WithHostFlag determines whether or not to enable the host flag for a test plugin
func WithHostFlag(flag bool) TestOption {
return func(o *testOptions) {
o.withHostFlag = flag
}
}
// WithStorageFlag determines whether or not to enable the storage flag for a test plugin
func WithStorageFlag(flag bool) TestOption {
return func(o *testOptions) {
o.withStorageFlag = flag
}
}
// TestPlugin creates a plugin and inserts it into the database. enables the "host" flag by default
//
// Supported options: WithHostFlag, WithStorageFlag
func TestPlugin(t testing.TB, conn *db.DB, name string, opt ...TestOption) *Plugin {
opts := getTestOpts(opt...)
t.Helper()
p := newPlugin(name)
id, err := db.NewPublicId("plg")
p := NewPlugin(WithName(name))
id, err := newPluginId()
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
wrapper := db.TestWrapper(t)
kmsCache := kms.TestKms(t, conn, wrapper)
ctx := context.Background()
repo, err := NewRepository(ctx, w, w, kmsCache)
require.NoError(t, err)
if opts.withHostFlag {
// add the host supported flag
repo.AddSupportFlag(context.Background(), p, PluginTypeHost)
}
if opts.withStorageFlag {
// add the storage supported flag
repo.AddSupportFlag(context.Background(), p, PluginTypeStorage)
}
return p
}
+2 -2
View File
@@ -11,11 +11,11 @@ import (
"github.com/stretchr/testify/require"
)
func Test_testPlugin(t *testing.T) {
func Test_TestPlugins(t *testing.T) {
assert, require := assert.New(t), require.New(t)
conn, _ := db.TestSetup(t, "postgres")
plg := testPlugin(t, conn, "test")
plg := TestPlugin(t, conn, "test")
require.NotNil(plg)
assert.NotEmpty(plg.GetPublicId())
}