Skip to content

Commit

Permalink
Merge pull request #122 from FleekHQ/feature/ch17900/update-create-sh…
Browse files Browse the repository at this point in the history
…are-logic

Partial release of share files implementation
  • Loading branch information
jsonsivar authored Aug 31, 2020
2 parents 7159d9b + b7968b2 commit 3dba584
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 2 deletions.
35 changes: 35 additions & 0 deletions core/space/domain/domain.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package domain

import (
"time"
)

type AppConfig struct {
Port int
AppPath string
Expand Down Expand Up @@ -72,6 +76,37 @@ type FileSharingInfo struct {
SpaceDownloadLink string
}

type InvitationStatus int

const (
Pending InvitationStatus = 0
Accepted
Rejected
)

type MessageType int

const (
InvitationMessage MessageType = 0
UsageAlertMessage
)

type MessageBody struct {
Type MessageType `json:"type"`
Body interface{} `json:"body`
}

type Invitation struct {
CustomMessage string `json:"customMessage"`
InvitationID string `json:"invitationID"`
InviteePublicKey string `json:"inviteePublicKey"`
InviterPublicKey string `json:"inviterPublicKey"`
Status InvitationStatus `json:"status"`
Paths []string `json:"Paths"`
ReadAt time.Time `json:"readAt"`
CreatedAt time.Time `json:"createdAt"`
}

type APISessionTokens struct {
HubToken string
ServicesToken string
Expand Down
31 changes: 31 additions & 0 deletions core/space/services/services_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package services
import (
"archive/zip"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
"os"
"path/filepath"

"github.com/FleekHQ/space-daemon/log"
crypto "github.com/libp2p/go-libp2p-crypto"

"github.com/textileio/dcrypto"

Expand Down Expand Up @@ -222,3 +224,32 @@ func (s *Space) OpenSharedFile(ctx context.Context, hash, password, filename str
Location: decryptedFile.Name(),
}, nil
}

func (s *Space) ShareFilesViaPublicKey(ctx context.Context, bucketName string, paths []string, pubkeys []crypto.PubKey) error {
err := s.tc.ShareFilesViaPublicKey(ctx, bucketName, paths, pubkeys)
if err != nil {
return err
}
for _, pk := range pubkeys {
d := &domain.Invitation{
Paths: paths,
// Key: TODO - get from keys thread for each file
}

b := &domain.MessageBody{
Type: domain.InvitationMessage,
Body: d,
}

j, err := json.Marshal(b)
if err != nil {
return err
}

_, err = s.tc.SendMessage(ctx, pk, j)
if err != nil {
return err
}
}
return nil
}
2 changes: 2 additions & 0 deletions core/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/FleekHQ/space-daemon/core/ipfs"
"github.com/FleekHQ/space-daemon/core/textile/hub"
"github.com/FleekHQ/space-daemon/core/vault"
crypto "github.com/libp2p/go-libp2p-crypto"

"github.com/FleekHQ/space-daemon/config"
"github.com/FleekHQ/space-daemon/core/env"
Expand Down Expand Up @@ -47,6 +48,7 @@ type Service interface {
CreateLocalKeysBackup(ctx context.Context, pathToKeyBackup string) error
RecoverKeysByLocalBackup(ctx context.Context, pathToKeyBackup string) error
ToggleBucketBackup(ctx context.Context, bucketName string, bucketBackup bool) error
ShareFilesViaPublicKey(ctx context.Context, bucketName string, paths []string, pubkeys []crypto.PubKey) error
GetAPISessionTokens(ctx context.Context) (*domain.APISessionTokens, error)
}

Expand Down
25 changes: 25 additions & 0 deletions core/textile/sharing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package textile

import (
"context"

crypto "github.com/libp2p/go-libp2p-crypto"
)

func (tc *textileClient) ShareFilesViaPublicKey(ctx context.Context, bucketName string, paths []string, pubkeys []crypto.PubKey) error {
// TOOD: uncomment once release and upgraded txl pkg
// ctx := tc.getHubCtx(ctx)

// for _, pth := range paths {
// var roles map[string]buckets.Role
// for _, pk := range pubkeys {
// roles[pk] = buckets.Role.Writer
// }
// err := tc.EditPathAccessRoles(ctx, key, pth, roles)
// if err != nil {
// return err
// }
// }

return nil
}
1 change: 1 addition & 0 deletions core/textile/textile.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Client interface {
Shutdown() error
WaitForReady() chan bool
Start(ctx context.Context, cfg config.Config) error
ShareFilesViaPublicKey(ctx context.Context, bucketName string, paths []string, pubkeys []crypto.PubKey) error
}

type Buckd interface {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/fatih/color v1.9.0 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.1
github.com/grpc-ecosystem/grpc-gateway v1.14.6
github.com/improbable-eng/grpc-web v0.12.0
github.com/ipfs/go-cid v0.0.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c h1:8ahmSVELW
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c/go.mod h1:Dq467ZllaHgAtVp4p1xUQWBrFXR9s/wyoTpG8zOJGkY=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible h1:8F3hqu9fGYLBifCmRCJsicFqDx/D68Rt3q1JMazcgBQ=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -860,6 +861,7 @@ github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.1.1-0.20190114141812-62fb9bc030d1 h1:qBCV/RLV02TSfQa7tFmxTihnG+u+7JXByOkhlkR5rmQ=
github.com/jonboulle/clockwork v0.1.1-0.20190114141812-62fb9bc030d1/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw=
Expand Down
19 changes: 18 additions & 1 deletion grpc/handlers_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@ import (
"context"

"github.com/FleekHQ/space-daemon/grpc/pb"
crypto "github.com/libp2p/go-libp2p-crypto"
)

func (srv *grpcServer) ShareFilesViaPublicKey(ctx context.Context, request *pb.ShareFilesViaPublicKeyRequest) (*pb.ShareFilesViaPublicKeyResponse, error) {
return nil, errNotImplemented

var pks []crypto.PubKey

for _, pk := range request.PublicKeys {
p, err := crypto.UnmarshalEd25519PublicKey([]byte(pk))
if err != nil {
return nil, err
}
pks = append(pks, p)
}

err := srv.sv.ShareFilesViaPublicKey(ctx, request.Bucket, request.Paths, pks)
if err != nil {
return nil, err
}

return &pb.ShareFilesViaPublicKeyResponse{}, nil
}

func (srv *grpcServer) GetSharedWithMeFiles(ctx context.Context, request *pb.GetSharedWithMeFilesRequest) (*pb.GetSharedWithMeFilesResponse, error) {
Expand Down
16 changes: 15 additions & 1 deletion mocks/mock_textile_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3dba584

Please sign in to comment.