add support for metadata plugins

This commit is contained in:
Nicola Murino
2021-12-16 18:18:36 +01:00
parent 1472a0f415
commit a587228cf0
37 changed files with 2283 additions and 132 deletions

View File

@@ -36,7 +36,7 @@ type Searcher interface {
limit, order int, actions, objectTypes, instanceIDs, excludeIDs []string) ([]byte, []string, []string, error)
}
// Plugin defines the implementation to serve/connect to a notifier plugin
// Plugin defines the implementation to serve/connect to a event search plugin
type Plugin struct {
plugin.Plugin
Impl Searcher

View File

@@ -76,7 +76,7 @@ type GRPCServer struct {
Impl Searcher
}
// SearchFsEvents implement the server side fs events search method
// SearchFsEvents implements the server side fs events search method
func (s *GRPCServer) SearchFsEvents(ctx context.Context, req *proto.FsEventsFilter) (*proto.SearchResponse, error) {
responseData, sameTsAtStart, sameTsAtEnd, err := s.Impl.SearchFsEvents(req.StartTimestamp,
req.EndTimestamp, req.Username, req.Ip, req.SshCmd, req.Actions, req.Protocols, req.InstanceIds,

82
sdk/plugin/metadata.go Normal file
View File

@@ -0,0 +1,82 @@
package plugin
import (
"crypto/sha256"
"fmt"
"os/exec"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/drakkan/sftpgo/v2/logger"
"github.com/drakkan/sftpgo/v2/sdk/plugin/metadata"
)
type metadataPlugin struct {
config Config
metadater metadata.Metadater
client *plugin.Client
}
func newMetadaterPlugin(config Config) (*metadataPlugin, error) {
p := &metadataPlugin{
config: config,
}
if err := p.initialize(); err != nil {
logger.Warn(logSender, "", "unable to create metadata plugin: %v, config %+v", err, config)
return nil, err
}
return p, nil
}
func (p *metadataPlugin) exited() bool {
return p.client.Exited()
}
func (p *metadataPlugin) cleanup() {
p.client.Kill()
}
func (p *metadataPlugin) initialize() error {
killProcess(p.config.Cmd)
logger.Debug(logSender, "", "create new metadata plugin %#v", p.config.Cmd)
var secureConfig *plugin.SecureConfig
if p.config.SHA256Sum != "" {
secureConfig.Checksum = []byte(p.config.SHA256Sum)
secureConfig.Hash = sha256.New()
}
client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: metadata.Handshake,
Plugins: metadata.PluginMap,
Cmd: exec.Command(p.config.Cmd, p.config.Args...),
AllowedProtocols: []plugin.Protocol{
plugin.ProtocolGRPC,
},
Managed: false,
AutoMTLS: p.config.AutoMTLS,
SecureConfig: secureConfig,
Logger: &logger.HCLogAdapter{
Logger: hclog.New(&hclog.LoggerOptions{
Name: fmt.Sprintf("%v.%v", logSender, metadata.PluginName),
Level: pluginsLogLevel,
DisableTime: true,
}),
},
})
rpcClient, err := client.Client()
if err != nil {
logger.Debug(logSender, "", "unable to get rpc client for plugin %#v: %v", p.config.Cmd, err)
return err
}
raw, err := rpcClient.Dispense(metadata.PluginName)
if err != nil {
logger.Debug(logSender, "", "unable to get plugin %v from rpc client for command %#v: %v",
metadata.PluginName, p.config.Cmd, err)
return err
}
p.client = client
p.metadater = raw.(metadata.Metadater)
return nil
}

160
sdk/plugin/metadata/grpc.go Normal file
View File

@@ -0,0 +1,160 @@
package metadata
import (
"context"
"time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/drakkan/sftpgo/v2/sdk/plugin/metadata/proto"
)
const (
rpcTimeout = 20 * time.Second
)
// GRPCClient is an implementation of Metadater interface that talks over RPC.
type GRPCClient struct {
client proto.MetadataClient
}
// SetModificationTime implements the Metadater interface
func (c *GRPCClient) SetModificationTime(storageID, objectPath string, mTime int64) error {
ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)
defer cancel()
_, err := c.client.SetModificationTime(ctx, &proto.SetModificationTimeRequest{
StorageId: storageID,
ObjectPath: objectPath,
ModificationTime: mTime,
})
return c.checkError(err)
}
// GetModificationTime implements the Metadater interface
func (c *GRPCClient) GetModificationTime(storageID, objectPath string) (int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)
defer cancel()
resp, err := c.client.GetModificationTime(ctx, &proto.GetModificationTimeRequest{
StorageId: storageID,
ObjectPath: objectPath,
})
if err != nil {
return 0, c.checkError(err)
}
return resp.ModificationTime, nil
}
// GetModificationTimes implements the Metadater interface
func (c *GRPCClient) GetModificationTimes(storageID, objectPath string) (map[string]int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout*4)
defer cancel()
resp, err := c.client.GetModificationTimes(ctx, &proto.GetModificationTimesRequest{
StorageId: storageID,
FolderPath: objectPath,
})
if err != nil {
return nil, c.checkError(err)
}
return resp.Pairs, nil
}
// RemoveMetadata implements the Metadater interface
func (c *GRPCClient) RemoveMetadata(storageID, objectPath string) error {
ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)
defer cancel()
_, err := c.client.RemoveMetadata(ctx, &proto.RemoveMetadataRequest{
StorageId: storageID,
ObjectPath: objectPath,
})
return c.checkError(err)
}
// GetFolders implements the Metadater interface
func (c *GRPCClient) GetFolders(storageID string, limit int, from string) ([]string, error) {
ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)
defer cancel()
resp, err := c.client.GetFolders(ctx, &proto.GetFoldersRequest{
StorageId: storageID,
Limit: int32(limit),
From: from,
})
if err != nil {
return nil, c.checkError(err)
}
return resp.Folders, nil
}
func (c *GRPCClient) checkError(err error) error {
if err == nil {
return nil
}
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return ErrNoSuchObject
}
}
return err
}
// GRPCServer defines the gRPC server that GRPCClient talks to.
type GRPCServer struct {
Impl Metadater
}
// SetModificationTime implements the server side set modification time method
func (s *GRPCServer) SetModificationTime(ctx context.Context, req *proto.SetModificationTimeRequest) (*emptypb.Empty, error) {
err := s.Impl.SetModificationTime(req.StorageId, req.ObjectPath, req.ModificationTime)
return &emptypb.Empty{}, err
}
// GetModificationTime implements the server side get modification time method
func (s *GRPCServer) GetModificationTime(ctx context.Context, req *proto.GetModificationTimeRequest) (
*proto.GetModificationTimeResponse, error,
) {
mTime, err := s.Impl.GetModificationTime(req.StorageId, req.ObjectPath)
return &proto.GetModificationTimeResponse{
ModificationTime: mTime,
}, err
}
// GetModificationTimes implements the server side get modification times method
func (s *GRPCServer) GetModificationTimes(ctx context.Context, req *proto.GetModificationTimesRequest) (
*proto.GetModificationTimesResponse, error,
) {
res, err := s.Impl.GetModificationTimes(req.StorageId, req.FolderPath)
return &proto.GetModificationTimesResponse{
Pairs: res,
}, err
}
// RemoveMetadata implements the server side remove metadata method
func (s *GRPCServer) RemoveMetadata(ctx context.Context, req *proto.RemoveMetadataRequest) (*emptypb.Empty, error) {
err := s.Impl.RemoveMetadata(req.StorageId, req.ObjectPath)
return &emptypb.Empty{}, err
}
// GetFolders implements the server side get folders method
func (s *GRPCServer) GetFolders(ctx context.Context, req *proto.GetFoldersRequest) (*proto.GetFoldersResponse, error) {
res, err := s.Impl.GetFolders(req.StorageId, int(req.Limit), req.From)
return &proto.GetFoldersResponse{
Folders: res,
}, err
}

