diff --git a/pkg/plugin/backup_item_action.go b/pkg/plugin/backup_item_action.go index 28dd561e2..076045dc3 100644 --- a/pkg/plugin/backup_item_action.go +++ b/pkg/plugin/backup_item_action.go @@ -49,6 +49,10 @@ func NewBackupItemActionPlugin(itemAction arkbackup.ItemAction) *BackupItemActio } } +func (p *BackupItemActionPlugin) Kind() PluginKind { + return PluginKindBackupItemAction +} + // GRPCServer registers a BackupItemAction gRPC server. func (p *BackupItemActionPlugin) GRPCServer(s *grpc.Server) error { proto.RegisterBackupItemActionServer(s, &BackupItemActionGRPCServer{impl: p.impl}) diff --git a/pkg/plugin/block_store.go b/pkg/plugin/block_store.go index ce52d1df6..4c0fcc580 100644 --- a/pkg/plugin/block_store.go +++ b/pkg/plugin/block_store.go @@ -45,6 +45,10 @@ func NewBlockStorePlugin(blockStore cloudprovider.BlockStore) *BlockStorePlugin } } +func (p *BlockStorePlugin) Kind() PluginKind { + return PluginKindBlockStore +} + // GRPCServer registers a BlockStore gRPC server. func (p *BlockStorePlugin) GRPCServer(s *grpc.Server) error { proto.RegisterBlockStoreServer(s, &BlockStoreGRPCServer{impl: p.impl}) diff --git a/pkg/plugin/interface.go b/pkg/plugin/interface.go new file mode 100644 index 000000000..961bfc034 --- /dev/null +++ b/pkg/plugin/interface.go @@ -0,0 +1,27 @@ +/* +Copyright 2017 the Heptio Ark contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package plugin + +import plugin "github.com/hashicorp/go-plugin" + +// Interface represents an Ark plugin. +type Interface interface { + plugin.Plugin + + // Kind returns the PluginKind for the plugin. + Kind() PluginKind +} diff --git a/pkg/plugin/object_store.go b/pkg/plugin/object_store.go index 17108bedc..8896881d4 100644 --- a/pkg/plugin/object_store.go +++ b/pkg/plugin/object_store.go @@ -46,6 +46,10 @@ func NewObjectStorePlugin(objectStore cloudprovider.ObjectStore) *ObjectStorePlu } } +func (p *ObjectStorePlugin) Kind() PluginKind { + return PluginKindObjectStore +} + // GRPCServer registers an ObjectStore gRPC server. func (p *ObjectStorePlugin) GRPCServer(s *grpc.Server) error { proto.RegisterObjectStoreServer(s, &ObjectStoreGRPCServer{impl: p.impl}) diff --git a/pkg/plugin/restore_item_action.go b/pkg/plugin/restore_item_action.go index 832a36ecb..53953ba80 100644 --- a/pkg/plugin/restore_item_action.go +++ b/pkg/plugin/restore_item_action.go @@ -49,6 +49,10 @@ func NewRestoreItemActionPlugin(itemAction restore.ItemAction) *RestoreItemActio } } +func (p *RestoreItemActionPlugin) Kind() PluginKind { + return PluginKindRestoreItemAction +} + // GRPCServer registers a RestoreItemAction gRPC server. func (p *RestoreItemActionPlugin) GRPCServer(s *grpc.Server) error { proto.RegisterRestoreItemActionServer(s, &RestoreItemActionGRPCServer{impl: p.impl}) diff --git a/pkg/plugin/shared.go b/pkg/plugin/shared.go index 0b92621cb..969490aa0 100644 --- a/pkg/plugin/shared.go +++ b/pkg/plugin/shared.go @@ -25,3 +25,14 @@ var Handshake = plugin.HandshakeConfig{ MagicCookieKey: "ARK_PLUGIN", MagicCookieValue: "hello", } + +// Serve serves the plugin p. +func Serve(p Interface) { + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: Handshake, + Plugins: map[string]plugin.Plugin{ + string(p.Kind()): p, + }, + GRPCServer: plugin.DefaultGRPCServer, + }) +}