mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-17 21:34:56 +00:00
make the file service multi-tenant and add read endpoint
This commit is contained in:
@@ -2,13 +2,13 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/micro/micro/v3/service/auth"
|
"github.com/micro/micro/v3/service/errors"
|
||||||
log "github.com/micro/micro/v3/service/logger"
|
log "github.com/micro/micro/v3/service/logger"
|
||||||
"github.com/micro/micro/v3/service/model"
|
"github.com/micro/micro/v3/service/model"
|
||||||
file "github.com/micro/services/file/proto"
|
file "github.com/micro/services/file/proto"
|
||||||
|
"github.com/micro/services/pkg/tenant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
@@ -32,50 +32,95 @@ func NewFile() *File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveResponse) error {
|
func (e *File) Read(ctx context.Context, req *file.ReadRequest, rsp *file.ReadResponse) error {
|
||||||
// @todo return proper micro errors
|
log.Info("Received File.Read request")
|
||||||
acc, ok := auth.AccountFromContext(ctx)
|
|
||||||
|
if len(req.Path) == 0 {
|
||||||
|
return errors.BadRequest("file.read", "missing file path")
|
||||||
|
}
|
||||||
|
|
||||||
|
tenantId, ok := tenant.FromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("File.Save requires authentication")
|
tenantId = "micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
var files []*file.Record
|
||||||
|
|
||||||
|
project := tenantId + "/" + req.Project
|
||||||
|
|
||||||
|
// read all the files for the project
|
||||||
|
err := e.db.Read(model.QueryEquals("project", project), &files)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter the file
|
||||||
|
for _, file := range files {
|
||||||
|
if file.Path == req.Path {
|
||||||
|
// strip the tenant id
|
||||||
|
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
|
||||||
|
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||||
|
rsp.File = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveResponse) error {
|
||||||
|
tenantId, ok := tenant.FromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
tenantId = "micro"
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Received File.Save request")
|
log.Info("Received File.Save request")
|
||||||
|
|
||||||
for _, reqFile := range req.Files {
|
for _, reqFile := range req.Files {
|
||||||
f := file.Record{}
|
// prefix the tenant
|
||||||
err := e.db.Read(model.QueryEquals("Id", reqFile.Id), &f)
|
reqFile.Id = tenantId + "/" + reqFile.Id
|
||||||
if err != nil && err != model.ErrorNotFound {
|
reqFile.Project = tenantId + "/" + reqFile.Project
|
||||||
return err
|
|
||||||
}
|
// create the file
|
||||||
// if file exists check ownership
|
err := e.db.Create(reqFile)
|
||||||
if f.Id != "" && f.Owner != acc.ID {
|
|
||||||
return errors.New("Not authorized")
|
|
||||||
}
|
|
||||||
err = e.db.Create(reqFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error {
|
func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error {
|
||||||
log.Info("Received File.List request")
|
log.Info("Received File.List request")
|
||||||
rsp.Files = []*file.Record{}
|
|
||||||
err := e.db.Read(model.QueryEquals("project", req.GetProject()), &rsp.Files)
|
tenantId, ok := tenant.FromContext(ctx)
|
||||||
if err != nil {
|
if !ok {
|
||||||
|
tenantId = "micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefix tenant id
|
||||||
|
project := tenantId + "/" + req.Project
|
||||||
|
|
||||||
|
var files []*file.Record
|
||||||
|
|
||||||
|
// read all the files for the project
|
||||||
|
if err := e.db.Read(model.QueryEquals("project", project), &files); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo funnily while this is the archetypical
|
// @todo funnily while this is the archetypical
|
||||||
// query for the KV store interface, it's not supported by the model
|
// query for the KV store interface, it's not supported by the model
|
||||||
// so we do client side filtering here
|
// so we do client side filtering here
|
||||||
if req.Path != "" {
|
for _, file := range rsp.Files {
|
||||||
filtered := []*file.Record{}
|
// strip the prefixes
|
||||||
for _, file := range rsp.Files {
|
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
|
||||||
if strings.HasPrefix(file.Path, req.Path) {
|
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||||
filtered = append(filtered, file)
|
|
||||||
}
|
// if requesting all files or path matches
|
||||||
|
if req.Path == "" || strings.HasPrefix(file.Path, req.Path) {
|
||||||
|
rsp.Files = append(rsp.Files, file)
|
||||||
}
|
}
|
||||||
rsp.Files = filtered
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.26.0
|
// protoc-gen-go v1.26.0
|
||||||
// protoc v3.6.1
|
// protoc v3.15.6
|
||||||
// source: proto/file.proto
|
// source: proto/file.proto
|
||||||
|
|
||||||
package file
|
package file
|
||||||
@@ -137,6 +137,112 @@ func (x *Record) GetOwner() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read a file by path
|
||||||
|
type ReadRequest struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
// project name
|
||||||
|
Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"`
|
||||||
|
// path to the file
|
||||||
|
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadRequest) Reset() {
|
||||||
|
*x = ReadRequest{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_proto_file_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ReadRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ReadRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_proto_file_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 ReadRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ReadRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_proto_file_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadRequest) GetProject() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Project
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadRequest) GetPath() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Path
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReadResponse struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
// Returns the file
|
||||||
|
File *Record `protobuf:"bytes,1,opt,name=file,proto3" json:"file,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadResponse) Reset() {
|
||||||
|
*x = ReadResponse{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_proto_file_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ReadResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ReadResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_proto_file_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 ReadResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ReadResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_proto_file_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ReadResponse) GetFile() *Record {
|
||||||
|
if x != nil {
|
||||||
|
return x.File
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// The save endpoint lets you batch save text file.
|
// The save endpoint lets you batch save text file.
|
||||||
type SaveRequest struct {
|
type SaveRequest struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
@@ -149,7 +255,7 @@ type SaveRequest struct {
|
|||||||
func (x *SaveRequest) Reset() {
|
func (x *SaveRequest) Reset() {
|
||||||
*x = SaveRequest{}
|
*x = SaveRequest{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proto_file_proto_msgTypes[1]
|
mi := &file_proto_file_proto_msgTypes[3]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -162,7 +268,7 @@ func (x *SaveRequest) String() string {
|
|||||||
func (*SaveRequest) ProtoMessage() {}
|
func (*SaveRequest) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *SaveRequest) ProtoReflect() protoreflect.Message {
|
func (x *SaveRequest) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proto_file_proto_msgTypes[1]
|
mi := &file_proto_file_proto_msgTypes[3]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -175,7 +281,7 @@ func (x *SaveRequest) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use SaveRequest.ProtoReflect.Descriptor instead.
|
// Deprecated: Use SaveRequest.ProtoReflect.Descriptor instead.
|
||||||
func (*SaveRequest) Descriptor() ([]byte, []int) {
|
func (*SaveRequest) Descriptor() ([]byte, []int) {
|
||||||
return file_proto_file_proto_rawDescGZIP(), []int{1}
|
return file_proto_file_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SaveRequest) GetFiles() []*Record {
|
func (x *SaveRequest) GetFiles() []*Record {
|
||||||
@@ -194,7 +300,7 @@ type SaveResponse struct {
|
|||||||
func (x *SaveResponse) Reset() {
|
func (x *SaveResponse) Reset() {
|
||||||
*x = SaveResponse{}
|
*x = SaveResponse{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proto_file_proto_msgTypes[2]
|
mi := &file_proto_file_proto_msgTypes[4]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -207,7 +313,7 @@ func (x *SaveResponse) String() string {
|
|||||||
func (*SaveResponse) ProtoMessage() {}
|
func (*SaveResponse) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *SaveResponse) ProtoReflect() protoreflect.Message {
|
func (x *SaveResponse) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proto_file_proto_msgTypes[2]
|
mi := &file_proto_file_proto_msgTypes[4]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -220,7 +326,7 @@ func (x *SaveResponse) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use SaveResponse.ProtoReflect.Descriptor instead.
|
// Deprecated: Use SaveResponse.ProtoReflect.Descriptor instead.
|
||||||
func (*SaveResponse) Descriptor() ([]byte, []int) {
|
func (*SaveResponse) Descriptor() ([]byte, []int) {
|
||||||
return file_proto_file_proto_rawDescGZIP(), []int{2}
|
return file_proto_file_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
// List file by their project and optionally a path.
|
// List file by their project and optionally a path.
|
||||||
@@ -241,7 +347,7 @@ type ListRequest struct {
|
|||||||
func (x *ListRequest) Reset() {
|
func (x *ListRequest) Reset() {
|
||||||
*x = ListRequest{}
|
*x = ListRequest{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proto_file_proto_msgTypes[3]
|
mi := &file_proto_file_proto_msgTypes[5]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -254,7 +360,7 @@ func (x *ListRequest) String() string {
|
|||||||
func (*ListRequest) ProtoMessage() {}
|
func (*ListRequest) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proto_file_proto_msgTypes[3]
|
mi := &file_proto_file_proto_msgTypes[5]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -267,7 +373,7 @@ func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
|
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
|
||||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||||
return file_proto_file_proto_rawDescGZIP(), []int{3}
|
return file_proto_file_proto_rawDescGZIP(), []int{5}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListRequest) GetProject() string {
|
func (x *ListRequest) GetProject() string {
|
||||||
@@ -295,7 +401,7 @@ type ListResponse struct {
|
|||||||
func (x *ListResponse) Reset() {
|
func (x *ListResponse) Reset() {
|
||||||
*x = ListResponse{}
|
*x = ListResponse{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proto_file_proto_msgTypes[4]
|
mi := &file_proto_file_proto_msgTypes[6]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -308,7 +414,7 @@ func (x *ListResponse) String() string {
|
|||||||
func (*ListResponse) ProtoMessage() {}
|
func (*ListResponse) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proto_file_proto_msgTypes[4]
|
mi := &file_proto_file_proto_msgTypes[6]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -321,7 +427,7 @@ func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.
|
// Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.
|
||||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||||
return file_proto_file_proto_rawDescGZIP(), []int{4}
|
return file_proto_file_proto_rawDescGZIP(), []int{6}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListResponse) GetFiles() []*Record {
|
func (x *ListResponse) GetFiles() []*Record {
|
||||||
@@ -350,26 +456,36 @@ var file_proto_file_proto_rawDesc = []byte{
|
|||||||
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74,
|
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74,
|
||||||
0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
|
0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||||
0x64, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09,
|
0x64, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x31, 0x0a, 0x0b, 0x53, 0x61, 0x76, 0x65, 0x52,
|
0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x3b, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52,
|
||||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18,
|
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63,
|
||||||
|
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74,
|
||||||
|
0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||||
|
0x70, 0x61, 0x74, 0x68, 0x22, 0x30, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70,
|
||||||
|
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01,
|
||||||
|
0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||||
|
0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x31, 0x0a, 0x0b, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65,
|
||||||
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x01,
|
||||||
|
0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f,
|
||||||
|
0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x61, 0x76,
|
||||||
|
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x4c, 0x69, 0x73,
|
||||||
|
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a,
|
||||||
|
0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65,
|
||||||
|
0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||||
|
0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x32, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
|
||||||
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18,
|
||||||
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63,
|
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63,
|
||||||
0x6f, 0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x61,
|
0x6f, 0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x32, 0x99, 0x01, 0x0a, 0x04, 0x46,
|
||||||
0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x4c, 0x69,
|
0x69, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x11, 0x2e, 0x66, 0x69,
|
||||||
0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f,
|
0x6c, 0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12,
|
||||||
0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a,
|
0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x65, 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x11, 0x2e, 0x66,
|
||||||
0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x32, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52,
|
0x69, 0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
||||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73,
|
0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||||
0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65,
|
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e,
|
||||||
0x63, 0x6f, 0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x32, 0x68, 0x0a, 0x04, 0x46,
|
0x66, 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||||
0x69, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x11, 0x2e, 0x66, 0x69,
|
0x1a, 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70,
|
||||||
0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12,
|
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
||||||
0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
0x6f, 0x3b, 0x66, 0x69, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x66,
|
|
||||||
0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
|
||||||
0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
|
||||||
0x3b, 0x66, 0x69, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -384,26 +500,31 @@ func file_proto_file_proto_rawDescGZIP() []byte {
|
|||||||
return file_proto_file_proto_rawDescData
|
return file_proto_file_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
var file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||||
var file_proto_file_proto_goTypes = []interface{}{
|
var file_proto_file_proto_goTypes = []interface{}{
|
||||||
(*Record)(nil), // 0: file.Record
|
(*Record)(nil), // 0: file.Record
|
||||||
(*SaveRequest)(nil), // 1: file.SaveRequest
|
(*ReadRequest)(nil), // 1: file.ReadRequest
|
||||||
(*SaveResponse)(nil), // 2: file.SaveResponse
|
(*ReadResponse)(nil), // 2: file.ReadResponse
|
||||||
(*ListRequest)(nil), // 3: file.ListRequest
|
(*SaveRequest)(nil), // 3: file.SaveRequest
|
||||||
(*ListResponse)(nil), // 4: file.ListResponse
|
(*SaveResponse)(nil), // 4: file.SaveResponse
|
||||||
|
(*ListRequest)(nil), // 5: file.ListRequest
|
||||||
|
(*ListResponse)(nil), // 6: file.ListResponse
|
||||||
}
|
}
|
||||||
var file_proto_file_proto_depIdxs = []int32{
|
var file_proto_file_proto_depIdxs = []int32{
|
||||||
0, // 0: file.SaveRequest.files:type_name -> file.Record
|
0, // 0: file.ReadResponse.file:type_name -> file.Record
|
||||||
0, // 1: file.ListResponse.files:type_name -> file.Record
|
0, // 1: file.SaveRequest.files:type_name -> file.Record
|
||||||
1, // 2: file.File.Save:input_type -> file.SaveRequest
|
0, // 2: file.ListResponse.files:type_name -> file.Record
|
||||||
3, // 3: file.File.List:input_type -> file.ListRequest
|
1, // 3: file.File.Read:input_type -> file.ReadRequest
|
||||||
2, // 4: file.File.Save:output_type -> file.SaveResponse
|
3, // 4: file.File.Save:input_type -> file.SaveRequest
|
||||||
4, // 5: file.File.List:output_type -> file.ListResponse
|
5, // 5: file.File.List:input_type -> file.ListRequest
|
||||||
4, // [4:6] is the sub-list for method output_type
|
2, // 6: file.File.Read:output_type -> file.ReadResponse
|
||||||
2, // [2:4] is the sub-list for method input_type
|
4, // 7: file.File.Save:output_type -> file.SaveResponse
|
||||||
2, // [2:2] is the sub-list for extension type_name
|
6, // 8: file.File.List:output_type -> file.ListResponse
|
||||||
2, // [2:2] is the sub-list for extension extendee
|
6, // [6:9] is the sub-list for method output_type
|
||||||
0, // [0:2] is the sub-list for field type_name
|
3, // [3:6] is the sub-list for method input_type
|
||||||
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
|
3, // [3:3] is the sub-list for extension extendee
|
||||||
|
0, // [0:3] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_proto_file_proto_init() }
|
func init() { file_proto_file_proto_init() }
|
||||||
@@ -425,7 +546,7 @@ func file_proto_file_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*SaveRequest); i {
|
switch v := v.(*ReadRequest); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
case 1:
|
case 1:
|
||||||
@@ -437,7 +558,7 @@ func file_proto_file_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*SaveResponse); i {
|
switch v := v.(*ReadResponse); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
case 1:
|
case 1:
|
||||||
@@ -449,7 +570,7 @@ func file_proto_file_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*ListRequest); i {
|
switch v := v.(*SaveRequest); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
case 1:
|
case 1:
|
||||||
@@ -461,6 +582,30 @@ func file_proto_file_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SaveResponse); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_proto_file_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*ListRequest); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_proto_file_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*ListResponse); i {
|
switch v := v.(*ListResponse); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -479,7 +624,7 @@ func file_proto_file_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_proto_file_proto_rawDesc,
|
RawDescriptor: file_proto_file_proto_rawDesc,
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 5,
|
NumMessages: 7,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func NewFileEndpoints() []*api.Endpoint {
|
|||||||
// Client API for File service
|
// Client API for File service
|
||||||
|
|
||||||
type FileService interface {
|
type FileService interface {
|
||||||
|
Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error)
|
||||||
Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error)
|
Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error)
|
||||||
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
||||||
}
|
}
|
||||||
@@ -58,6 +59,16 @@ func NewFileService(name string, c client.Client) FileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *fileService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) {
|
||||||
|
req := c.c.NewRequest(c.name, "File.Read", in)
|
||||||
|
out := new(ReadResponse)
|
||||||
|
err := c.c.Call(ctx, req, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *fileService) Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error) {
|
func (c *fileService) Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error) {
|
||||||
req := c.c.NewRequest(c.name, "File.Save", in)
|
req := c.c.NewRequest(c.name, "File.Save", in)
|
||||||
out := new(SaveResponse)
|
out := new(SaveResponse)
|
||||||
@@ -81,12 +92,14 @@ func (c *fileService) List(ctx context.Context, in *ListRequest, opts ...client.
|
|||||||
// Server API for File service
|
// Server API for File service
|
||||||
|
|
||||||
type FileHandler interface {
|
type FileHandler interface {
|
||||||
|
Read(context.Context, *ReadRequest, *ReadResponse) error
|
||||||
Save(context.Context, *SaveRequest, *SaveResponse) error
|
Save(context.Context, *SaveRequest, *SaveResponse) error
|
||||||
List(context.Context, *ListRequest, *ListResponse) error
|
List(context.Context, *ListRequest, *ListResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterFileHandler(s server.Server, hdlr FileHandler, opts ...server.HandlerOption) error {
|
func RegisterFileHandler(s server.Server, hdlr FileHandler, opts ...server.HandlerOption) error {
|
||||||
type file interface {
|
type file interface {
|
||||||
|
Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error
|
||||||
Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error
|
Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error
|
||||||
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
||||||
}
|
}
|
||||||
@@ -101,6 +114,10 @@ type fileHandler struct {
|
|||||||
FileHandler
|
FileHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *fileHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error {
|
||||||
|
return h.FileHandler.Read(ctx, in, out)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *fileHandler) Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error {
|
func (h *fileHandler) Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error {
|
||||||
return h.FileHandler.Save(ctx, in, out)
|
return h.FileHandler.Save(ctx, in, out)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package file;
|
|||||||
option go_package = "./proto;file";
|
option go_package = "./proto;file";
|
||||||
|
|
||||||
service File {
|
service File {
|
||||||
|
rpc Read(ReadRequest) returns (ReadResponse) {}
|
||||||
rpc Save(SaveRequest) returns (SaveResponse) {}
|
rpc Save(SaveRequest) returns (SaveResponse) {}
|
||||||
rpc List(ListRequest) returns (ListResponse) {}
|
rpc List(ListRequest) returns (ListResponse) {}
|
||||||
}
|
}
|
||||||
@@ -27,6 +28,19 @@ message Record {
|
|||||||
string owner = 9;
|
string owner = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read a file by path
|
||||||
|
message ReadRequest {
|
||||||
|
// project name
|
||||||
|
string project = 1;
|
||||||
|
// path to the file
|
||||||
|
string path = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ReadResponse {
|
||||||
|
// Returns the file
|
||||||
|
Record file = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// The save endpoint lets you batch save text file.
|
// The save endpoint lets you batch save text file.
|
||||||
message SaveRequest {
|
message SaveRequest {
|
||||||
repeated Record files = 1;
|
repeated Record files = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user