View File

@@ -0,0 +1,61 @@
package metadata
import (
"context"
"errors"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
"github.com/drakkan/sftpgo/v2/sdk/plugin/metadata/proto"
)
const (
// PluginName defines the name for a metadata plugin
PluginName = "metadata"
)
var (
// Handshake is a common handshake that is shared by plugin and host.
Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "SFTPGO_PLUGIN_METADATA",
MagicCookieValue: "85dddeea-56d8-4d5b-b488-8b125edb3a0f",
}
// ErrNoSuchObject is the error that plugins must return if the request object does not exist
ErrNoSuchObject = errors.New("no such object")
// PluginMap is the map of plugins we can dispense.
PluginMap = map[string]plugin.Plugin{
PluginName: &Plugin{},
}
)
// Metadater defines the interface for metadata plugins
type Metadater interface {
SetModificationTime(storageID, objectPath string, mTime int64) error
GetModificationTime(storageID, objectPath string) (int64, error)
GetModificationTimes(storageID, objectPath string) (map[string]int64, error)
RemoveMetadata(storageID, objectPath string) error
GetFolders(storageID string, limit int, from string) ([]string, error)
}
// Plugin defines the implementation to serve/connect to a metadata plugin
type Plugin struct {
plugin.Plugin
Impl Metadater
}
// GRPCServer defines the GRPC server implementation for this plugin
func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterMetadataServer(s, &GRPCServer{
Impl: p.Impl,
})
return nil
}
// GRPCClient defines the GRPC client implementation for this plugin
func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCClient{
client: proto.NewMetadataClient(c),
}, nil
}

