test(plugin): Support storage service in loopback plugin
This commit is contained in:
1 parent
351444f1bd
commit
9ef94892f4
17 files changed
+183
-739
No files matched your search
@@ -5,92 +5,104 @@ package loopback
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ plgpb.HostPluginServiceClient = (*WrappingPluginClient)(nil)
|
||||
var (
|
||||
_ plgpb.HostPluginServiceClient = (*WrappingPluginHostClient)(nil)
|
||||
_ plgpb.StoragePluginServiceClient = (*WrappingPluginStorageClient)(nil)
|
||||
)
|
||||
|
||||
// WrappingPluginClient provides a wrapper around a Server implementation that
|
||||
// WrappingPluginHostClient provides a wrapper around a Server implementation that
|
||||
// can be used when loading a plugin in-memory. Supports HostServiceServer
|
||||
type WrappingPluginClient struct {
|
||||
Server any
|
||||
type WrappingPluginHostClient struct {
|
||||
Server plgpb.HostPluginServiceServer
|
||||
}
|
||||
|
||||
func NewWrappingPluginClient(s any) *WrappingPluginClient {
|
||||
return &WrappingPluginClient{Server: s}
|
||||
func NewWrappingPluginHostClient(s plgpb.HostPluginServiceServer) *WrappingPluginHostClient {
|
||||
return &WrappingPluginHostClient{Server: s}
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) NormalizeCatalogData(ctx context.Context, req *plgpb.NormalizeCatalogDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeCatalogDataResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
func (tpc *WrappingPluginHostClient) NormalizeCatalogData(ctx context.Context, req *plgpb.NormalizeCatalogDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeCatalogDataResponse, error) {
|
||||
return tpc.Server.NormalizeCatalogData(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnCreateCatalog(ctx context.Context, req *plgpb.OnCreateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnCreateCatalogResponse, error) {
|
||||
return tpc.Server.OnCreateCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnUpdateCatalog(ctx context.Context, req *plgpb.OnUpdateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateCatalogResponse, error) {
|
||||
return tpc.Server.OnUpdateCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnDeleteCatalog(ctx context.Context, req *plgpb.OnDeleteCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteCatalogResponse, error) {
|
||||
return tpc.Server.OnDeleteCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) NormalizeSetData(ctx context.Context, req *plgpb.NormalizeSetDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeSetDataResponse, error) {
|
||||
return tpc.Server.NormalizeSetData(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnCreateSet(ctx context.Context, req *plgpb.OnCreateSetRequest, opts ...grpc.CallOption) (*plgpb.OnCreateSetResponse, error) {
|
||||
return tpc.Server.OnCreateSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnUpdateSet(ctx context.Context, req *plgpb.OnUpdateSetRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateSetResponse, error) {
|
||||
return tpc.Server.OnUpdateSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) OnDeleteSet(ctx context.Context, req *plgpb.OnDeleteSetRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteSetResponse, error) {
|
||||
return tpc.Server.OnDeleteSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginHostClient) ListHosts(ctx context.Context, req *plgpb.ListHostsRequest, opts ...grpc.CallOption) (*plgpb.ListHostsResponse, error) {
|
||||
return tpc.Server.ListHosts(ctx, req)
|
||||
}
|
||||
|
||||
// WrappingPluginStorageClient provides a wrapper around a Server implementation that
|
||||
// can be used when loading a plugin in-memory. Supports StoragePluginServiceClient
|
||||
type WrappingPluginStorageClient struct {
|
||||
Server plgpb.StoragePluginServiceServer
|
||||
}
|
||||
|
||||
func NewWrappingPluginStorageClient(s plgpb.StoragePluginServiceServer) *WrappingPluginStorageClient {
|
||||
return &WrappingPluginStorageClient{Server: s}
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) OnCreateStorageBucket(ctx context.Context, req *plgpb.OnCreateStorageBucketRequest, opts ...grpc.CallOption) (*plgpb.OnCreateStorageBucketResponse, error) {
|
||||
return tpc.Server.OnCreateStorageBucket(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) OnUpdateStorageBucket(ctx context.Context, req *plgpb.OnUpdateStorageBucketRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateStorageBucketResponse, error) {
|
||||
return tpc.Server.OnUpdateStorageBucket(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) OnDeleteStorageBucket(ctx context.Context, req *plgpb.OnDeleteStorageBucketRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteStorageBucketResponse, error) {
|
||||
return tpc.Server.OnDeleteStorageBucket(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) HeadObject(ctx context.Context, req *plgpb.HeadObjectRequest, opts ...grpc.CallOption) (*plgpb.HeadObjectResponse, error) {
|
||||
return tpc.Server.HeadObject(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) ValidatePermissions(ctx context.Context, req *plgpb.ValidatePermissionsRequest, opts ...grpc.CallOption) (*plgpb.ValidatePermissionsResponse, error) {
|
||||
return tpc.Server.ValidatePermissions(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginStorageClient) GetObject(ctx context.Context, req *plgpb.GetObjectRequest, opts ...grpc.CallOption) (plgpb.StoragePluginService_GetObjectClient, error) {
|
||||
stream := newGetObjectStream()
|
||||
if err := tpc.Server.GetObject(req, stream.server); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return svc.NormalizeCatalogData(ctx, req)
|
||||
return stream.client, nil
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnCreateCatalog(ctx context.Context, req *plgpb.OnCreateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnCreateCatalogResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
func (tpc *WrappingPluginStorageClient) PutObject(ctx context.Context, opts ...grpc.CallOption) (plgpb.StoragePluginService_PutObjectClient, error) {
|
||||
stream := newPutObjectStream()
|
||||
if err := tpc.Server.PutObject(stream.server); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return svc.OnCreateCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnUpdateCatalog(ctx context.Context, req *plgpb.OnUpdateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateCatalogResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.OnUpdateCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnDeleteCatalog(ctx context.Context, req *plgpb.OnDeleteCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteCatalogResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.OnDeleteCatalog(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) NormalizeSetData(ctx context.Context, req *plgpb.NormalizeSetDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeSetDataResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.NormalizeSetData(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnCreateSet(ctx context.Context, req *plgpb.OnCreateSetRequest, opts ...grpc.CallOption) (*plgpb.OnCreateSetResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.OnCreateSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnUpdateSet(ctx context.Context, req *plgpb.OnUpdateSetRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateSetResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.OnUpdateSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) OnDeleteSet(ctx context.Context, req *plgpb.OnDeleteSetRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteSetResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.OnDeleteSet(ctx, req)
|
||||
}
|
||||
|
||||
func (tpc *WrappingPluginClient) ListHosts(ctx context.Context, req *plgpb.ListHostsRequest, opts ...grpc.CallOption) (*plgpb.ListHostsResponse, error) {
|
||||
svc, ok := tpc.Server.(plgpb.HostPluginServiceServer)
|
||||
if !ok {
|
||||
return nil, errors.New("wrapping client not initialized with a HostServiceServer")
|
||||
}
|
||||
return svc.ListHosts(ctx, req)
|
||||
return stream.client, nil
|
||||
}
|
||||
Reference in new issue
Block a user