Simply serving plugins for external developers
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>pull/223/head
parent
c129d1cec3
commit
1f7e9b65e8
|
@ -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})
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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})
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue