sdk: add host plugin protobufs and interface (#1473)

* sdk: add host plugin protobufs and interface

This adds the protobufs and interface for the upcoming plugin-based host
feature for boundary, providing a common interface for building targets
and host catalogs off of dynamic cloud data.

* Fix signature formatting and separate out/flesh out descriptions

* sdk: re-gen with protobuf v3.15.8

* sdk: update protobuf according to @talanknight's comments

* Update internal/proto/local/plugin/host_catalog.proto

Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>

* Add TODO for host catalog persisted data for size limits

* sdk: move id to external_id and make protobuild

* Move plugin interface to GRPC service

This re-uses existing protobufs where possible, a few more messages have
been created for persisted data and for the host response where it's
important that we make it clear that the external ID is *not* the same
ID as the calculated stable ID for the host within Boundary.

* Update internal/proto/local/plugin/host_plugin_service.proto

Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>

* Move proto target to plugin/proto, fix formatting

Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>
pull/1506/head
Chris Marchesi 5 years ago committed by GitHub
parent 8e42b04b04
commit 2c097c2f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,174 @@
syntax = "proto3";
package plugin;
option go_package = "github.com/hashicorp/boundary/plugin/proto;proto";
import "google/protobuf/struct.proto";
import "controller/api/resources/hostcatalogs/v1/host_catalog.proto";
import "controller/api/resources/hostsets/v1/host_set.proto";
import "controller/api/resources/hosts/v1/host.proto";
// HostPluginService describes the service for host plugins.
service HostPluginService {
// OnCreateCatalog is a hook that runs when a host catalog is
// created.
rpc OnCreateCatalog(OnCreateCatalogRequest) returns (OnCreateCatalogResponse);
// OnUpdateCatalog is a hook that runs when a host catalog is
// updated.
rpc OnUpdateCatalog(OnUpdateCatalogRequest) returns (OnUpdateCatalogResponse);
// OnDeleteCatalog is a hook that runs when a host catalog is
// deleted.
rpc OnDeleteCatalog(OnDeleteCatalogRequest) returns (OnDeleteCatalogResponse);
// OnCreateSet is a hook that runs when a host set is created.
rpc OnCreateSet(OnCreateSetRequest) returns (OnCreateSetResponse);
// OnUpdateSet is a hook that runs when a host set is updated.
rpc OnUpdateSet(OnUpdateSetRequest) returns (OnUpdateSetResponse);
// OnDeleteSet is a hook that runs when a host set is deleted.
rpc OnDeleteSet(OnDeleteSetRequest) returns (OnDeleteSetResponse);
// ListHosts looks up all the hosts in the provided host sets.
rpc ListHosts(ListHostsRequest) returns (ListHostsResponse);
}
message OnCreateCatalogRequest {
// The host catalog to create. The request may contain optional
// secret data to help authenticate the request against a cloud
// API.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
}
message OnCreateCatalogResponse {
// Secret data to persist encrypted within Boundary. This should be
// used to store authentication data and other necessary
// configuration to be used in later hooks and calls. Returning an
// error from the call will cause this data to not be persisted.
HostCatalogPersisted persisted = 10;
}
message OnUpdateCatalogRequest {
// The existing state of the catalog.
controller.api.resources.hostcatalogs.v1.HostCatalog current_catalog = 10;
// The requested new state of the catalog. This field may contain
// optional secret data that may have been updated from old
// authentication data contained within the persisted state.
controller.api.resources.hostcatalogs.v1.HostCatalog new_catalog = 20;
// The existing persisted secret data.
HostCatalogPersisted persisted = 30;
}
message OnUpdateCatalogResponse {
// The updated secret data to persist encrypted within Boundary.
// It's important that this be returned if it existed previously,
// as the returned data overwrites the previously existing copy. If
// an error is returned, the update of the persisted data is
// aborted.
HostCatalogPersisted persisted = 10;
}
message OnDeleteCatalogRequest {
// The existing state of the catalog to delete.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
// The existing persisted secret data.
HostCatalogPersisted persisted = 20;
}
message OnDeleteCatalogResponse {}
message OnCreateSetRequest {
// The host catalog that the set belongs to.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
// The host set to create.
controller.api.resources.hostsets.v1.HostSet set = 20;
// The persisted data for the host catalog that the set belongs to.
HostCatalogPersisted persisted = 30;
}
message OnCreateSetResponse {}
message OnUpdateSetRequest {
// The host catalog that the set belongs to.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
// The existing state of the host set.
controller.api.resources.hostsets.v1.HostSet current_set = 20;
// The requested new state of the host set.
controller.api.resources.hostsets.v1.HostSet new_set = 30;
// The persisted data for the host catalog that the set belongs to.
HostCatalogPersisted persisted = 40;
}
message OnUpdateSetResponse {}
message OnDeleteSetRequest {
// The host catalog that the set belongs to.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
// The host set to delete.
controller.api.resources.hostsets.v1.HostSet current_set = 20;
// The persisted data for the host catalog that the set belongs to.
HostCatalogPersisted persisted = 30;
}
message OnDeleteSetResponse {}
message ListHostsRequest {
// The host catalog that the supplied host sets belong to.
controller.api.resources.hostcatalogs.v1.HostCatalog catalog = 10;
// The host sets to look up hosts for.
repeated controller.api.resources.hostsets.v1.HostSet sets = 20;
// The persisted data for the host catalog that the supplied host
// sets belong to.
HostCatalogPersisted persisted = 30;
}
message ListHostsResponse {
// The hosts to return.
repeated ListHostsResponseHost hosts = 10;
}
message ListHostsResponseHost {
// Required. A stable identifier for this host. This field is used
// to generate a stable ID for the host within Boundary and is
// included in audit logs. It should be set to something unique and
// useful, ie: a compute instance ID.
string external_id = 10;
// Required. The primary address for the host.
string address = 20;
// Optional. Provider-specific metadata that is applicable to this
// host. Example: host descriptions, tags, alternate network
// addresses, etc.
google.protobuf.Struct attributes = 100;
}
// HostCatalogPersisted represents state persisted between host
// catalog calls. Its intended purpose is to store authentication data
// required by the plugin to make calls to its respective cloud API.
//
// The data stored in this message is encrypted at-rest by Boundary
// and never returned to the end user.
//
// TODO: Add a size limit to this data before we export the plugin
// SDK.
message HostCatalogPersisted {
// The persisted data.
google.protobuf.Struct data = 100;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,337 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// HostPluginServiceClient is the client API for HostPluginService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type HostPluginServiceClient interface {
// OnCreateCatalog is a hook that runs when a host catalog is
// created.
OnCreateCatalog(ctx context.Context, in *OnCreateCatalogRequest, opts ...grpc.CallOption) (*OnCreateCatalogResponse, error)
// OnUpdateCatalog is a hook that runs when a host catalog is
// updated.
OnUpdateCatalog(ctx context.Context, in *OnUpdateCatalogRequest, opts ...grpc.CallOption) (*OnUpdateCatalogResponse, error)
// OnDeleteCatalog is a hook that runs when a host catalog is
// deleted.
OnDeleteCatalog(ctx context.Context, in *OnDeleteCatalogRequest, opts ...grpc.CallOption) (*OnDeleteCatalogResponse, error)
// OnCreateSet is a hook that runs when a host set is created.
OnCreateSet(ctx context.Context, in *OnCreateSetRequest, opts ...grpc.CallOption) (*OnCreateSetResponse, error)
// OnUpdateSet is a hook that runs when a host set is updated.
OnUpdateSet(ctx context.Context, in *OnUpdateSetRequest, opts ...grpc.CallOption) (*OnUpdateSetResponse, error)
// OnDeleteSet is a hook that runs when a host set is deleted.
OnDeleteSet(ctx context.Context, in *OnDeleteSetRequest, opts ...grpc.CallOption) (*OnDeleteSetResponse, error)
// ListHosts looks up all the hosts in the provided host sets.
ListHosts(ctx context.Context, in *ListHostsRequest, opts ...grpc.CallOption) (*ListHostsResponse, error)
}
type hostPluginServiceClient struct {
cc grpc.ClientConnInterface
}
func NewHostPluginServiceClient(cc grpc.ClientConnInterface) HostPluginServiceClient {
return &hostPluginServiceClient{cc}
}
func (c *hostPluginServiceClient) OnCreateCatalog(ctx context.Context, in *OnCreateCatalogRequest, opts ...grpc.CallOption) (*OnCreateCatalogResponse, error) {
out := new(OnCreateCatalogResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnCreateCatalog", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) OnUpdateCatalog(ctx context.Context, in *OnUpdateCatalogRequest, opts ...grpc.CallOption) (*OnUpdateCatalogResponse, error) {
out := new(OnUpdateCatalogResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnUpdateCatalog", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) OnDeleteCatalog(ctx context.Context, in *OnDeleteCatalogRequest, opts ...grpc.CallOption) (*OnDeleteCatalogResponse, error) {
out := new(OnDeleteCatalogResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnDeleteCatalog", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) OnCreateSet(ctx context.Context, in *OnCreateSetRequest, opts ...grpc.CallOption) (*OnCreateSetResponse, error) {
out := new(OnCreateSetResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnCreateSet", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) OnUpdateSet(ctx context.Context, in *OnUpdateSetRequest, opts ...grpc.CallOption) (*OnUpdateSetResponse, error) {
out := new(OnUpdateSetResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnUpdateSet", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) OnDeleteSet(ctx context.Context, in *OnDeleteSetRequest, opts ...grpc.CallOption) (*OnDeleteSetResponse, error) {
out := new(OnDeleteSetResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/OnDeleteSet", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hostPluginServiceClient) ListHosts(ctx context.Context, in *ListHostsRequest, opts ...grpc.CallOption) (*ListHostsResponse, error) {
out := new(ListHostsResponse)
err := c.cc.Invoke(ctx, "/plugin.HostPluginService/ListHosts", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// HostPluginServiceServer is the server API for HostPluginService service.
// All implementations must embed UnimplementedHostPluginServiceServer
// for forward compatibility
type HostPluginServiceServer interface {
// OnCreateCatalog is a hook that runs when a host catalog is
// created.
OnCreateCatalog(context.Context, *OnCreateCatalogRequest) (*OnCreateCatalogResponse, error)
// OnUpdateCatalog is a hook that runs when a host catalog is
// updated.
OnUpdateCatalog(context.Context, *OnUpdateCatalogRequest) (*OnUpdateCatalogResponse, error)
// OnDeleteCatalog is a hook that runs when a host catalog is
// deleted.
OnDeleteCatalog(context.Context, *OnDeleteCatalogRequest) (*OnDeleteCatalogResponse, error)
// OnCreateSet is a hook that runs when a host set is created.
OnCreateSet(context.Context, *OnCreateSetRequest) (*OnCreateSetResponse, error)
// OnUpdateSet is a hook that runs when a host set is updated.
OnUpdateSet(context.Context, *OnUpdateSetRequest) (*OnUpdateSetResponse, error)
// OnDeleteSet is a hook that runs when a host set is deleted.
OnDeleteSet(context.Context, *OnDeleteSetRequest) (*OnDeleteSetResponse, error)
// ListHosts looks up all the hosts in the provided host sets.
ListHosts(context.Context, *ListHostsRequest) (*ListHostsResponse, error)
mustEmbedUnimplementedHostPluginServiceServer()
}
// UnimplementedHostPluginServiceServer must be embedded to have forward compatible implementations.
type UnimplementedHostPluginServiceServer struct {
}
func (UnimplementedHostPluginServiceServer) OnCreateCatalog(context.Context, *OnCreateCatalogRequest) (*OnCreateCatalogResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnCreateCatalog not implemented")
}
func (UnimplementedHostPluginServiceServer) OnUpdateCatalog(context.Context, *OnUpdateCatalogRequest) (*OnUpdateCatalogResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnUpdateCatalog not implemented")
}
func (UnimplementedHostPluginServiceServer) OnDeleteCatalog(context.Context, *OnDeleteCatalogRequest) (*OnDeleteCatalogResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnDeleteCatalog not implemented")
}
func (UnimplementedHostPluginServiceServer) OnCreateSet(context.Context, *OnCreateSetRequest) (*OnCreateSetResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnCreateSet not implemented")
}
func (UnimplementedHostPluginServiceServer) OnUpdateSet(context.Context, *OnUpdateSetRequest) (*OnUpdateSetResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnUpdateSet not implemented")
}
func (UnimplementedHostPluginServiceServer) OnDeleteSet(context.Context, *OnDeleteSetRequest) (*OnDeleteSetResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method OnDeleteSet not implemented")
}
func (UnimplementedHostPluginServiceServer) ListHosts(context.Context, *ListHostsRequest) (*ListHostsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListHosts not implemented")
}
func (UnimplementedHostPluginServiceServer) mustEmbedUnimplementedHostPluginServiceServer() {}
// UnsafeHostPluginServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to HostPluginServiceServer will
// result in compilation errors.
type UnsafeHostPluginServiceServer interface {
mustEmbedUnimplementedHostPluginServiceServer()
}
func RegisterHostPluginServiceServer(s grpc.ServiceRegistrar, srv HostPluginServiceServer) {
s.RegisterService(&HostPluginService_ServiceDesc, srv)
}
func _HostPluginService_OnCreateCatalog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnCreateCatalogRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnCreateCatalog(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnCreateCatalog",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnCreateCatalog(ctx, req.(*OnCreateCatalogRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_OnUpdateCatalog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnUpdateCatalogRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnUpdateCatalog(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnUpdateCatalog",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnUpdateCatalog(ctx, req.(*OnUpdateCatalogRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_OnDeleteCatalog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnDeleteCatalogRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnDeleteCatalog(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnDeleteCatalog",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnDeleteCatalog(ctx, req.(*OnDeleteCatalogRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_OnCreateSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnCreateSetRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnCreateSet(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnCreateSet",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnCreateSet(ctx, req.(*OnCreateSetRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_OnUpdateSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnUpdateSetRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnUpdateSet(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnUpdateSet",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnUpdateSet(ctx, req.(*OnUpdateSetRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_OnDeleteSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(OnDeleteSetRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).OnDeleteSet(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/OnDeleteSet",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).OnDeleteSet(ctx, req.(*OnDeleteSetRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HostPluginService_ListHosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListHostsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HostPluginServiceServer).ListHosts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/plugin.HostPluginService/ListHosts",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HostPluginServiceServer).ListHosts(ctx, req.(*ListHostsRequest))
}
return interceptor(ctx, in, info, handler)
}
// HostPluginService_ServiceDesc is the grpc.ServiceDesc for HostPluginService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var HostPluginService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "plugin.HostPluginService",
HandlerType: (*HostPluginServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "OnCreateCatalog",
Handler: _HostPluginService_OnCreateCatalog_Handler,
},
{
MethodName: "OnUpdateCatalog",
Handler: _HostPluginService_OnUpdateCatalog_Handler,
},
{
MethodName: "OnDeleteCatalog",
Handler: _HostPluginService_OnDeleteCatalog_Handler,
},
{
MethodName: "OnCreateSet",
Handler: _HostPluginService_OnCreateSet_Handler,
},
{
MethodName: "OnUpdateSet",
Handler: _HostPluginService_OnUpdateSet_Handler,
},
{
MethodName: "OnDeleteSet",
Handler: _HostPluginService_OnDeleteSet_Handler,
},
{
MethodName: "ListHosts",
Handler: _HostPluginService_ListHosts_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "plugin/host_plugin_service.proto",
}
Loading…
Cancel
Save