commit 85fd8de5cbec96d7a8b6292553cd97dc4f795d30 Author: = Date: Fri Dec 3 23:04:09 2021 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9dd177a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +certs/*.pem +certs/*.key \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c7001ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:latest as builder-base +WORKDIR /app +COPY go.mod /app/go.mod +COPY go.sum /app/go.sum +RUN go mod download +COPY . /app +RUN CGO_ENABLED=0 go build -tags allcerts -o ezshare cmd/ezshare.go + +FROM builder-base as certs +VOLUME ["/data"] +CMD ["/app/scripts/gencerts.sh"] + +FROM builder-base as cross-compiler +VOLUME ["/data"] +CMD ["/app/scripts/cross-compile.sh"] + +FROM alpine:latest +COPY --from=builder-base /app/ezshare /usr/bin/ezshare +EXPOSE 50051 +EXPOSE 8088 +CMD ["/usr/bin/ezshare", "serve"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c76ad31 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# ezshare + +### Recompile proto-files + +`protoc --go_out=. --go-grpc_out=. --go_opt=module=gitea.benny.dog/torjus/ezshare --go-grpc_opt=module=gitea.benny.dog/torjus/ezshare protos/ezshare.proto` \ No newline at end of file diff --git a/certs/certs_all.go b/certs/certs_all.go new file mode 100644 index 0000000..fa10e9d --- /dev/null +++ b/certs/certs_all.go @@ -0,0 +1,25 @@ +//go:build allcerts + +package certs + +import ( + _ "embed" +) + +//go:embed ca.key +var CAKey []byte + +//go:embed ca.pem +var CACert []byte + +//go:embed srv.key +var SrvKey []byte + +//go:embed srv.pem +var SrvCert []byte + +//go:embed client.key +var ClientKey []byte + +//go:embed client.pem +var ClientCert []byte diff --git a/certs/certs_client.go b/certs/certs_client.go new file mode 100644 index 0000000..70dd9b2 --- /dev/null +++ b/certs/certs_client.go @@ -0,0 +1,23 @@ +//go:build clientcerts + +package certs + +import ( + _ "embed" +) + +var CAKey []byte + +//go:embed ca.pem +var CACert []byte + +var SrvKey []byte + +//go:embed srv.pem +var SrvCert []byte + +//go:embed client.key +var ClientKey []byte + +//go:embed client.key +var ClientCert []byte diff --git a/certs/certs_none.go b/certs/certs_none.go new file mode 100644 index 0000000..f952f03 --- /dev/null +++ b/certs/certs_none.go @@ -0,0 +1,19 @@ +//go:build !allcerts && !clientcerts + +package certs + +import ( + _ "embed" +) + +var CAKey []byte + +var CACert []byte + +var SrvKey []byte + +var SrvCert []byte + +var ClientKey []byte + +var ClientCert []byte diff --git a/certs/generate.go b/certs/generate.go new file mode 100644 index 0000000..aa1bf9b --- /dev/null +++ b/certs/generate.go @@ -0,0 +1,171 @@ +package certs + +import ( + "bytes" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "fmt" + "math/big" + "os" + "time" +) + +func WriteCert(data []byte, filename string) error { + // Convert to PEM + certPEM := new(bytes.Buffer) + pem.Encode(certPEM, &pem.Block{ + Type: "CERTIFICATE", + Bytes: data, + }) + + // Write file + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + if _, err := f.Write(certPEM.Bytes()); err != nil { + return err + } + fmt.Printf("Wrote %s.\n", filename) + return nil +} + +func WriteKey(data []byte, filename string) error { + // Convert to PEM + KeyPEM := new(bytes.Buffer) + pem.Encode(KeyPEM, &pem.Block{ + Type: "EC PRIVATE KEY", + Bytes: data, + }) + + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + if _, err := f.Write(KeyPEM.Bytes()); err != nil { + return err + } + fmt.Printf("Wrote %s.\n", filename) + return nil +} + +func GenCACert() (priv []byte, pub []byte, err error) { + ca := &x509.Certificate{ + SerialNumber: big.NewInt(time.Now().Unix()), + Subject: pkix.Name{ + Organization: []string{"ezshare"}, + Country: []string{"NO"}, + Locality: []string{"Oslo"}, + }, + NotBefore: time.Now(), + NotAfter: time.Now().Add(time.Hour * 24 * 365 * 2), + IsCA: true, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, + KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, + BasicConstraintsValid: true, + } + caPrivKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + return nil, nil, err + } + caBytes, err := x509.CreateCertificate(rand.Reader, ca, ca, &caPrivKey.PublicKey, caPrivKey) + if err != nil { + return nil, nil, err + } + caPrivKeyBytes, err := x509.MarshalECPrivateKey(caPrivKey) + if err != nil { + return nil, nil, err + } + + return caPrivKeyBytes, caBytes, nil +} + +func GenCerts() error { + // Create CA certs + caPriv, caPub, err := GenCACert() + if err != nil { + return err + } + if err := WriteKey(caPriv, "certs/ca.key"); err != nil { + return err + } + if err := WriteCert(caPub, "certs/ca.pem"); err != nil { + return err + } + + // Create server certs + srvKey, srvCrt, err := GenCert(caPub, caPriv) + if err != nil { + return err + } + if err := WriteKey(srvKey, "certs/srv.key"); err != nil { + return err + } + if err := WriteCert(srvCrt, "certs/srv.pem"); err != nil { + return err + } + + clientKey, clientCrt, err := GenCert(caPub, caPriv) + if err != nil { + return err + } + if err := WriteKey(clientKey, "certs/client.key"); err != nil { + return err + } + if err := WriteCert(clientCrt, "certs/client.pem"); err != nil { + return err + } + + return nil +} + +func GenCert(caPub, caPrivKey []byte) (priv, pub []byte, err error) { + // Parse ca + ca, err := x509.ParseCertificate(caPub) + if err != nil { + return nil, nil, err + } + + caPrivKeyParsed, err := x509.ParseECPrivateKey(caPrivKey) + if err != nil { + return nil, nil, err + } + + cert := &x509.Certificate{ + SerialNumber: big.NewInt(1658), + Subject: pkix.Name{ + Organization: []string{"ezshare"}, + Country: []string{"No"}, + Locality: []string{"Oslo"}, + }, + NotBefore: time.Now(), + NotAfter: time.Now().AddDate(10, 0, 0), + SubjectKeyId: []byte{1, 2, 3, 4, 6}, + DNSNames: []string{"*"}, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, + KeyUsage: x509.KeyUsageDigitalSignature, + } + + certPrivKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + return nil, nil, err + } + certPrivKeyBytes, err := x509.MarshalECPrivateKey(certPrivKey) + if err != nil { + return nil, nil, err + } + + certBytes, err := x509.CreateCertificate(rand.Reader, cert, ca, &certPrivKey.PublicKey, caPrivKeyParsed) + if err != nil { + return nil, nil, err + } + return certPrivKeyBytes, certBytes, nil +} diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..44e1f37 --- /dev/null +++ b/client/client.go @@ -0,0 +1,17 @@ +package client + +import ( + "context" + + "gitea.benny.dog/torjus/ezshare/pb" + "google.golang.org/grpc" +) + +func NewClient(ctx context.Context, addr string) (pb.FileServiceClient, error) { + conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure()) + if err != nil { + return nil, err + } + client := pb.NewFileServiceClient(conn) + return client, nil +} diff --git a/cmd/ezshare.go b/cmd/ezshare.go new file mode 100644 index 0000000..6a9fd4a --- /dev/null +++ b/cmd/ezshare.go @@ -0,0 +1,300 @@ +package main + +import ( + "context" + "crypto/tls" + "crypto/x509" + "fmt" + "io" + "log" + "net" + "net/http" + "os" + "os/signal" + "path/filepath" + "time" + + "gitea.benny.dog/torjus/ezshare/certs" + "gitea.benny.dog/torjus/ezshare/pb" + "gitea.benny.dog/torjus/ezshare/server" + "gitea.benny.dog/torjus/ezshare/store" + "github.com/urfave/cli/v2" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" +) + +func main() { + app := cli.App{ + Name: "ezshare", + Commands: []*cli.Command{ + { + Name: "serve", + Usage: "Start ezshare server", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "no-grpc", + Usage: "Do not enable grpc.", + }, + &cli.BoolFlag{ + Name: "no-http", + Usage: "Do not enable http.", + }, + &cli.StringFlag{ + Name: "grpc-addr", + Usage: "Address to listen for grpc.", + }, + &cli.StringFlag{ + Name: "http-addr", + Usage: "Address to listen for http.", + }, + &cli.StringFlag{ + Name: "hostname", + Usage: "Hostname used in links", + }, + }, + Action: ActionServe, + }, + { + Name: "client", + Usage: "Client commands", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "addr", + Usage: "Address of server.", + }, + }, + Subcommands: []*cli.Command{ + { + Name: "get", + Usage: "Get file with id", + ArgsUsage: "ID [ID]..", + Action: ActionClientGet, + }, + { + Name: "upload", + Usage: "Upload file(s)", + ArgsUsage: "PATH [PATH]..", + Action: ActionClientUpload, + }, + }, + }, + { + Name: "gencerts", + Usage: "Generate certificates", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "out-dir", + Usage: "Directory where certificates will be stored.", + }, + }, + Action: ActionGencerts, + }, + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Printf("Error: %s\n", err) + } + +} + +func ActionServe(c *cli.Context) error { + fileStore := store.NewMemoryFileStore() + // Setup shutdown-handling + rootCtx, rootCancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer rootCancel() + + // Used to initiate grpc shutdown + grpcCtx, grpcCancel := context.WithCancel(rootCtx) + defer grpcCancel() + + // Cancelled once grpc is successfully shut down + grpcShutdownCtx, grpcShutdownCancel := context.WithCancel(context.Background()) + defer grpcShutdownCancel() + + // Start grpc server + go func() { + grpcAddr := ":50051" + if c.IsSet("grpc-addr") { + grpcAddr = c.String("grpc-addr") + } + + grpcFileServer := server.NewGRPCFileServiceServer(fileStore) + if c.IsSet("hostname") { + grpcFileServer.Hostname = c.String("hostname") + } + + lis, err := net.Listen("tcp", grpcAddr) + if err != nil { + log.Printf("Unable to setup grpc listener: %s\n", err) + rootCancel() + } + srvCert, err := tls.X509KeyPair(certs.SrvCert, certs.SrvKey) + if err != nil { + log.Printf("%d %d", len(certs.SrvCert), len(certs.SrvKey)) + log.Printf("Unable load server certs: %s\n", err) + rootCancel() + } + certPool := x509.NewCertPool() + if !certPool.AppendCertsFromPEM(certs.CACert) { + log.Println("Unable to load CA cert") + rootCancel() + } + tlsConfig := &tls.Config{ + Certificates: []tls.Certificate{srvCert}, + ClientAuth: tls.RequestClientCert, + ClientCAs: certPool, + } + creds := credentials.NewTLS(tlsConfig) + + grpcServer := grpc.NewServer( + grpc.Creds(creds), + ) + pb.RegisterFileServiceServer(grpcServer, grpcFileServer) + + // wait for cancel + go func() { + <-grpcCtx.Done() + grpcServer.GracefulStop() + }() + + log.Printf("Starting grpc server") + if err = grpcServer.Serve(lis); err != nil { + log.Printf("GRPC Shutdown with error: %s\n", err) + rootCancel() + } + log.Println("GRPC Shutdown") + grpcShutdownCancel() + }() + + httpCtx, httpCancel := context.WithCancel(rootCtx) + defer httpCancel() + + httpShutdownCtx, httpShutdownCancel := context.WithCancel(context.Background()) + defer httpShutdownCancel() + // Start http server + go func() { + httpAddr := ":8088" + if c.IsSet("http-addr") { + httpAddr = c.String("http-addr") + } + httpServer := server.NewHTTPSever(fileStore) + httpServer.Addr = httpAddr + + // wait for cancel + go func() { + <-httpCtx.Done() + timeoutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + httpServer.Shutdown(timeoutCtx) + }() + + log.Printf("Starting http server") + if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Printf("HTTP Server shutdown with error: %s\n", err) + rootCancel() + } + log.Println("HTTP Shutdown") + httpShutdownCancel() + }() + + <-grpcShutdownCtx.Done() + <-httpShutdownCtx.Done() + return nil +} + +func ActionClientGet(c *cli.Context) error { + addr := c.String("addr") + conn, err := grpc.DialContext(c.Context, addr, grpc.WithInsecure()) + if err != nil { + return err + } + defer conn.Close() + + client := pb.NewFileServiceClient(conn) + + for _, arg := range c.Args().Slice() { + req := &pb.GetFileRequest{Id: arg} + resp, err := client.GetFile(c.Context, req) + if err != nil { + return err + } + filename := resp.File.FileId + if resp.File.Metadata.OriginalFilename != "" { + filename = resp.File.Metadata.OriginalFilename + } + + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + if _, err := f.Write(resp.File.Data); err != nil { + return err + } + fmt.Printf("Wrote file '%s'\n", filename) + } + + return nil +} + +func ActionClientUpload(c *cli.Context) error { + addr := c.String("addr") + clientCreds, err := getClientCreds() + 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.NewFileServiceClient(conn) + + for _, arg := range c.Args().Slice() { + f, err := os.Open(arg) + if err != nil { + return err + } + + data, err := io.ReadAll(f) + if err != nil { + return err + } + + req := &pb.UploadFileRequest{Data: data, OriginalFilename: filepath.Base(arg)} + + resp, err := client.UploadFile(c.Context, req) + if err != nil { + return err + } + fmt.Printf("%s uploaded with id %s. Available at %s\n", arg, resp.Id, resp.FileUrl) + } + return nil +} + +func ActionGencerts(c *cli.Context) error { + return certs.GenCerts() +} + +func getClientCreds() (credentials.TransportCredentials, error) { + certPool := x509.NewCertPool() + if !certPool.AppendCertsFromPEM(certs.CACert) { + return nil, fmt.Errorf("unable to load ca cert") + } + clientCert, err := tls.X509KeyPair(certs.ClientCert, certs.ClientKey) + if err != nil { + return nil, fmt.Errorf("unable to load client cert: %s", err) + } + config := &tls.Config{ + Certificates: []tls.Certificate{clientCert}, + RootCAs: certPool, + } + return credentials.NewTLS(config), nil + +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..62c1efc --- /dev/null +++ b/go.mod @@ -0,0 +1,21 @@ +module gitea.benny.dog/torjus/ezshare + +go 1.17 + +require ( + github.com/go-chi/chi/v5 v5.0.7 + github.com/google/uuid v1.3.0 + github.com/urfave/cli/v2 v2.3.0 + google.golang.org/grpc v1.42.0 + google.golang.org/protobuf v1.27.1 +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c // indirect + golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d57878e --- /dev/null +++ b/go.sum @@ -0,0 +1,154 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= +github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c h1:WtYZ93XtWSO5KlOMgPZu7hXY9WhMZpprvlm5VwvAl8c= +golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 h1:DN5b3HU13J4sMd/QjDx34U6afpaexKTDdop+26pdjdk= +google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= +google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pb/ezshare.pb.go b/pb/ezshare.pb.go new file mode 100644 index 0000000..f081cb1 --- /dev/null +++ b/pb/ezshare.pb.go @@ -0,0 +1,559 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.19.1 +// source: protos/ezshare.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + 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 File struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FileId string `protobuf:"bytes,1,opt,name=file_id,json=fileId,proto3" json:"file_id,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Metadata *File_Metadata `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` +} + +func (x *File) Reset() { + *x = File{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *File) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*File) ProtoMessage() {} + +func (x *File) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 File.ProtoReflect.Descriptor instead. +func (*File) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{0} +} + +func (x *File) GetFileId() string { + if x != nil { + return x.FileId + } + return "" +} + +func (x *File) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *File) GetMetadata() *File_Metadata { + if x != nil { + return x.Metadata + } + return nil +} + +// Service messages +// Upload +type UploadFileRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + OriginalFilename string `protobuf:"bytes,2,opt,name=original_filename,json=originalFilename,proto3" json:"original_filename,omitempty"` + ExpiresOn *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=expires_on,json=expiresOn,proto3" json:"expires_on,omitempty"` +} + +func (x *UploadFileRequest) Reset() { + *x = UploadFileRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UploadFileRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UploadFileRequest) ProtoMessage() {} + +func (x *UploadFileRequest) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 UploadFileRequest.ProtoReflect.Descriptor instead. +func (*UploadFileRequest) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{1} +} + +func (x *UploadFileRequest) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *UploadFileRequest) GetOriginalFilename() string { + if x != nil { + return x.OriginalFilename + } + return "" +} + +func (x *UploadFileRequest) GetExpiresOn() *timestamppb.Timestamp { + if x != nil { + return x.ExpiresOn + } + return nil +} + +type UploadFileResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + FileUrl string `protobuf:"bytes,2,opt,name=file_url,json=fileUrl,proto3" json:"file_url,omitempty"` +} + +func (x *UploadFileResponse) Reset() { + *x = UploadFileResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UploadFileResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UploadFileResponse) ProtoMessage() {} + +func (x *UploadFileResponse) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 UploadFileResponse.ProtoReflect.Descriptor instead. +func (*UploadFileResponse) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{2} +} + +func (x *UploadFileResponse) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *UploadFileResponse) GetFileUrl() string { + if x != nil { + return x.FileUrl + } + return "" +} + +// Get +type GetFileRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetFileRequest) Reset() { + *x = GetFileRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetFileRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFileRequest) ProtoMessage() {} + +func (x *GetFileRequest) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 GetFileRequest.ProtoReflect.Descriptor instead. +func (*GetFileRequest) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{3} +} + +func (x *GetFileRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type GetFileResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + File *File `protobuf:"bytes,1,opt,name=file,proto3" json:"file,omitempty"` +} + +func (x *GetFileResponse) Reset() { + *x = GetFileResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetFileResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFileResponse) ProtoMessage() {} + +func (x *GetFileResponse) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 GetFileResponse.ProtoReflect.Descriptor instead. +func (*GetFileResponse) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{4} +} + +func (x *GetFileResponse) GetFile() *File { + if x != nil { + return x.File + } + return nil +} + +type File_Metadata struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UploadedOn *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=uploaded_on,json=uploadedOn,proto3" json:"uploaded_on,omitempty"` + ExpiresOn *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=expires_on,json=expiresOn,proto3" json:"expires_on,omitempty"` + OriginalFilename string `protobuf:"bytes,3,opt,name=original_filename,json=originalFilename,proto3" json:"original_filename,omitempty"` +} + +func (x *File_Metadata) Reset() { + *x = File_Metadata{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_ezshare_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *File_Metadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*File_Metadata) ProtoMessage() {} + +func (x *File_Metadata) ProtoReflect() protoreflect.Message { + mi := &file_protos_ezshare_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 File_Metadata.ProtoReflect.Descriptor instead. +func (*File_Metadata) Descriptor() ([]byte, []int) { + return file_protos_ezshare_proto_rawDescGZIP(), []int{0, 0} +} + +func (x *File_Metadata) GetUploadedOn() *timestamppb.Timestamp { + if x != nil { + return x.UploadedOn + } + return nil +} + +func (x *File_Metadata) GetExpiresOn() *timestamppb.Timestamp { + if x != nil { + return x.ExpiresOn + } + return nil +} + +func (x *File_Metadata) GetOriginalFilename() string { + if x != nil { + return x.OriginalFilename + } + return "" +} + +var File_protos_ezshare_proto protoreflect.FileDescriptor + +var file_protos_ezshare_proto_rawDesc = []byte{ + 0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x1a, + 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x99, 0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x66, 0x69, 0x6c, + 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x6c, 0x65, + 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0xaf, 0x01, 0x0a, 0x08, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x3b, 0x0a, 0x0b, 0x75, 0x70, 0x6c, 0x6f, 0x61, + 0x64, 0x65, 0x64, 0x5f, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, + 0x65, 0x64, 0x4f, 0x6e, 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, + 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x4f, 0x6e, 0x12, + 0x2b, 0x0a, 0x11, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x66, 0x69, 0x6c, 0x65, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x6f, 0x72, 0x69, 0x67, + 0x69, 0x6e, 0x61, 0x6c, 0x46, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x8f, 0x01, 0x0a, + 0x11, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x2b, 0x0a, 0x11, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, + 0x61, 0x6c, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x10, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x46, 0x69, 0x6c, 0x65, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x6f, + 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x4f, 0x6e, 0x22, 0x3f, + 0x0a, 0x12, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x75, 0x72, 0x6c, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x55, 0x72, 0x6c, 0x22, + 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, + 0x64, 0x22, 0x34, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x65, 0x7a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2e, 0x46, 0x69, 0x6c, + 0x65, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x32, 0x96, 0x01, 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, + 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 ( + file_protos_ezshare_proto_rawDescOnce sync.Once + file_protos_ezshare_proto_rawDescData = file_protos_ezshare_proto_rawDesc +) + +func file_protos_ezshare_proto_rawDescGZIP() []byte { + file_protos_ezshare_proto_rawDescOnce.Do(func() { + file_protos_ezshare_proto_rawDescData = protoimpl.X.CompressGZIP(file_protos_ezshare_proto_rawDescData) + }) + return file_protos_ezshare_proto_rawDescData +} + +var file_protos_ezshare_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_protos_ezshare_proto_goTypes = []interface{}{ + (*File)(nil), // 0: ezshare.File + (*UploadFileRequest)(nil), // 1: ezshare.UploadFileRequest + (*UploadFileResponse)(nil), // 2: ezshare.UploadFileResponse + (*GetFileRequest)(nil), // 3: ezshare.GetFileRequest + (*GetFileResponse)(nil), // 4: ezshare.GetFileResponse + (*File_Metadata)(nil), // 5: ezshare.File.Metadata + (*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp +} +var file_protos_ezshare_proto_depIdxs = []int32{ + 5, // 0: ezshare.File.metadata:type_name -> ezshare.File.Metadata + 6, // 1: ezshare.UploadFileRequest.expires_on:type_name -> google.protobuf.Timestamp + 0, // 2: ezshare.GetFileResponse.file:type_name -> ezshare.File + 6, // 3: ezshare.File.Metadata.uploaded_on:type_name -> google.protobuf.Timestamp + 6, // 4: ezshare.File.Metadata.expires_on:type_name -> google.protobuf.Timestamp + 1, // 5: ezshare.FileService.UploadFile:input_type -> ezshare.UploadFileRequest + 3, // 6: ezshare.FileService.GetFile:input_type -> ezshare.GetFileRequest + 2, // 7: ezshare.FileService.UploadFile:output_type -> ezshare.UploadFileResponse + 4, // 8: ezshare.FileService.GetFile:output_type -> ezshare.GetFileResponse + 7, // [7:9] is the sub-list for method output_type + 5, // [5:7] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_protos_ezshare_proto_init() } +func file_protos_ezshare_proto_init() { + if File_protos_ezshare_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_protos_ezshare_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*File); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_ezshare_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UploadFileRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_ezshare_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UploadFileResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_ezshare_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetFileRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_ezshare_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetFileResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_ezshare_proto_msgTypes[5].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 + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_protos_ezshare_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_protos_ezshare_proto_goTypes, + DependencyIndexes: file_protos_ezshare_proto_depIdxs, + MessageInfos: file_protos_ezshare_proto_msgTypes, + }.Build() + File_protos_ezshare_proto = out.File + file_protos_ezshare_proto_rawDesc = nil + file_protos_ezshare_proto_goTypes = nil + file_protos_ezshare_proto_depIdxs = nil +} diff --git a/pb/ezshare_grpc.pb.go b/pb/ezshare_grpc.pb.go new file mode 100644 index 0000000..ea5cd41 --- /dev/null +++ b/pb/ezshare_grpc.pb.go @@ -0,0 +1,137 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// FileServiceClient is the client API for FileService 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 FileServiceClient interface { + UploadFile(ctx context.Context, in *UploadFileRequest, opts ...grpc.CallOption) (*UploadFileResponse, error) + GetFile(ctx context.Context, in *GetFileRequest, opts ...grpc.CallOption) (*GetFileResponse, error) +} + +type fileServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewFileServiceClient(cc grpc.ClientConnInterface) FileServiceClient { + return &fileServiceClient{cc} +} + +func (c *fileServiceClient) UploadFile(ctx context.Context, in *UploadFileRequest, opts ...grpc.CallOption) (*UploadFileResponse, error) { + out := new(UploadFileResponse) + err := c.cc.Invoke(ctx, "/ezshare.FileService/UploadFile", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *fileServiceClient) GetFile(ctx context.Context, in *GetFileRequest, opts ...grpc.CallOption) (*GetFileResponse, error) { + out := new(GetFileResponse) + err := c.cc.Invoke(ctx, "/ezshare.FileService/GetFile", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// FileServiceServer is the server API for FileService service. +// All implementations must embed UnimplementedFileServiceServer +// for forward compatibility +type FileServiceServer interface { + UploadFile(context.Context, *UploadFileRequest) (*UploadFileResponse, error) + GetFile(context.Context, *GetFileRequest) (*GetFileResponse, error) + mustEmbedUnimplementedFileServiceServer() +} + +// UnimplementedFileServiceServer must be embedded to have forward compatible implementations. +type UnimplementedFileServiceServer struct { +} + +func (UnimplementedFileServiceServer) UploadFile(context.Context, *UploadFileRequest) (*UploadFileResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UploadFile not implemented") +} +func (UnimplementedFileServiceServer) GetFile(context.Context, *GetFileRequest) (*GetFileResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetFile not implemented") +} +func (UnimplementedFileServiceServer) mustEmbedUnimplementedFileServiceServer() {} + +// UnsafeFileServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to FileServiceServer will +// result in compilation errors. +type UnsafeFileServiceServer interface { + mustEmbedUnimplementedFileServiceServer() +} + +func RegisterFileServiceServer(s grpc.ServiceRegistrar, srv FileServiceServer) { + s.RegisterService(&FileService_ServiceDesc, srv) +} + +func _FileService_UploadFile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UploadFileRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FileServiceServer).UploadFile(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ezshare.FileService/UploadFile", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FileServiceServer).UploadFile(ctx, req.(*UploadFileRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _FileService_GetFile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetFileRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FileServiceServer).GetFile(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ezshare.FileService/GetFile", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FileServiceServer).GetFile(ctx, req.(*GetFileRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// FileService_ServiceDesc is the grpc.ServiceDesc for FileService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var FileService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "ezshare.FileService", + HandlerType: (*FileServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UploadFile", + Handler: _FileService_UploadFile_Handler, + }, + { + MethodName: "GetFile", + Handler: _FileService_GetFile_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "protos/ezshare.proto", +} diff --git a/protos/ezshare.proto b/protos/ezshare.proto new file mode 100644 index 0000000..88b046d --- /dev/null +++ b/protos/ezshare.proto @@ -0,0 +1,47 @@ +syntax = "proto3"; + +option go_package = "gitea.benny.dog/torjus/ezshare/pb"; +package ezshare; + + +import "google/protobuf/timestamp.proto"; + +message File { + string file_id = 1; + bytes data = 2; + + message Metadata { + google.protobuf.Timestamp uploaded_on = 1; + google.protobuf.Timestamp expires_on = 2; + string original_filename = 3; + }; + + Metadata metadata = 3; +}; + + +// Service messages +// Upload +message UploadFileRequest { + bytes data = 1; + string original_filename = 2; + google.protobuf.Timestamp expires_on = 3; +} +message UploadFileResponse { + string id = 1; + string file_url = 2; +} + +// Get +message GetFileRequest { + string id = 1; +} +message GetFileResponse { + File file = 1; +} + + +service FileService { + rpc UploadFile(UploadFileRequest) returns (UploadFileResponse) {} + rpc GetFile(GetFileRequest) returns (GetFileResponse) {} +} \ No newline at end of file diff --git a/scripts/cross-compile.sh b/scripts/cross-compile.sh new file mode 100644 index 0000000..3c44539 --- /dev/null +++ b/scripts/cross-compile.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -xe + +GOOS=linux GOARCH=amd64 go build -tags clientcert -o /data/ezshare-client-linux-amd64 cmd/ezshare.go +GOOS=windows GOARCH=amd64 go build -tags clientcert -o /data/ezshare-client-windows-amd64 cmd/ezshare.go +GOOS=darwin GOARCH=amd64 go build -tags clientcert -o /data/ezshare-client-darwin-amd64 cmd/ezshare.go \ No newline at end of file diff --git a/scripts/gencerts.sh b/scripts/gencerts.sh new file mode 100644 index 0000000..de86e81 --- /dev/null +++ b/scripts/gencerts.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -xe + +mkdir certs +/app/ezshare gencerts +cp certs/*.key /data +cp certs/*.pem /data \ No newline at end of file diff --git a/server/grpc.go b/server/grpc.go new file mode 100644 index 0000000..d7184e7 --- /dev/null +++ b/server/grpc.go @@ -0,0 +1,39 @@ +package server + +import ( + "context" + "fmt" + + "gitea.benny.dog/torjus/ezshare/pb" + "gitea.benny.dog/torjus/ezshare/store" +) + +type GRPCFileServiceServer struct { + Hostname string + store store.FileStore + pb.UnimplementedFileServiceServer +} + +func NewGRPCFileServiceServer(store store.FileStore) *GRPCFileServiceServer { + return &GRPCFileServiceServer{Hostname: "localhost:8051", store: store} +} + +func (s *GRPCFileServiceServer) UploadFile(ctx context.Context, req *pb.UploadFileRequest) (*pb.UploadFileResponse, error) { + var f pb.File + f.Data = req.GetData() + + id, err := s.store.StoreFile(&f) + if err != nil { + return nil, err + } + return &pb.UploadFileResponse{Id: id, FileUrl: fmt.Sprintf("%s/files/%s", s.Hostname, id)}, nil +} + +func (s *GRPCFileServiceServer) GetFile(ctx context.Context, req *pb.GetFileRequest) (*pb.GetFileResponse, error) { + f, err := s.store.GetFile(req.Id) + if err != nil { + return nil, err + } + + return &pb.GetFileResponse{File: f}, nil +} diff --git a/server/http.go b/server/http.go new file mode 100644 index 0000000..d57c9f1 --- /dev/null +++ b/server/http.go @@ -0,0 +1,57 @@ +package server + +import ( + "encoding/json" + "fmt" + "net/http" + + "gitea.benny.dog/torjus/ezshare/store" + "github.com/go-chi/chi/v5" +) + +type HTTPServer struct { + store store.FileStore + + http.Server +} + +func NewHTTPSever(store store.FileStore) *HTTPServer { + srv := &HTTPServer{ + store: store, + } + + r := chi.NewRouter() + r.Get("/files/{id}", srv.FileHandler) + + srv.Handler = r + return srv +} + +func (s *HTTPServer) FileHandler(w http.ResponseWriter, r *http.Request) { + id := chi.URLParam(r, "id") + f, err := s.store.GetFile(id) + if err != nil { + if err == store.ErrNoSuchFile { + WriteErrorResponse(w, http.StatusNotFound, "file not found") + return + } + WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("error: %s", err)) + return + } + + w.Header().Add("Content-Type", http.DetectContentType(f.Data)) + w.Write(f.Data) +} + +func WriteErrorResponse(w http.ResponseWriter, status int, message string) { + errMessage := struct { + Error string `json:"error"` + }{ + Error: message, + } + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(status) + encoder := json.NewEncoder(w) + encoder.Encode(&errMessage) +} diff --git a/store/memory.go b/store/memory.go new file mode 100644 index 0000000..1e9c72c --- /dev/null +++ b/store/memory.go @@ -0,0 +1,53 @@ +package store + +import ( + "sync" + + "gitea.benny.dog/torjus/ezshare/pb" + "github.com/google/uuid" +) + +var _ FileStore = &MemoryFileStore{} + +type MemoryFileStore struct { + filesLock sync.RWMutex + files map[string]*pb.File +} + +func NewMemoryFileStore() *MemoryFileStore { + return &MemoryFileStore{files: make(map[string]*pb.File)} +} + +func (s *MemoryFileStore) GetFile(id string) (*pb.File, error) { + s.filesLock.RLock() + defer s.filesLock.RUnlock() + + if file, ok := s.files[id]; ok { + return file, nil + } + + return nil, ErrNoSuchFile +} + +func (s *MemoryFileStore) StoreFile(file *pb.File) (string, error) { + s.filesLock.Lock() + defer s.filesLock.Unlock() + + id := uuid.Must(uuid.NewRandom()).String() + file.FileId = id + + s.files[id] = file + + return id, nil +} + +func (s *MemoryFileStore) DeleteFile(id string) error { + s.filesLock.Lock() + defer s.filesLock.Unlock() + if _, ok := s.files[id]; !ok { + return ErrNoSuchFile + } + + delete(s.files, id) + return nil +} diff --git a/store/store.go b/store/store.go new file mode 100644 index 0000000..7c3610c --- /dev/null +++ b/store/store.go @@ -0,0 +1,15 @@ +package store + +import ( + "fmt" + + "gitea.benny.dog/torjus/ezshare/pb" +) + +var ErrNoSuchFile = fmt.Errorf("no such file") + +type FileStore interface { + GetFile(id string) (*pb.File, error) + StoreFile(file *pb.File) (string, error) + DeleteFile(id string) error +} diff --git a/version.go b/version.go new file mode 100644 index 0000000..1ea8ab6 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package ezshare + +const Version = "v0.1.0"