View File

@@ -0,0 +1,938 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.3
// source: metadata/proto/metadata.proto
package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
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 SetModificationTimeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StorageId string `protobuf:"bytes,1,opt,name=storage_id,json=storageId,proto3" json:"storage_id,omitempty"`
ObjectPath string `protobuf:"bytes,2,opt,name=object_path,json=objectPath,proto3" json:"object_path,omitempty"`
ModificationTime int64 `protobuf:"varint,3,opt,name=modification_time,json=modificationTime,proto3" json:"modification_time,omitempty"`
}
func (x *SetModificationTimeRequest) Reset() {
*x = SetModificationTimeRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SetModificationTimeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SetModificationTimeRequest) ProtoMessage() {}
func (x *SetModificationTimeRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_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 SetModificationTimeRequest.ProtoReflect.Descriptor instead.
func (*SetModificationTimeRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{0}
}
func (x *SetModificationTimeRequest) GetStorageId() string {
if x != nil {
return x.StorageId
}
return ""
}
func (x *SetModificationTimeRequest) GetObjectPath() string {
if x != nil {
return x.ObjectPath
}
return ""
}
func (x *SetModificationTimeRequest) GetModificationTime() int64 {
if x != nil {
return x.ModificationTime
}
return 0
}
type GetModificationTimeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StorageId string `protobuf:"bytes,1,opt,name=storage_id,json=storageId,proto3" json:"storage_id,omitempty"`
ObjectPath string `protobuf:"bytes,2,opt,name=object_path,json=objectPath,proto3" json:"object_path,omitempty"`
}
func (x *GetModificationTimeRequest) Reset() {
*x = GetModificationTimeRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetModificationTimeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetModificationTimeRequest) ProtoMessage() {}
func (x *GetModificationTimeRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[1]
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 GetModificationTimeRequest.ProtoReflect.Descriptor instead.
func (*GetModificationTimeRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{1}
}
func (x *GetModificationTimeRequest) GetStorageId() string {
if x != nil {
return x.StorageId
}
return ""
}
func (x *GetModificationTimeRequest) GetObjectPath() string {
if x != nil {
return x.ObjectPath
}
return ""
}
type GetModificationTimeResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ModificationTime int64 `protobuf:"varint,1,opt,name=modification_time,json=modificationTime,proto3" json:"modification_time,omitempty"`
}
func (x *GetModificationTimeResponse) Reset() {
*x = GetModificationTimeResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetModificationTimeResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetModificationTimeResponse) ProtoMessage() {}
func (x *GetModificationTimeResponse) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[2]
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 GetModificationTimeResponse.ProtoReflect.Descriptor instead.
func (*GetModificationTimeResponse) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{2}
}
func (x *GetModificationTimeResponse) GetModificationTime() int64 {
if x != nil {
return x.ModificationTime
}
return 0
}
type GetModificationTimesRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StorageId string `protobuf:"bytes,1,opt,name=storage_id,json=storageId,proto3" json:"storage_id,omitempty"`
FolderPath string `protobuf:"bytes,2,opt,name=folder_path,json=folderPath,proto3" json:"folder_path,omitempty"`
}
func (x *GetModificationTimesRequest) Reset() {
*x = GetModificationTimesRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetModificationTimesRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetModificationTimesRequest) ProtoMessage() {}
func (x *GetModificationTimesRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[3]
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 GetModificationTimesRequest.ProtoReflect.Descriptor instead.
func (*GetModificationTimesRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{3}
}
func (x *GetModificationTimesRequest) GetStorageId() string {
if x != nil {
return x.StorageId
}
return ""
}
func (x *GetModificationTimesRequest) GetFolderPath() string {
if x != nil {
return x.FolderPath
}
return ""
}
type GetModificationTimesResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// the file name (not the full path) is the map key and the modification time is the map value
Pairs map[string]int64 `protobuf:"bytes,1,rep,name=pairs,proto3" json:"pairs,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
}
func (x *GetModificationTimesResponse) Reset() {
*x = GetModificationTimesResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetModificationTimesResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetModificationTimesResponse) ProtoMessage() {}
func (x *GetModificationTimesResponse) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[4]
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 GetModificationTimesResponse.ProtoReflect.Descriptor instead.
func (*GetModificationTimesResponse) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{4}
}
func (x *GetModificationTimesResponse) GetPairs() map[string]int64 {
if x != nil {
return x.Pairs
}
return nil
}
type RemoveMetadataRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StorageId string `protobuf:"bytes,1,opt,name=storage_id,json=storageId,proto3" json:"storage_id,omitempty"`
ObjectPath string `protobuf:"bytes,2,opt,name=object_path,json=objectPath,proto3" json:"object_path,omitempty"`
}
func (x *RemoveMetadataRequest) Reset() {
*x = RemoveMetadataRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *RemoveMetadataRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RemoveMetadataRequest) ProtoMessage() {}
func (x *RemoveMetadataRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[5]
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 RemoveMetadataRequest.ProtoReflect.Descriptor instead.
func (*RemoveMetadataRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{5}
}
func (x *RemoveMetadataRequest) GetStorageId() string {
if x != nil {
return x.StorageId
}
return ""
}
func (x *RemoveMetadataRequest) GetObjectPath() string {
if x != nil {
return x.ObjectPath
}
return ""
}
type GetFoldersRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StorageId string `protobuf:"bytes,1,opt,name=storage_id,json=storageId,proto3" json:"storage_id,omitempty"`
Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
From string `protobuf:"bytes,3,opt,name=from,proto3" json:"from,omitempty"`
}
func (x *GetFoldersRequest) Reset() {
*x = GetFoldersRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetFoldersRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetFoldersRequest) ProtoMessage() {}
func (x *GetFoldersRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[6]
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 GetFoldersRequest.ProtoReflect.Descriptor instead.
func (*GetFoldersRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{6}
}
func (x *GetFoldersRequest) GetStorageId() string {
if x != nil {
return x.StorageId
}
return ""
}
func (x *GetFoldersRequest) GetLimit() int32 {
if x != nil {
return x.Limit
}
return 0
}
func (x *GetFoldersRequest) GetFrom() string {
if x != nil {
return x.From
}
return ""
}
type GetFoldersResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Folders []string `protobuf:"bytes,1,rep,name=folders,proto3" json:"folders,omitempty"`
}
func (x *GetFoldersResponse) Reset() {
*x = GetFoldersResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_metadata_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetFoldersResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetFoldersResponse) ProtoMessage() {}
func (x *GetFoldersResponse) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_metadata_proto_msgTypes[7]
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 GetFoldersResponse.ProtoReflect.Descriptor instead.
func (*GetFoldersResponse) Descriptor() ([]byte, []int) {
return file_metadata_proto_metadata_proto_rawDescGZIP(), []int{7}
}
func (x *GetFoldersResponse) GetFolders() []string {
if x != nil {
return x.Folders
}
return nil
}
var File_metadata_proto_metadata_proto protoreflect.FileDescriptor
var file_metadata_proto_metadata_proto_rawDesc = []byte{
0x0a, 0x1d, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0x89, 0x01, 0x0a, 0x1a, 0x53, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x49,
0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x70, 0x61, 0x74, 0x68,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x61,
0x74, 0x68, 0x12, 0x2b, 0x0a, 0x11, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, 0x6d,
0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x22,
0x5c, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a,
0x0a, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b,
0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0a, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x61, 0x74, 0x68, 0x22, 0x4a, 0x0a,
0x1b, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x54, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2b, 0x0a, 0x11,
0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x5d, 0x0a, 0x1b, 0x47, 0x65, 0x74,
0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65,
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x6f, 0x72,
0x61, 0x67, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74,
0x6f, 0x72, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x66, 0x6f, 0x6c, 0x64, 0x65,
0x72, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x66, 0x6f,
0x6c, 0x64, 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x22, 0x9e, 0x01, 0x0a, 0x1c, 0x47, 0x65, 0x74,
0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x05, 0x70, 0x61, 0x69,
0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x54, 0x69, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x50, 0x61,
0x69, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x70, 0x61, 0x69, 0x72, 0x73, 0x1a,
0x38, 0x0a, 0x0a, 0x50, 0x61, 0x69, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12,
0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, 0x15, 0x52, 0x65, 0x6d,
0x6f, 0x76, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x49,
0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x70, 0x61, 0x74, 0x68,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x61,
0x74, 0x68, 0x22, 0x5c, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x6f, 0x72, 0x61,
0x67, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f,
0x72, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04,
0x66, 0x72, 0x6f, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d,
0x22, 0x2e, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73,
0x32, 0xa6, 0x03, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x50, 0x0a,
0x13, 0x53, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x54, 0x69, 0x6d, 0x65, 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74,
0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12,
0x5c, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47,
0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69,
0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x54, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a,
0x14, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x54, 0x69, 0x6d, 0x65, 0x73, 0x12, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65,
0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d,
0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46,
0x0a, 0x0e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x4d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x41, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x6c,
0x64, 0x65, 0x72, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74,
0x46, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x6c, 0x64, 0x65, 0x72,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x1b, 0x5a, 0x19, 0x73, 0x64, 0x6b,
0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_metadata_proto_metadata_proto_rawDescOnce sync.Once
file_metadata_proto_metadata_proto_rawDescData = file_metadata_proto_metadata_proto_rawDesc
)
func file_metadata_proto_metadata_proto_rawDescGZIP() []byte {
file_metadata_proto_metadata_proto_rawDescOnce.Do(func() {
file_metadata_proto_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_metadata_proto_metadata_proto_rawDescData)
})
return file_metadata_proto_metadata_proto_rawDescData
}
var file_metadata_proto_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_metadata_proto_metadata_proto_goTypes = []interface{}{
(*SetModificationTimeRequest)(nil), // 0: proto.SetModificationTimeRequest
(*GetModificationTimeRequest)(nil), // 1: proto.GetModificationTimeRequest
(*GetModificationTimeResponse)(nil), // 2: proto.GetModificationTimeResponse
(*GetModificationTimesRequest)(nil), // 3: proto.GetModificationTimesRequest
(*GetModificationTimesResponse)(nil), // 4: proto.GetModificationTimesResponse
(*RemoveMetadataRequest)(nil), // 5: proto.RemoveMetadataRequest
(*GetFoldersRequest)(nil), // 6: proto.GetFoldersRequest
(*GetFoldersResponse)(nil), // 7: proto.GetFoldersResponse
nil, // 8: proto.GetModificationTimesResponse.PairsEntry
(*emptypb.Empty)(nil), // 9: google.protobuf.Empty
}
var file_metadata_proto_metadata_proto_depIdxs = []int32{
8, // 0: proto.GetModificationTimesResponse.pairs:type_name -> proto.GetModificationTimesResponse.PairsEntry
0, // 1: proto.Metadata.SetModificationTime:input_type -> proto.SetModificationTimeRequest
1, // 2: proto.Metadata.GetModificationTime:input_type -> proto.GetModificationTimeRequest
3, // 3: proto.Metadata.GetModificationTimes:input_type -> proto.GetModificationTimesRequest
5, // 4: proto.Metadata.RemoveMetadata:input_type -> proto.RemoveMetadataRequest
6, // 5: proto.Metadata.GetFolders:input_type -> proto.GetFoldersRequest
9, // 6: proto.Metadata.SetModificationTime:output_type -> google.protobuf.Empty
2, // 7: proto.Metadata.GetModificationTime:output_type -> proto.GetModificationTimeResponse
4, // 8: proto.Metadata.GetModificationTimes:output_type -> proto.GetModificationTimesResponse
9, // 9: proto.Metadata.RemoveMetadata:output_type -> google.protobuf.Empty
7, // 10: proto.Metadata.GetFolders:output_type -> proto.GetFoldersResponse
6, // [6:11] is the sub-list for method output_type
1, // [1:6] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_metadata_proto_metadata_proto_init() }
func file_metadata_proto_metadata_proto_init() {
if File_metadata_proto_metadata_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_metadata_proto_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SetModificationTimeRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetModificationTimeRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetModificationTimeResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetModificationTimesRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetModificationTimesResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*RemoveMetadataRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetFoldersRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_metadata_proto_metadata_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetFoldersResponse); 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_metadata_proto_metadata_proto_rawDesc,
NumEnums: 0,
NumMessages: 9,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_metadata_proto_metadata_proto_goTypes,
DependencyIndexes: file_metadata_proto_metadata_proto_depIdxs,
MessageInfos: file_metadata_proto_metadata_proto_msgTypes,
}.Build()
File_metadata_proto_metadata_proto = out.File
file_metadata_proto_metadata_proto_rawDesc = nil
file_metadata_proto_metadata_proto_goTypes = nil
file_metadata_proto_metadata_proto_depIdxs = nil
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// MetadataClient is the client API for Metadata service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type MetadataClient interface {
SetModificationTime(ctx context.Context, in *SetModificationTimeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
GetModificationTime(ctx context.Context, in *GetModificationTimeRequest, opts ...grpc.CallOption) (*GetModificationTimeResponse, error)
GetModificationTimes(ctx context.Context, in *GetModificationTimesRequest, opts ...grpc.CallOption) (*GetModificationTimesResponse, error)
RemoveMetadata(ctx context.Context, in *RemoveMetadataRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
GetFolders(ctx context.Context, in *GetFoldersRequest, opts ...grpc.CallOption) (*GetFoldersResponse, error)
}
type metadataClient struct {
cc grpc.ClientConnInterface
}
func NewMetadataClient(cc grpc.ClientConnInterface) MetadataClient {
return &metadataClient{cc}
}
func (c *metadataClient) SetModificationTime(ctx context.Context, in *SetModificationTimeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/proto.Metadata/SetModificationTime", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *metadataClient) GetModificationTime(ctx context.Context, in *GetModificationTimeRequest, opts ...grpc.CallOption) (*GetModificationTimeResponse, error) {
out := new(GetModificationTimeResponse)
err := c.cc.Invoke(ctx, "/proto.Metadata/GetModificationTime", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *metadataClient) GetModificationTimes(ctx context.Context, in *GetModificationTimesRequest, opts ...grpc.CallOption) (*GetModificationTimesResponse, error) {
out := new(GetModificationTimesResponse)
err := c.cc.Invoke(ctx, "/proto.Metadata/GetModificationTimes", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *metadataClient) RemoveMetadata(ctx context.Context, in *RemoveMetadataRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/proto.Metadata/RemoveMetadata", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *metadataClient) GetFolders(ctx context.Context, in *GetFoldersRequest, opts ...grpc.CallOption) (*GetFoldersResponse, error) {
out := new(GetFoldersResponse)
err := c.cc.Invoke(ctx, "/proto.Metadata/GetFolders", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// MetadataServer is the server API for Metadata service.
type MetadataServer interface {
SetModificationTime(context.Context, *SetModificationTimeRequest) (*emptypb.Empty, error)
GetModificationTime(context.Context, *GetModificationTimeRequest) (*GetModificationTimeResponse, error)
GetModificationTimes(context.Context, *GetModificationTimesRequest) (*GetModificationTimesResponse, error)
RemoveMetadata(context.Context, *RemoveMetadataRequest) (*emptypb.Empty, error)
GetFolders(context.Context, *GetFoldersRequest) (*GetFoldersResponse, error)
}
// UnimplementedMetadataServer can be embedded to have forward compatible implementations.
type UnimplementedMetadataServer struct {
}
func (*UnimplementedMetadataServer) SetModificationTime(context.Context, *SetModificationTimeRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetModificationTime not implemented")
}
func (*UnimplementedMetadataServer) GetModificationTime(context.Context, *GetModificationTimeRequest) (*GetModificationTimeResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetModificationTime not implemented")
}
func (*UnimplementedMetadataServer) GetModificationTimes(context.Context, *GetModificationTimesRequest) (*GetModificationTimesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetModificationTimes not implemented")
}
func (*UnimplementedMetadataServer) RemoveMetadata(context.Context, *RemoveMetadataRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method RemoveMetadata not implemented")
}
func (*UnimplementedMetadataServer) GetFolders(context.Context, *GetFoldersRequest) (*GetFoldersResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetFolders not implemented")
}
func RegisterMetadataServer(s *grpc.Server, srv MetadataServer) {
s.RegisterService(&_Metadata_serviceDesc, srv)
}
func _Metadata_SetModificationTime_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetModificationTimeRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MetadataServer).SetModificationTime(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Metadata/SetModificationTime",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MetadataServer).SetModificationTime(ctx, req.(*SetModificationTimeRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Metadata_GetModificationTime_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetModificationTimeRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MetadataServer).GetModificationTime(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Metadata/GetModificationTime",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MetadataServer).GetModificationTime(ctx, req.(*GetModificationTimeRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Metadata_GetModificationTimes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetModificationTimesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MetadataServer).GetModificationTimes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Metadata/GetModificationTimes",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MetadataServer).GetModificationTimes(ctx, req.(*GetModificationTimesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Metadata_RemoveMetadata_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RemoveMetadataRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MetadataServer).RemoveMetadata(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Metadata/RemoveMetadata",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MetadataServer).RemoveMetadata(ctx, req.(*RemoveMetadataRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Metadata_GetFolders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetFoldersRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MetadataServer).GetFolders(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Metadata/GetFolders",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MetadataServer).GetFolders(ctx, req.(*GetFoldersRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Metadata_serviceDesc = grpc.ServiceDesc{
ServiceName: "proto.Metadata",
HandlerType: (*MetadataServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "SetModificationTime",
Handler: _Metadata_SetModificationTime_Handler,
},
{
MethodName: "GetModificationTime",
Handler: _Metadata_GetModificationTime_Handler,
},
{
MethodName: "GetModificationTimes",
Handler: _Metadata_GetModificationTimes_Handler,
},
{
MethodName: "RemoveMetadata",
Handler: _Metadata_RemoveMetadata_Handler,
},
{
MethodName: "GetFolders",
Handler: _Metadata_GetFolders_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "metadata/proto/metadata.proto",
}

View File

@@ -0,0 +1,54 @@
syntax = "proto3";
package proto;
import "google/protobuf/empty.proto";
option go_package = "sdk/plugin/metadata/proto";
message SetModificationTimeRequest {
string storage_id = 1;
string object_path = 2;
int64 modification_time = 3;
}
message GetModificationTimeRequest {
string storage_id = 1;
string object_path = 2;
}
message GetModificationTimeResponse {
int64 modification_time = 1;
}
message GetModificationTimesRequest {
string storage_id = 1;
string folder_path = 2;
}
message GetModificationTimesResponse {
// the file name (not the full path) is the map key and the modification time is the map value
map<string,int64> pairs = 1;
}
message RemoveMetadataRequest {
string storage_id = 1;
string object_path = 2;
}
message GetFoldersRequest {
string storage_id = 1;
int32 limit = 2;
string from = 3;
}
message GetFoldersResponse {
repeated string folders = 1;
}
service Metadata {
rpc SetModificationTime(SetModificationTimeRequest) returns (google.protobuf.Empty);
rpc GetModificationTime(GetModificationTimeRequest) returns (GetModificationTimeResponse);
rpc GetModificationTimes(GetModificationTimesRequest) returns (GetModificationTimesResponse);
rpc RemoveMetadata(RemoveMetadataRequest) returns (google.protobuf.Empty);
rpc GetFolders(GetFoldersRequest) returns (GetFoldersResponse);
}

View File

@@ -4,3 +4,4 @@ protoc notifier/proto/notifier.proto --go_out=plugins=grpc:../.. --go_out=../../
protoc kms/proto/kms.proto --go_out=plugins=grpc:../.. --go_out=../../..
protoc auth/proto/auth.proto --go_out=plugins=grpc:../.. --go_out=../../..
protoc eventsearcher/proto/search.proto --go_out=plugins=grpc:../.. --go_out=../../..
protoc metadata/proto/metadata.proto --go_out=plugins=grpc:../.. --go_out=../../..

View File

@@ -16,6 +16,7 @@ import (
"github.com/drakkan/sftpgo/v2/sdk/plugin/auth"
"github.com/drakkan/sftpgo/v2/sdk/plugin/eventsearcher"
kmsplugin "github.com/drakkan/sftpgo/v2/sdk/plugin/kms"
"github.com/drakkan/sftpgo/v2/sdk/plugin/metadata"
"github.com/drakkan/sftpgo/v2/sdk/plugin/notifier"
"github.com/drakkan/sftpgo/v2/util"
)
@@ -30,6 +31,8 @@ var (
pluginsLogLevel = hclog.Debug
// ErrNoSearcher defines the error to return for events searches if no plugin is configured
ErrNoSearcher = errors.New("no events searcher plugin defined")
// ErrNoMetadater returns the error to return for metadata methods if no plugin is configured
ErrNoMetadater = errors.New("no metadata plugin defined")
)
// Renderer defines the interface for generic objects rendering
@@ -78,17 +81,20 @@ type Manager struct {
closed int32
done chan bool
// List of configured plugins
Configs []Config `json:"plugins" mapstructure:"plugins"`
notifLock sync.RWMutex
notifiers []*notifierPlugin
kmsLock sync.RWMutex
kms []*kmsPlugin
authLock sync.RWMutex
auths []*authPlugin
searcherLock sync.RWMutex
searcher *searcherPlugin
authScopes int
hasSearcher bool
Configs []Config `json:"plugins" mapstructure:"plugins"`
notifLock sync.RWMutex
notifiers []*notifierPlugin
kmsLock sync.RWMutex
kms []*kmsPlugin
authLock sync.RWMutex
auths []*authPlugin
searcherLock sync.RWMutex
searcher *searcherPlugin
metadaterLock sync.RWMutex
metadater *metadataPlugin
authScopes int
hasSearcher bool
hasMetadater bool
}
// Initialize initializes the configured plugins
@@ -100,19 +106,15 @@ func Initialize(configs []Config, logVerbose bool) error {
closed: 0,
authScopes: -1,
}
setLogLevel(logVerbose)
if len(configs) == 0 {
return nil
}
if err := Handler.validateConfigs(); err != nil {
return err
}
if logVerbose {
pluginsLogLevel = hclog.Debug
} else {
pluginsLogLevel = hclog.Info
}
kmsID := 0
for idx, config := range Handler.Configs {
switch config.Type {
@@ -151,6 +153,12 @@ func Initialize(configs []Config, logVerbose bool) error {
return err
}
Handler.searcher = plugin
case metadata.PluginName:
plugin, err := newMetadaterPlugin(config)
if err != nil {
return err
}
Handler.metadater = plugin
default:
return fmt.Errorf("unsupported plugin type: %v", config.Type)
}
@@ -163,6 +171,7 @@ func (m *Manager) validateConfigs() error {
kmsSchemes := make(map[string]bool)
kmsEncryptions := make(map[string]bool)
m.hasSearcher = false
m.hasMetadater = false
for _, config := range m.Configs {
if config.Type == kmsplugin.PluginName {
@@ -177,10 +186,16 @@ func (m *Manager) validateConfigs() error {
}
if config.Type == eventsearcher.PluginName {
if m.hasSearcher {
return fmt.Errorf("only one eventsearcher plugin can be defined")
return errors.New("only one eventsearcher plugin can be defined")
}
m.hasSearcher = true
}
if config.Type == metadata.PluginName {
if m.hasMetadater {
return errors.New("only one metadata plugin can be defined")
}
m.hasMetadater = true
}
}
return nil
}
@@ -242,6 +257,71 @@ func (m *Manager) SearchProviderEvents(startTimestamp, endTimestamp int64, usern
order, actions, objectTypes, instanceIDs, excludeIDs)
}
// HasMetadater returns true if a metadata plugin is defined
func (m *Manager) HasMetadater() bool {
return m.hasMetadater
}
// SetModificationTime sets the modification time for the specified object
func (m *Manager) SetModificationTime(storageID, objectPath string, mTime int64) error {
if !m.hasMetadater {
return ErrNoMetadater
}
m.metadaterLock.RLock()
plugin := m.metadater
m.metadaterLock.RUnlock()
return plugin.metadater.SetModificationTime(storageID, objectPath, mTime)
}
// GetModificationTime returns the modification time for the specified path
func (m *Manager) GetModificationTime(storageID, objectPath string, isDir bool) (int64, error) {
if !m.hasMetadater {
return 0, ErrNoMetadater
}
m.metadaterLock.RLock()
plugin := m.metadater
m.metadaterLock.RUnlock()
return plugin.metadater.GetModificationTime(storageID, objectPath)
}
// GetModificationTimes returns the modification times for all the files within the specified folder
func (m *Manager) GetModificationTimes(storageID, objectPath string) (map[string]int64, error) {
if !m.hasMetadater {
return nil, ErrNoMetadater
}
m.metadaterLock.RLock()
plugin := m.metadater
m.metadaterLock.RUnlock()
return plugin.metadater.GetModificationTimes(storageID, objectPath)
}
// RemoveMetadata deletes the metadata stored for the specified object
func (m *Manager) RemoveMetadata(storageID, objectPath string) error {
if !m.hasMetadater {
return ErrNoMetadater
}
m.metadaterLock.RLock()
plugin := m.metadater
m.metadaterLock.RUnlock()
return plugin.metadater.RemoveMetadata(storageID, objectPath)
}
// GetMetadataFolders returns the folders that metadata is associated with
func (m *Manager) GetMetadataFolders(storageID, from string, limit int) ([]string, error) {
if !m.hasMetadater {
return nil, ErrNoMetadater
}
m.metadaterLock.RLock()
plugin := m.metadater
m.metadaterLock.RUnlock()
return plugin.metadater.GetFolders(storageID, limit, from)
}
func (m *Manager) kmsEncrypt(secret kms.BaseSecret, url string, masterKey string, kmsID int) (string, string, int32, error) {
m.kmsLock.RLock()
plugin := m.kms[kmsID]
@@ -417,6 +497,7 @@ func (m *Manager) checkCrashedPlugins() {
}
}
m.authLock.RUnlock()
if m.hasSearcher {
m.searcherLock.RLock()
if m.searcher.exited() {
@@ -426,6 +507,16 @@ func (m *Manager) checkCrashedPlugins() {
}
m.searcherLock.RUnlock()
}
if m.hasMetadater {
m.metadaterLock.RLock()
if m.metadater.exited() {
defer func(cfg Config) {
Handler.restartMetadaterPlugin(cfg)
}(m.metadater.config)
}
m.metadaterLock.RUnlock()
}
}
func (m *Manager) restartNotifierPlugin(config Config, idx int) {
@@ -494,6 +585,22 @@ func (m *Manager) restartSearcherPlugin(config Config) {
m.searcherLock.Unlock()
}
func (m *Manager) restartMetadaterPlugin(config Config) {
if atomic.LoadInt32(&m.closed) == 1 {
return
}
logger.Info(logSender, "", "try to restart crashed metadater plugin %#v", config.Cmd)
plugin, err := newMetadaterPlugin(config)
if err != nil {
logger.Warn(logSender, "", "unable to restart metadater plugin %#v, err: %v", config.Cmd, err)
return
}
m.metadaterLock.Lock()
m.metadater = plugin
m.metadaterLock.Unlock()
}
// Cleanup releases all the active plugins
func (m *Manager) Cleanup() {
logger.Debug(logSender, "", "cleanup")
@@ -526,6 +633,21 @@ func (m *Manager) Cleanup() {
m.searcher.cleanup()
m.searcherLock.Unlock()
}
if m.hasMetadater {
m.metadaterLock.Lock()
logger.Debug(logSender, "", "cleanup metadater plugin %v", m.metadater.config.Cmd)
m.metadater.cleanup()
m.metadaterLock.Unlock()
}
}
func setLogLevel(logVerbose bool) {
if logVerbose {
pluginsLogLevel = hclog.Debug
} else {
pluginsLogLevel = hclog.Info
}
}
func startCheckTicker() {