Merge pull request 'feature/binaries' (#20) from feature/binaries into master

Reviewed-on: https://gitea.benny.dog/torjus/ezshare/pulls/20
This commit is contained in:
Torjus Håkestad 2021-12-08 05:38:13 +00:00
commit 10ab3950d3
19 changed files with 1108 additions and 113 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/*
tmp/*
dist/*
ezshare.toml
ezshare.test.toml

89
actions/admin.go Normal file
View File

@ -0,0 +1,89 @@
package actions
import (
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"gitea.benny.dog/torjus/ezshare/pb"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
)
func ParseBinary(path string) (*pb.Binary, error) {
baseName := filepath.Base(path)
pattern := `ezshare-(\d+\.\d+\.\d+).([a-z]+)-([a-z1-9]+)(\.exe)*`
re := regexp.MustCompile(pattern)
match := re.FindStringSubmatch(baseName)
if len(match) < 4 {
return nil, fmt.Errorf("invalid filename")
}
version := fmt.Sprintf("v%s", match[1])
operatingSystem := match[2]
arch := match[3]
binary := &pb.Binary{
Arch: arch,
Os: operatingSystem,
Version: version,
}
// TODO: Verify that os and arch are valid
f, err := os.Open(path)
if err != nil {
return nil, err
}
binary.Data, err = io.ReadAll(f)
if err != nil {
return nil, err
}
return binary, nil
}
func ActionAdminUploadBinary(c *cli.Context) error {
if c.Args().Len() < 1 {
return cli.Exit("need at least 1 argument", 1)
}
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds), grpc.WithMaxMsgSize(1024*1024*100))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewBinaryServiceClient(conn)
var binaries []*pb.Binary
for _, arg := range c.Args().Slice() {
binary, err := ParseBinary(arg)
if err != nil {
return cli.Exit(fmt.Sprintf("error reading binary: %s", err), 1)
}
binaries = append(binaries, binary)
}
if _, err := client.UploadBinaries(c.Context, &pb.UploadBinariesRequest{Binaries: binaries}); err != nil {
return cli.Exit(fmt.Sprintf("error upload binaries: %s", err), 1)
}
return nil
}

View File

@ -12,11 +12,13 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"syscall"
"time"
"gitea.benny.dog/torjus/ezshare/certs"
"gitea.benny.dog/torjus/ezshare/config"
"gitea.benny.dog/torjus/ezshare/ezshare"
"gitea.benny.dog/torjus/ezshare/pb"
"gitea.benny.dog/torjus/ezshare/server"
"github.com/urfave/cli/v2"
@ -470,3 +472,66 @@ func ActionClientCertRevoke(c *cli.Context) error {
}
return nil
}
func ActionClientUpdate(c *cli.Context) error {
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewBinaryServiceClient(conn)
// Check if we have the latest version
resp, err := client.GetLatestVersion(c.Context, &pb.Empty{})
if err != nil {
return cli.Exit(fmt.Sprintf("Error getting latest version: %s", err), 1)
}
if resp.Version == ezshare.Version {
fmt.Println("Already running latest version.")
return nil
}
// Fetch latest version
bin, err := client.GetBinary(c.Context, &pb.GetBinaryRequest{Version: "latest", Arch: runtime.GOARCH, Os: runtime.GOOS})
if err != nil {
return cli.Exit(fmt.Sprintf("Error getting binary: %s", err), 1)
}
outDir := "."
if c.IsSet("out-dir") {
outDir = c.String("out-dir")
}
filename := fmt.Sprintf("ezshare-%s-%s-%s", bin.Version[1:], bin.Os, bin.Arch)
if runtime.GOOS == "windows" {
filename = fmt.Sprintf("%s.exe", filename)
}
outputPath := filepath.Join(outDir, filename)
f, err := os.Create(outputPath)
if err != nil {
return cli.Exit(fmt.Sprintf("Unable to write latest binary: %s", err), 1)
}
if _, err := f.Write(bin.Data); err != nil {
return cli.Exit(fmt.Sprintf("Unable to write latest binary: %s", err), 1)
}
fmt.Printf("Wrote latest binary to %s", outputPath)
return nil
}

View File

@ -8,6 +8,9 @@ import (
"github.com/urfave/cli/v2"
)
// TODO: This should probably be in some more sensible package
const Version = "v0.1.1"
func ActionGencerts(c *cli.Context) error {
outDir := "."
if c.IsSet("out-dir") {

View File

@ -34,6 +34,7 @@ func ActionServe(c *cli.Context) error {
authLogger := logger.Named("AUTH")
httpLogger := logger.Named("HTTP")
certLogger := logger.Named("CERT")
binsLogger := logger.Named("BINS")
// Read certificates
srvCertBytes, err := cfg.Server.GRPC.Certs.GetCertBytes()
@ -82,6 +83,9 @@ func ActionServe(c *cli.Context) error {
return fmt.Errorf("error initializing certificate service: %w", err)
}
// Setup binary store
binaryStore := store.NewMemoryStore()
// Setup shutdown-handling
rootCtx, rootCancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer rootCancel()
@ -117,6 +121,9 @@ func ActionServe(c *cli.Context) error {
grpcUserServer := server.NewGRPCUserServiceServer(userStore, certSvc)
grpcUserServer.Logger = logger.Named("USER")
binaryServer := server.NewBinaryServiceServer(binaryStore)
binaryServer.Logger = binsLogger
lis, err := net.Listen("tcp", grpcAddr)
if err != nil {
serverLogger.Errorw("Unable to setup GRPC listener.", "error", err)
@ -140,12 +147,15 @@ func ActionServe(c *cli.Context) error {
creds := credentials.NewTLS(tlsConfig)
grpcServer := grpc.NewServer(
grpc.MaxRecvMsgSize(100*1024*1024),
grpc.MaxSendMsgSize(100*1024*1024),
grpc.Creds(creds),
grpc.ChainUnaryInterceptor(interceptors.NewAuthInterceptor(userStore, certSvc, authLogger)),
)
pb.RegisterFileServiceServer(grpcServer, grpcFileServer)
pb.RegisterUserServiceServer(grpcServer, grpcUserServer)
pb.RegisterCertificateServiceServer(grpcServer, certServiceServer)
pb.RegisterBinaryServiceServer(grpcServer, binaryServer)
// wait for cancel
go func() {
@ -173,7 +183,7 @@ func ActionServe(c *cli.Context) error {
if c.IsSet("http-addr") {
httpAddr = c.String("http-addr")
}
httpServer := server.NewHTTPSever(s, srvCertBytes, cfg.Server.GRPCEndpoint)
httpServer := server.NewHTTPSever(s, binaryStore, srvCertBytes, cfg.Server.GRPCEndpoint)
httpServer.Logger = httpLogger
httpServer.Addr = httpAddr

4
ezshare/version.go Normal file
View File

@ -0,0 +1,4 @@
package ezshare
// TODO: Maybe put this somewhere more sensible
const Version = "v0.1.1"

28
main.go
View File

@ -5,16 +5,15 @@ import (
"os"
"gitea.benny.dog/torjus/ezshare/actions"
"gitea.benny.dog/torjus/ezshare/ezshare"
"github.com/urfave/cli/v2"
)
const Version = "v0.1.1"
func main() {
cli.VersionFlag = &cli.BoolFlag{Name: "version"}
app := cli.App{
Name: "ezshare",
Version: Version,
Version: ezshare.Version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
@ -128,6 +127,17 @@ func main() {
Usage: "Initialize default config",
Action: actions.ActionInitConfig,
},
{
Name: "update",
Usage: "Download the latest ezshare",
Action: actions.ActionClientUpdate,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "out-dir",
Usage: "Directory where binary is saved",
},
},
},
{
Name: "cert",
Usage: "Certificate-related commands",
@ -147,6 +157,18 @@ func main() {
},
},
},
{
Name: "admin",
Usage: "Admin commands",
Subcommands: []*cli.Command{
{
Name: "upload",
Usage: "Upload binaries to be served",
ArgsUsage: "FILENAME [FILENAME...]",
Action: actions.ActionAdminUploadBinary,
},
},
},
{
Name: "cert",
Usage: "Certificate commands",

View File

@ -1184,6 +1184,234 @@ func (x *RevokeCertificateRequest) GetSerial() string {
return ""
}
type Binary struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
Arch string `protobuf:"bytes,2,opt,name=arch,proto3" json:"arch,omitempty"`
Os string `protobuf:"bytes,3,opt,name=os,proto3" json:"os,omitempty"`
Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *Binary) Reset() {
*x = Binary{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Binary) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Binary) ProtoMessage() {}
func (x *Binary) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[21]
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 Binary.ProtoReflect.Descriptor instead.
func (*Binary) Descriptor() ([]byte, []int) {
return file_protos_ezshare_proto_rawDescGZIP(), []int{21}
}
func (x *Binary) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
func (x *Binary) GetArch() string {
if x != nil {
return x.Arch
}
return ""
}
func (x *Binary) GetOs() string {
if x != nil {
return x.Os
}
return ""
}
func (x *Binary) GetData() []byte {
if x != nil {
return x.Data
}
return nil
}
type UploadBinariesRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Binaries []*Binary `protobuf:"bytes,2,rep,name=binaries,proto3" json:"binaries,omitempty"`
}
func (x *UploadBinariesRequest) Reset() {
*x = UploadBinariesRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UploadBinariesRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UploadBinariesRequest) ProtoMessage() {}
func (x *UploadBinariesRequest) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[22]
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 UploadBinariesRequest.ProtoReflect.Descriptor instead.
func (*UploadBinariesRequest) Descriptor() ([]byte, []int) {
return file_protos_ezshare_proto_rawDescGZIP(), []int{22}
}
func (x *UploadBinariesRequest) GetBinaries() []*Binary {
if x != nil {
return x.Binaries
}
return nil
}
type GetBinaryRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
Arch string `protobuf:"bytes,2,opt,name=arch,proto3" json:"arch,omitempty"`
Os string `protobuf:"bytes,3,opt,name=os,proto3" json:"os,omitempty"`
}
func (x *GetBinaryRequest) Reset() {
*x = GetBinaryRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetBinaryRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetBinaryRequest) ProtoMessage() {}
func (x *GetBinaryRequest) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[23]
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 GetBinaryRequest.ProtoReflect.Descriptor instead.
func (*GetBinaryRequest) Descriptor() ([]byte, []int) {
return file_protos_ezshare_proto_rawDescGZIP(), []int{23}
}
func (x *GetBinaryRequest) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
func (x *GetBinaryRequest) GetArch() string {
if x != nil {
return x.Arch
}
return ""
}
func (x *GetBinaryRequest) GetOs() string {
if x != nil {
return x.Os
}
return ""
}
type LatestVersionResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
}
func (x *LatestVersionResponse) Reset() {
*x = LatestVersionResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LatestVersionResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LatestVersionResponse) ProtoMessage() {}
func (x *LatestVersionResponse) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[24]
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 LatestVersionResponse.ProtoReflect.Descriptor instead.
func (*LatestVersionResponse) Descriptor() ([]byte, []int) {
return file_protos_ezshare_proto_rawDescGZIP(), []int{24}
}
func (x *LatestVersionResponse) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
type File_Metadata struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1201,7 +1429,7 @@ type File_Metadata struct {
func (x *File_Metadata) Reset() {
*x = File_Metadata{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[21]
mi := &file_protos_ezshare_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1214,7 +1442,7 @@ func (x *File_Metadata) String() string {
func (*File_Metadata) ProtoMessage() {}
func (x *File_Metadata) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[21]
mi := &file_protos_ezshare_proto_msgTypes[25]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1291,7 +1519,7 @@ type ListFilesResponse_ListFileInfo struct {
func (x *ListFilesResponse_ListFileInfo) Reset() {
*x = ListFilesResponse_ListFileInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[22]
mi := &file_protos_ezshare_proto_msgTypes[26]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1304,7 +1532,7 @@ func (x *ListFilesResponse_ListFileInfo) String() string {
func (*ListFilesResponse_ListFileInfo) ProtoMessage() {}
func (x *ListFilesResponse_ListFileInfo) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[22]
mi := &file_protos_ezshare_proto_msgTypes[26]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1347,7 +1575,7 @@ type ListCertificatesResponse_CertificateInfo struct {
func (x *ListCertificatesResponse_CertificateInfo) Reset() {
*x = ListCertificatesResponse_CertificateInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_protos_ezshare_proto_msgTypes[23]
mi := &file_protos_ezshare_proto_msgTypes[27]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1360,7 +1588,7 @@ func (x *ListCertificatesResponse_CertificateInfo) String() string {
func (*ListCertificatesResponse_CertificateInfo) ProtoMessage() {}
func (x *ListCertificatesResponse_CertificateInfo) ProtoReflect() protoreflect.Message {
mi := &file_protos_ezshare_proto_msgTypes[23]
mi := &file_protos_ezshare_proto_msgTypes[27]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1535,60 +1763,92 @@ var file_protos_ezshare_proto_rawDesc = []byte{
0x18, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61,
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72,
0x69, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x72, 0x69, 0x61,
0x6c, 0x32, 0xa5, 0x02, 0x0a, 0x0b, 0x46, 0x69, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x47, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x12,
0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64,
0x6c, 0x22, 0x5a, 0x0a, 0x06, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76,
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x63, 0x68, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x63, 0x68, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x73, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x6f, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74,
0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x44, 0x0a,
0x15, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x69, 0x65, 0x73, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x08, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x69,
0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61,
0x72, 0x65, 0x2e, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x52, 0x08, 0x62, 0x69, 0x6e, 0x61, 0x72,
0x69, 0x65, 0x73, 0x22, 0x50, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69,
0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x63, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x61, 0x72, 0x63, 0x68, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x02, 0x6f, 0x73, 0x22, 0x31, 0x0a, 0x15, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x56,
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x32, 0xa5, 0x02, 0x0a, 0x0b, 0x46, 0x69, 0x6c,
0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f,
0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65,
0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x6c,
0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x12, 0x3e, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x17, 0x2e, 0x65,
0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e,
0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x12, 0x47, 0x0a, 0x0a, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x12,
0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x65, 0x7a,
0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x07, 0x47, 0x65,
0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x17, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e,
0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18,
0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0a, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61,
0x72, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x73,
0x12, 0x19, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x46,
0x69, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x7a,
0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x32, 0xd9, 0x02, 0x0a, 0x0b, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x49, 0x0a, 0x08, 0x52, 0x65, 0x67,
0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e,
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x52, 0x65,
0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x19, 0x2e,
0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61,
0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19,
0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65,
0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68,
0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x72, 0x6f,
0x76, 0x65, 0x12, 0x1b, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70,
0x72, 0x6f, 0x76, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22,
0x00, 0x12, 0x42, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77,
0x6f, 0x72, 0x64, 0x12, 0x1e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x43, 0x68,
0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d,
0x70, 0x74, 0x79, 0x22, 0x00, 0x32, 0xa7, 0x01, 0x0a, 0x12, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66,
0x69, 0x63, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x10,
0x4c, 0x69, 0x73, 0x74, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73,
0x12, 0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
0x1a, 0x21, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43,
0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x11, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x43,
0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x21, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x43, 0x65, 0x72, 0x74, 0x69,
0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e,
0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42,
0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x62, 0x65, 0x6e, 0x6e, 0x79, 0x2e, 0x64,
0x6f, 0x67, 0x2f, 0x74, 0x6f, 0x72, 0x6a, 0x75, 0x73, 0x2f, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72,
0x65, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69,
0x73, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x12, 0x19, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72,
0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73,
0x74, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x32, 0xd9, 0x02, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x12, 0x49, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x65,
0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55,
0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x05, 0x4c,
0x6f, 0x67, 0x69, 0x6e, 0x12, 0x19, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c,
0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55,
0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a,
0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e,
0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x1a, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55,
0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x38,
0x0a, 0x07, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x65, 0x12, 0x1b, 0x2e, 0x65, 0x7a, 0x73, 0x68,
0x61, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65,
0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x42, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e,
0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1e, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77,
0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x32, 0xa7, 0x01, 0x0a,
0x12, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x65, 0x72, 0x74, 0x69,
0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x12, 0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72,
0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x21, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72,
0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x11,
0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x65, 0x12, 0x21, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x76, 0x6f,
0x6b, 0x65, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45,
0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x32, 0xd4, 0x01, 0x0a, 0x0d, 0x42, 0x69, 0x6e, 0x61, 0x72,
0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x42, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f,
0x61, 0x64, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x69, 0x65, 0x73, 0x12, 0x1e, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x42, 0x69, 0x6e, 0x61, 0x72,
0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x7a, 0x73,
0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x39, 0x0a, 0x09,
0x47, 0x65, 0x74, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x12, 0x19, 0x2e, 0x65, 0x7a, 0x73, 0x68,
0x61, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x42,
0x69, 0x6e, 0x61, 0x72, 0x79, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4c, 0x61,
0x74, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x2e, 0x65, 0x7a,
0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1e, 0x2e, 0x65, 0x7a,
0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x23, 0x5a,
0x21, 0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x62, 0x65, 0x6e, 0x6e, 0x79, 0x2e, 0x64, 0x6f, 0x67,
0x2f, 0x74, 0x6f, 0x72, 0x6a, 0x75, 0x73, 0x2f, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -1604,7 +1864,7 @@ func file_protos_ezshare_proto_rawDescGZIP() []byte {
}
var file_protos_ezshare_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_protos_ezshare_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_protos_ezshare_proto_msgTypes = make([]protoimpl.MessageInfo, 28)
var file_protos_ezshare_proto_goTypes = []interface{}{
(User_Role)(0), // 0: ezshare.User.Role
(*Empty)(nil), // 1: ezshare.Empty
@ -1628,49 +1888,60 @@ var file_protos_ezshare_proto_goTypes = []interface{}{
(*ChangePasswordRequest)(nil), // 19: ezshare.ChangePasswordRequest
(*ListCertificatesResponse)(nil), // 20: ezshare.ListCertificatesResponse
(*RevokeCertificateRequest)(nil), // 21: ezshare.RevokeCertificateRequest
(*File_Metadata)(nil), // 22: ezshare.File.Metadata
(*ListFilesResponse_ListFileInfo)(nil), // 23: ezshare.ListFilesResponse.ListFileInfo
(*ListCertificatesResponse_CertificateInfo)(nil), // 24: ezshare.ListCertificatesResponse.CertificateInfo
(*timestamppb.Timestamp)(nil), // 25: google.protobuf.Timestamp
(*Binary)(nil), // 22: ezshare.Binary
(*UploadBinariesRequest)(nil), // 23: ezshare.UploadBinariesRequest
(*GetBinaryRequest)(nil), // 24: ezshare.GetBinaryRequest
(*LatestVersionResponse)(nil), // 25: ezshare.LatestVersionResponse
(*File_Metadata)(nil), // 26: ezshare.File.Metadata
(*ListFilesResponse_ListFileInfo)(nil), // 27: ezshare.ListFilesResponse.ListFileInfo
(*ListCertificatesResponse_CertificateInfo)(nil), // 28: ezshare.ListCertificatesResponse.CertificateInfo
(*timestamppb.Timestamp)(nil), // 29: google.protobuf.Timestamp
}
var file_protos_ezshare_proto_depIdxs = []int32{
22, // 0: ezshare.File.metadata:type_name -> ezshare.File.Metadata
25, // 1: ezshare.UploadFileRequest.expires_on:type_name -> google.protobuf.Timestamp
26, // 0: ezshare.File.metadata:type_name -> ezshare.File.Metadata
29, // 1: ezshare.UploadFileRequest.expires_on:type_name -> google.protobuf.Timestamp
2, // 2: ezshare.GetFileResponse.file:type_name -> ezshare.File
23, // 3: ezshare.ListFilesResponse.files:type_name -> ezshare.ListFilesResponse.ListFileInfo
27, // 3: ezshare.ListFilesResponse.files:type_name -> ezshare.ListFilesResponse.ListFileInfo
0, // 4: ezshare.User.user_role:type_name -> ezshare.User.Role
11, // 5: ezshare.ListUsersResponse.users:type_name -> ezshare.User
24, // 6: ezshare.ListCertificatesResponse.certificates:type_name -> ezshare.ListCertificatesResponse.CertificateInfo
25, // 7: ezshare.File.Metadata.uploaded_on:type_name -> google.protobuf.Timestamp
25, // 8: ezshare.File.Metadata.expires_on:type_name -> google.protobuf.Timestamp
22, // 9: ezshare.ListFilesResponse.ListFileInfo.metadata:type_name -> ezshare.File.Metadata
3, // 10: ezshare.FileService.UploadFile:input_type -> ezshare.UploadFileRequest
5, // 11: ezshare.FileService.GetFile:input_type -> ezshare.GetFileRequest
7, // 12: ezshare.FileService.DeleteFile:input_type -> ezshare.DeleteFileRequest
9, // 13: ezshare.FileService.ListFiles:input_type -> ezshare.ListFilesRequest
12, // 14: ezshare.UserService.Register:input_type -> ezshare.RegisterUserRequest
14, // 15: ezshare.UserService.Login:input_type -> ezshare.LoginUserRequest
16, // 16: ezshare.UserService.List:input_type -> ezshare.ListUsersRequest
18, // 17: ezshare.UserService.Approve:input_type -> ezshare.ApproveUserRequest
19, // 18: ezshare.UserService.ChangePassword:input_type -> ezshare.ChangePasswordRequest
1, // 19: ezshare.CertificateService.ListCertificates:input_type -> ezshare.Empty
21, // 20: ezshare.CertificateService.RevokeCertificate:input_type -> ezshare.RevokeCertificateRequest
4, // 21: ezshare.FileService.UploadFile:output_type -> ezshare.UploadFileResponse
6, // 22: ezshare.FileService.GetFile:output_type -> ezshare.GetFileResponse
8, // 23: ezshare.FileService.DeleteFile:output_type -> ezshare.DeleteFileResponse
10, // 24: ezshare.FileService.ListFiles:output_type -> ezshare.ListFilesResponse
13, // 25: ezshare.UserService.Register:output_type -> ezshare.RegisterUserResponse
15, // 26: ezshare.UserService.Login:output_type -> ezshare.LoginUserResponse
17, // 27: ezshare.UserService.List:output_type -> ezshare.ListUsersResponse
1, // 28: ezshare.UserService.Approve:output_type -> ezshare.Empty
1, // 29: ezshare.UserService.ChangePassword:output_type -> ezshare.Empty
20, // 30: ezshare.CertificateService.ListCertificates:output_type -> ezshare.ListCertificatesResponse
1, // 31: ezshare.CertificateService.RevokeCertificate:output_type -> ezshare.Empty
21, // [21:32] is the sub-list for method output_type
10, // [10:21] is the sub-list for method input_type
10, // [10:10] is the sub-list for extension type_name
10, // [10:10] is the sub-list for extension extendee
0, // [0:10] is the sub-list for field type_name
28, // 6: ezshare.ListCertificatesResponse.certificates:type_name -> ezshare.ListCertificatesResponse.CertificateInfo
22, // 7: ezshare.UploadBinariesRequest.binaries:type_name -> ezshare.Binary
29, // 8: ezshare.File.Metadata.uploaded_on:type_name -> google.protobuf.Timestamp
29, // 9: ezshare.File.Metadata.expires_on:type_name -> google.protobuf.Timestamp
26, // 10: ezshare.ListFilesResponse.ListFileInfo.metadata:type_name -> ezshare.File.Metadata
3, // 11: ezshare.FileService.UploadFile:input_type -> ezshare.UploadFileRequest
5, // 12: ezshare.FileService.GetFile:input_type -> ezshare.GetFileRequest
7, // 13: ezshare.FileService.DeleteFile:input_type -> ezshare.DeleteFileRequest
9, // 14: ezshare.FileService.ListFiles:input_type -> ezshare.ListFilesRequest
12, // 15: ezshare.UserService.Register:input_type -> ezshare.RegisterUserRequest
14, // 16: ezshare.UserService.Login:input_type -> ezshare.LoginUserRequest
16, // 17: ezshare.UserService.List:input_type -> ezshare.ListUsersRequest
18, // 18: ezshare.UserService.Approve:input_type -> ezshare.ApproveUserRequest
19, // 19: ezshare.UserService.ChangePassword:input_type -> ezshare.ChangePasswordRequest
1, // 20: ezshare.CertificateService.ListCertificates:input_type -> ezshare.Empty
21, // 21: ezshare.CertificateService.RevokeCertificate:input_type -> ezshare.RevokeCertificateRequest
23, // 22: ezshare.BinaryService.UploadBinaries:input_type -> ezshare.UploadBinariesRequest
24, // 23: ezshare.BinaryService.GetBinary:input_type -> ezshare.GetBinaryRequest
1, // 24: ezshare.BinaryService.GetLatestVersion:input_type -> ezshare.Empty
4, // 25: ezshare.FileService.UploadFile:output_type -> ezshare.UploadFileResponse
6, // 26: ezshare.FileService.GetFile:output_type -> ezshare.GetFileResponse
8, // 27: ezshare.FileService.DeleteFile:output_type -> ezshare.DeleteFileResponse
10, // 28: ezshare.FileService.ListFiles:output_type -> ezshare.ListFilesResponse
13, // 29: ezshare.UserService.Register:output_type -> ezshare.RegisterUserResponse
15, // 30: ezshare.UserService.Login:output_type -> ezshare.LoginUserResponse
17, // 31: ezshare.UserService.List:output_type -> ezshare.ListUsersResponse
1, // 32: ezshare.UserService.Approve:output_type -> ezshare.Empty
1, // 33: ezshare.UserService.ChangePassword:output_type -> ezshare.Empty
20, // 34: ezshare.CertificateService.ListCertificates:output_type -> ezshare.ListCertificatesResponse
1, // 35: ezshare.CertificateService.RevokeCertificate:output_type -> ezshare.Empty
1, // 36: ezshare.BinaryService.UploadBinaries:output_type -> ezshare.Empty
22, // 37: ezshare.BinaryService.GetBinary:output_type -> ezshare.Binary
25, // 38: ezshare.BinaryService.GetLatestVersion:output_type -> ezshare.LatestVersionResponse
25, // [25:39] is the sub-list for method output_type
11, // [11:25] is the sub-list for method input_type
11, // [11:11] is the sub-list for extension type_name
11, // [11:11] is the sub-list for extension extendee
0, // [0:11] is the sub-list for field type_name
}
func init() { file_protos_ezshare_proto_init() }
@ -1932,7 +2203,7 @@ func file_protos_ezshare_proto_init() {
}
}
file_protos_ezshare_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*File_Metadata); i {
switch v := v.(*Binary); i {
case 0:
return &v.state
case 1:
@ -1944,7 +2215,7 @@ func file_protos_ezshare_proto_init() {
}
}
file_protos_ezshare_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListFilesResponse_ListFileInfo); i {
switch v := v.(*UploadBinariesRequest); i {
case 0:
return &v.state
case 1:
@ -1956,6 +2227,54 @@ func file_protos_ezshare_proto_init() {
}
}
file_protos_ezshare_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetBinaryRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_protos_ezshare_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LatestVersionResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_protos_ezshare_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*File_Metadata); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_protos_ezshare_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListFilesResponse_ListFileInfo); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_protos_ezshare_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListCertificatesResponse_CertificateInfo); i {
case 0:
return &v.state
@ -1974,9 +2293,9 @@ func file_protos_ezshare_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_protos_ezshare_proto_rawDesc,
NumEnums: 1,
NumMessages: 24,
NumMessages: 28,
NumExtensions: 0,
NumServices: 3,
NumServices: 4,
},
GoTypes: file_protos_ezshare_proto_goTypes,
DependencyIndexes: file_protos_ezshare_proto_depIdxs,

View File

@ -559,3 +559,161 @@ var CertificateService_ServiceDesc = grpc.ServiceDesc{
Streams: []grpc.StreamDesc{},
Metadata: "protos/ezshare.proto",
}
// BinaryServiceClient is the client API for BinaryService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type BinaryServiceClient interface {
UploadBinaries(ctx context.Context, in *UploadBinariesRequest, opts ...grpc.CallOption) (*Empty, error)
GetBinary(ctx context.Context, in *GetBinaryRequest, opts ...grpc.CallOption) (*Binary, error)
GetLatestVersion(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LatestVersionResponse, error)
}
type binaryServiceClient struct {
cc grpc.ClientConnInterface
}
func NewBinaryServiceClient(cc grpc.ClientConnInterface) BinaryServiceClient {
return &binaryServiceClient{cc}
}
func (c *binaryServiceClient) UploadBinaries(ctx context.Context, in *UploadBinariesRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/ezshare.BinaryService/UploadBinaries", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *binaryServiceClient) GetBinary(ctx context.Context, in *GetBinaryRequest, opts ...grpc.CallOption) (*Binary, error) {
out := new(Binary)
err := c.cc.Invoke(ctx, "/ezshare.BinaryService/GetBinary", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *binaryServiceClient) GetLatestVersion(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LatestVersionResponse, error) {
out := new(LatestVersionResponse)
err := c.cc.Invoke(ctx, "/ezshare.BinaryService/GetLatestVersion", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// BinaryServiceServer is the server API for BinaryService service.
// All implementations must embed UnimplementedBinaryServiceServer
// for forward compatibility
type BinaryServiceServer interface {
UploadBinaries(context.Context, *UploadBinariesRequest) (*Empty, error)
GetBinary(context.Context, *GetBinaryRequest) (*Binary, error)
GetLatestVersion(context.Context, *Empty) (*LatestVersionResponse, error)
mustEmbedUnimplementedBinaryServiceServer()
}
// UnimplementedBinaryServiceServer must be embedded to have forward compatible implementations.
type UnimplementedBinaryServiceServer struct {
}
func (UnimplementedBinaryServiceServer) UploadBinaries(context.Context, *UploadBinariesRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method UploadBinaries not implemented")
}
func (UnimplementedBinaryServiceServer) GetBinary(context.Context, *GetBinaryRequest) (*Binary, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBinary not implemented")
}
func (UnimplementedBinaryServiceServer) GetLatestVersion(context.Context, *Empty) (*LatestVersionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetLatestVersion not implemented")
}
func (UnimplementedBinaryServiceServer) mustEmbedUnimplementedBinaryServiceServer() {}
// UnsafeBinaryServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to BinaryServiceServer will
// result in compilation errors.
type UnsafeBinaryServiceServer interface {
mustEmbedUnimplementedBinaryServiceServer()
}
func RegisterBinaryServiceServer(s grpc.ServiceRegistrar, srv BinaryServiceServer) {
s.RegisterService(&BinaryService_ServiceDesc, srv)
}
func _BinaryService_UploadBinaries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UploadBinariesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BinaryServiceServer).UploadBinaries(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ezshare.BinaryService/UploadBinaries",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BinaryServiceServer).UploadBinaries(ctx, req.(*UploadBinariesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _BinaryService_GetBinary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetBinaryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BinaryServiceServer).GetBinary(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ezshare.BinaryService/GetBinary",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BinaryServiceServer).GetBinary(ctx, req.(*GetBinaryRequest))
}
return interceptor(ctx, in, info, handler)
}
func _BinaryService_GetLatestVersion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BinaryServiceServer).GetLatestVersion(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ezshare.BinaryService/GetLatestVersion",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BinaryServiceServer).GetLatestVersion(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
// BinaryService_ServiceDesc is the grpc.ServiceDesc for BinaryService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var BinaryService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "ezshare.BinaryService",
HandlerType: (*BinaryServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "UploadBinaries",
Handler: _BinaryService_UploadBinaries_Handler,
},
{
MethodName: "GetBinary",
Handler: _BinaryService_GetBinary_Handler,
},
{
MethodName: "GetLatestVersion",
Handler: _BinaryService_GetLatestVersion_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "protos/ezshare.proto",
}

View File

@ -166,3 +166,34 @@ service CertificateService {
rpc ListCertificates(Empty) returns (ListCertificatesResponse) {}
rpc RevokeCertificate(RevokeCertificateRequest) returns (Empty) {}
}
//////////////////////////
// Binary related stuff //
//////////////////////////
message Binary {
string version = 1;
string arch = 2;
string os = 3;
bytes data = 4;
}
message UploadBinariesRequest {
repeated Binary binaries = 2;
}
message GetBinaryRequest {
string version = 1;
string arch = 2;
string os = 3;
}
message LatestVersionResponse {
string version = 1;
}
service BinaryService {
rpc UploadBinaries(UploadBinariesRequest) returns (Empty) {}
rpc GetBinary(GetBinaryRequest) returns (Binary) {}
rpc GetLatestVersion(Empty) returns (LatestVersionResponse) {}
}

61
server/binaryservice.go Normal file
View File

@ -0,0 +1,61 @@
package server
import (
"context"
"gitea.benny.dog/torjus/ezshare/ezshare"
"gitea.benny.dog/torjus/ezshare/pb"
"gitea.benny.dog/torjus/ezshare/server/interceptors"
"gitea.benny.dog/torjus/ezshare/store"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type BinaryServiceServer struct {
Logger *zap.SugaredLogger
store store.BinaryStore
pb.UnimplementedBinaryServiceServer
}
func NewBinaryServiceServer(store store.BinaryStore) *BinaryServiceServer {
return &BinaryServiceServer{Logger: zap.NewNop().Sugar(), store: store}
}
func (s *BinaryServiceServer) UploadBinaries(ctx context.Context, req *pb.UploadBinariesRequest) (*pb.Empty, error) {
if !interceptors.RoleAtLeast(ctx, pb.User_ADMIN) {
return nil, status.Error(codes.PermissionDenied, "you are not allowed to upload release.")
}
for _, release := range req.Binaries {
if err := s.store.StoreBinary(release); err != nil {
s.Logger.Errorw("Error storing binary.", "version", release.Version, "os", release.Os, "arch", release.Arch)
return nil, status.Errorf(codes.Internal, "error storing release: %s", err)
}
s.Logger.Infow("Stored new binary.", "version", release.Version, "os", release.Os, "arch", release.Arch)
}
return &pb.Empty{}, nil
}
func (s *BinaryServiceServer) GetBinary(ctx context.Context, req *pb.GetBinaryRequest) (*pb.Binary, error) {
version := "latest"
if req.Version != "" {
version = req.Version
}
binary, err := s.store.GetBinary(version, req.Os, req.Arch)
if err != nil {
if err == store.ErrNoSuchItem {
return nil, status.Error(codes.NotFound, "release not found")
}
s.Logger.Errorw("Error getting binary.", "error", err, "version", req.Version, "os", req.Os, "arch", req.Arch)
return nil, status.Errorf(codes.Internal, "release not found: %s", err)
}
s.Logger.Infow("Sent binary.", "version", binary.Version, "os", binary.Os, "arch", binary.Arch)
return binary, nil
}
func (s *BinaryServiceServer) GetLatestVersion(_ context.Context, _ *pb.Empty) (*pb.LatestVersionResponse, error) {
return &pb.LatestVersionResponse{Version: ezshare.Version}, nil
}

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
"gitea.benny.dog/torjus/ezshare/store"
@ -14,6 +15,7 @@ import (
type HTTPServer struct {
Logger *zap.SugaredLogger
store store.FileStore
binaryStore store.BinaryStore
serverGRPCCert []byte
grpcEndpoint string
@ -24,10 +26,11 @@ type MetadataResponse struct {
GRPCEndpoint string `json:"grpc_endpoint"`
}
func NewHTTPSever(store store.FileStore, certBytes []byte, grpcEndpoint string) *HTTPServer {
func NewHTTPSever(store store.FileStore, binaryStore store.BinaryStore, certBytes []byte, grpcEndpoint string) *HTTPServer {
srv := &HTTPServer{
Logger: zap.NewNop().Sugar(),
store: store,
binaryStore: binaryStore,
serverGRPCCert: certBytes,
grpcEndpoint: grpcEndpoint,
}
@ -36,6 +39,8 @@ func NewHTTPSever(store store.FileStore, certBytes []byte, grpcEndpoint string)
r.Get("/server.pem", srv.ServerCertHandler)
r.Get("/metadata", srv.MetadataHandler)
r.Get("/files/{id}", srv.FileHandler)
r.Get("/b", srv.BinaryIndexHandler)
r.Get("/b/{filename}", srv.BinaryHandler)
srv.Handler = r
return srv
@ -48,6 +53,37 @@ func (s *HTTPServer) ServerCertHandler(w http.ResponseWriter, r *http.Request) {
}
s.Logger.Infow("Sent server certificate.", "remote_addr", r.RemoteAddr)
}
func (s *HTTPServer) BinaryIndexHandler(w http.ResponseWriter, r *http.Request) {
binaries, err := s.binaryStore.List()
if err != nil {
WriteErrorResponse(w, http.StatusInternalServerError, "error listing binaries")
return
}
for _, bin := range binaries {
w.Write([]byte(fmt.Sprintf("%s\n", bin)))
}
}
func (s *HTTPServer) BinaryHandler(w http.ResponseWriter, r *http.Request) {
filename := chi.URLParam(r, "filename")
split := strings.Split(filename, "-")
if len(split) != 4 {
WriteErrorResponse(w, http.StatusBadRequest, "invalid filename")
return
}
version := split[1][1:]
operatingSystem := split[2]
arch := split[3]
release, err := s.binaryStore.GetBinary(version, operatingSystem, arch)
if err != nil {
WriteErrorResponse(w, http.StatusNotFound, "release not found")
return
}
if operatingSystem == "windows" {
filename = fmt.Sprintf("%s.exe", filename)
}
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
w.Write(release.Data)
}
func (s *HTTPServer) MetadataHandler(w http.ResponseWriter, r *http.Request) {
md := &MetadataResponse{
GRPCEndpoint: s.grpcEndpoint,

View File

@ -85,5 +85,5 @@ func UserIDFromContext(ctx context.Context) string {
func RoleAtLeast(ctx context.Context, role pb.User_Role) bool {
ctxRole := RoleFromContext(ctx)
return ctxRole > role
return ctxRole >= role
}

View File

@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"crypto/x509"
"fmt"
"strings"
"gitea.benny.dog/torjus/ezshare/pb"
"github.com/google/uuid"
@ -22,6 +23,7 @@ var bktKeyCerts = []byte("certs")
var bktKeyKeys = []byte("keys")
var bktKeyUsers = []byte("users")
var bktKeyRevoked = []byte("revoked")
var bktKeyBinary = []byte("binaries")
func NewBoltStore(path string) (*BoltStore, error) {
s := &BoltStore{}
@ -46,6 +48,9 @@ func NewBoltStore(path string) (*BoltStore, error) {
if _, err := t.CreateBucketIfNotExists(bktKeyRevoked); err != nil {
return err
}
if _, err := t.CreateBucketIfNotExists(bktKeyBinary); err != nil {
return err
}
return nil
})
if err != nil {
@ -298,3 +303,57 @@ func (s *BoltStore) GetUserByUsername(username string) (*pb.User, error) {
}
return nil, ErrNoSuchItem
}
/////////////////
// BinaryStore //
/////////////////
var _ BinaryStore = &BoltStore{}
func binaryKey(version string, os string, arch string) []byte {
return []byte(fmt.Sprintf("%s,%s,%s", version, os, arch))
}
func (s *BoltStore) StoreBinary(release *pb.Binary) error {
return s.db.Update(func(tx *bolt.Tx) error {
bkt := tx.Bucket(bktKeyBinary)
key := binaryKey(release.Version, release.Os, release.Arch)
return bkt.Put(key, release.Data)
})
}
func (s *BoltStore) GetBinary(version string, os string, arch string) (*pb.Binary, error) {
binary := &pb.Binary{}
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(bktKeyBinary)
key := binaryKey(version, os, arch)
binary.Data = bkt.Get(key)
return nil
})
if err != nil {
return nil, err
}
if binary.Data == nil {
return nil, ErrNoSuchItem
}
return binary, nil
}
func (s *BoltStore) List() ([]string, error) {
var releases []string
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(bktKeyBinary)
return bkt.ForEach(func(k, _ []byte) error {
key := strings.Split(string(k), ",")
releases = append(releases, fmt.Sprintf("ezshare-%s-%s-%s", key[0][1:], key[1], key[2]))
return nil
})
})
if err != nil {
return nil, err
}
return releases, nil
}

View File

@ -37,3 +37,12 @@ func TestBoltUserStore(t *testing.T) {
}
doUserStoreTests(s, t)
}
func TestBoltBinaryStore(t *testing.T) {
path := filepath.Join(t.TempDir(), "boltstore.db")
s, err := store.NewBoltStore(path)
defer s.Close()
if err != nil {
t.Fatalf("Error opening store: %s", err)
}
doBinaryStoreTests(s, t)
}

View File

@ -2,7 +2,10 @@ package store
import (
"crypto/ecdsa"
"crypto/sha256"
"crypto/x509"
"fmt"
"strings"
"sync"
"gitea.benny.dog/torjus/ezshare/pb"
@ -10,16 +13,22 @@ import (
)
type MemoryStore struct {
// Filestore
filesLock sync.RWMutex
files map[string]*pb.File
// Certstore
certLock sync.RWMutex
certs map[string][]byte
keyLock sync.RWMutex
keys map[string][]byte
usersLock sync.RWMutex
users map[string]*pb.User
revokedCerts map[string]struct{}
revokedLock sync.RWMutex
// Userstore
usersLock sync.RWMutex
users map[string]*pb.User
// Binarystore
binaryLock sync.RWMutex
binaries map[[32]byte]*pb.Binary
}
func NewMemoryStore() *MemoryStore {
@ -29,6 +38,7 @@ func NewMemoryStore() *MemoryStore {
keys: make(map[string][]byte),
users: make(map[string]*pb.User),
revokedCerts: make(map[string]struct{}),
binaries: make(map[[32]byte]*pb.Binary),
}
}
@ -212,3 +222,48 @@ func (s *MemoryStore) GetUserByUsername(username string) (*pb.User, error) {
}
return nil, ErrNoSuchItem
}
//////////////////
// Binary store //
//////////////////
var _ BinaryStore = &MemoryStore{}
func (s *MemoryStore) StoreBinary(release *pb.Binary) error {
s.binaryLock.Lock()
defer s.binaryLock.Unlock()
hasher := sha256.New()
_, err := hasher.Write(release.Data)
if err != nil {
return fmt.Errorf("unable to hash binary: %w", err)
}
sum := hasher.Sum(nil)
var byteSum [32]byte
copy(byteSum[:], sum[:32])
s.binaries[byteSum] = release
return nil
}
func (s *MemoryStore) GetBinary(version string, os string, arch string) (*pb.Binary, error) {
s.binaryLock.RLock()
defer s.binaryLock.RUnlock()
for _, release := range s.binaries {
if release.Arch == arch && release.Os == os {
if release.Version == version || strings.EqualFold(os, "latest") {
return release, nil
}
}
}
return nil, ErrNoSuchItem
}
func (s *MemoryStore) List() ([]string, error) {
var releases []string
for _, release := range s.binaries {
releases = append(releases, fmt.Sprintf("ezshare-%s-%s-%s", release.Version[1:], release.Os, release.Arch))
}
return releases, nil
}

View File

@ -19,3 +19,7 @@ func TestMemoryUserStore(t *testing.T) {
s := store.NewMemoryStore()
doUserStoreTests(s, t)
}
func TestMemoryBinaryStore(t *testing.T) {
s := store.NewMemoryStore()
doBinaryStoreTests(s, t)
}

View File

@ -33,3 +33,9 @@ type UserStore interface {
GetUserByUsername(username string) (*pb.User, error)
ListUsers() ([]string, error)
}
type BinaryStore interface {
StoreBinary(release *pb.Binary) error
GetBinary(version, os, arch string) (*pb.Binary, error)
List() ([]string, error)
}

View File

@ -209,3 +209,66 @@ func doUserStoreTests(s store.UserStore, t *testing.T) {
}
})
}
func doBinaryStoreTests(s store.BinaryStore, t *testing.T) {
winBinary := &pb.Binary{
Version: "v1.0.0",
Arch: "amd64",
Os: "windows",
Data: []byte("WINDOWS"),
}
linuxBinary := &pb.Binary{
Version: "v1.0.0",
Arch: "arm",
Os: "linux",
Data: []byte("LINUXLOL"),
}
// Store
if err := s.StoreBinary(winBinary); err != nil {
t.Fatalf("Error storing binary: %s", err)
}
if err := s.StoreBinary(linuxBinary); err != nil {
t.Fatalf("Error storing binary: %s", err)
}
// Get
linux, err := s.GetBinary(linuxBinary.Version, linuxBinary.Os, linuxBinary.Arch)
if err != nil {
t.Fatalf("Error geting linux binary: %s", err)
}
windows, err := s.GetBinary(winBinary.Version, winBinary.Os, winBinary.Arch)
if err != nil {
t.Fatalf("Error geting linux binary: %s", err)
}
if string(linux.Data) != string(linuxBinary.Data) {
t.Fatalf("Data is not the same in linux-binary")
}
if string(windows.Data) != string(winBinary.Data) {
t.Fatalf("Data is not the same in linux-binary")
}
// List
list, err := s.List()
if err != nil {
t.Fatalf("List returned error: %s", err)
}
var lFound, wFound bool
for _, item := range list {
if item == "ezshare-1.0.0-linux-arm" {
lFound = true
}
if item == "ezshare-1.0.0-windows-amd64" {
wFound = true
}
}
if !lFound {
t.Fatalf("Linux binary not in list. %+v", list)
}
if !wFound {
t.Fatalf("Windows binary not in list. %+v", list)
}
}