Skip to content

Commit

Permalink
Merge pull request #211 from FleekHQ/master
Browse files Browse the repository at this point in the history
Sync develop with master
  • Loading branch information
jsonsivar authored Oct 19, 2020
2 parents 448fff6 + 1bef0c3 commit e2349fe
Show file tree
Hide file tree
Showing 27 changed files with 315 additions and 70 deletions.
2 changes: 1 addition & 1 deletion core/space/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/FleekHQ/space-daemon/core/vault"
"github.com/FleekHQ/space-daemon/mocks"
"github.com/stretchr/testify/assert"
buckets_pb "github.com/textileio/textile/api/buckets/pb"
buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions core/textile/buckd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/FleekHQ/space-daemon/config"
"github.com/FleekHQ/space-daemon/log"
"github.com/textileio/textile/cmd"
"github.com/textileio/textile/core"
"github.com/textileio/textile/v2/cmd"
"github.com/textileio/textile/v2/core"
)

var IpfsAddr string
Expand Down
6 changes: 3 additions & 3 deletions core/textile/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/textileio/go-threads/core/thread"
bucketsClient "github.com/textileio/textile/api/buckets/client"
bucketsproto "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/buckets"
bucketsClient "github.com/textileio/textile/v2/api/buckets/client"
bucketsproto "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/buckets"
)

type BucketData struct {
Expand Down
8 changes: 4 additions & 4 deletions core/textile/bucket_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/alecthomas/jsonschema"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/go-threads/db"
bc "github.com/textileio/textile/api/buckets/client"
buckets_pb "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/cmd"
tdb "github.com/textileio/textile/threaddb"
bc "github.com/textileio/textile/v2/api/buckets/client"
buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/cmd"
tdb "github.com/textileio/textile/v2/threaddb"
)

func NotFound(slug string) error {
Expand Down
10 changes: 5 additions & 5 deletions core/textile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/FleekHQ/space-daemon/log"
threadsClient "github.com/textileio/go-threads/api/client"
nc "github.com/textileio/go-threads/net/api/client"
bucketsClient "github.com/textileio/textile/api/buckets/client"
"github.com/textileio/textile/api/common"
uc "github.com/textileio/textile/api/users/client"
"github.com/textileio/textile/cmd"
mail "github.com/textileio/textile/mail/local"
bucketsClient "github.com/textileio/textile/v2/api/buckets/client"
"github.com/textileio/textile/v2/api/common"
uc "github.com/textileio/textile/v2/api/users/client"
"github.com/textileio/textile/v2/cmd"
mail "github.com/textileio/textile/v2/mail/local"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand Down
2 changes: 1 addition & 1 deletion core/textile/hub/hub_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/dgrijalva/jwt-go"
mbase "github.com/multiformats/go-multibase"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/api/common"
"github.com/textileio/textile/v2/api/common"
"golang.org/x/net/websocket"
)

Expand Down
6 changes: 3 additions & 3 deletions core/textile/mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/FleekHQ/space-daemon/log"
crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/api/users/client"
"github.com/textileio/textile/cmd"
mail "github.com/textileio/textile/mail/local"
"github.com/textileio/textile/v2/api/users/client"
"github.com/textileio/textile/v2/cmd"
mail "github.com/textileio/textile/v2/mail/local"
)

type GrpcMailboxNotifier interface {
Expand Down
4 changes: 2 additions & 2 deletions core/textile/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

"github.com/ipfs/go-cid"
"github.com/pkg/errors"
api_buckets_pb "github.com/textileio/textile/api/buckets/pb"
api_buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"

"github.com/FleekHQ/space-daemon/core/textile/bucket"

"github.com/FleekHQ/space-daemon/core/textile/utils"
"github.com/FleekHQ/space-daemon/log"
"github.com/textileio/go-threads/core/thread"
bc "github.com/textileio/textile/api/buckets/client"
bc "github.com/textileio/textile/v2/api/buckets/client"
)

// Get a public bucket on hub. Public bucket has no encryption and its content should be accessible directly via ipfs/ipns
Expand Down
8 changes: 4 additions & 4 deletions core/textile/secure_bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/FleekHQ/space-daemon/core/textile/bucket/crypto"

"github.com/ipfs/interface-go-ipfs-core/path"
bc "github.com/textileio/textile/api/buckets/client"
bucketsClient "github.com/textileio/textile/api/buckets/client"
bucketspb "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/buckets"
bc "github.com/textileio/textile/v2/api/buckets/client"
bucketsClient "github.com/textileio/textile/v2/api/buckets/client"
bucketspb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/buckets"
)

var textileRelPathRegex = regexp.MustCompile(`/ip[f|n]s/[^/]*(?P<relPath>/.*)`)
Expand Down
2 changes: 1 addition & 1 deletion core/textile/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/FleekHQ/space-daemon/log"
crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/buckets"
"github.com/textileio/textile/v2/buckets"
)

func (tc *textileClient) ShareFilesViaPublicKey(ctx context.Context, paths []domain.FullPath, pubkeys []crypto.PubKey, keys [][]byte) error {
Expand Down
4 changes: 2 additions & 2 deletions core/textile/sync/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/FleekHQ/space-daemon/log"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/go-threads/db"
bucketsClient "github.com/textileio/textile/api/buckets/client"
"github.com/textileio/textile/buckets"
bucketsClient "github.com/textileio/textile/v2/api/buckets/client"
"github.com/textileio/textile/v2/buckets"
)

const mirrorThreadKeyName = "mirrorV1"
Expand Down
2 changes: 1 addition & 1 deletion core/textile/sync/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
threadsClient "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
nc "github.com/textileio/go-threads/net/api/client"
bucketsClient "github.com/textileio/textile/api/buckets/client"
bucketsClient "github.com/textileio/textile/v2/api/buckets/client"
)

type GetMirrorBucketFn func(ctx context.Context, slug string) (bucket.BucketInterface, error)
Expand Down
2 changes: 1 addition & 1 deletion core/textile/sync/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/FleekHQ/space-daemon/config"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/cmd"
"github.com/textileio/textile/v2/cmd"
)

// replicate a local thread on the hub
Expand Down
4 changes: 2 additions & 2 deletions core/textile/textile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/textileio/go-threads/db"

buckets_pb "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/api/users/client"
buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/api/users/client"

threadsClient "github.com/textileio/go-threads/api/client"
)
Expand Down
2 changes: 1 addition & 1 deletion core/textile/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
crypto "github.com/libp2p/go-libp2p-crypto"
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/api/common"
"github.com/textileio/textile/v2/api/common"
"golang.org/x/crypto/pbkdf2"
)

Expand Down
146 changes: 146 additions & 0 deletions examples/textileBucketsClient/bucket-sync/bucket-sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package main

import (
"bytes"
"context"
"crypto/rand"
"crypto/tls"
"log"
"os"
"strings"
"time"

"github.com/libp2p/go-libp2p-core/crypto"
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
bc "github.com/textileio/textile/v2/api/buckets/client"
buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/api/common"
tb "github.com/textileio/textile/v2/buckets"
"github.com/textileio/textile/v2/cmd"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

type TextileBucketRoot buckets_pb.Root

func main() {
host := os.Getenv("TXL_HUB_TARGET")
key := os.Getenv("TXL_USER_KEY")
secret := os.Getenv("TXL_USER_SECRET")

var threads *tc.Client
var buckets *bc.Client
var err error
auth := common.Credentials{}
var opts []grpc.DialOption
hubTarget := host
threadstarget := host

if strings.Contains(host, "443") {
creds := credentials.NewTLS(&tls.Config{})
opts = append(opts, grpc.WithTransportCredentials(creds))
auth.Secure = true
} else {
opts = append(opts, grpc.WithInsecure())
}

opts = append(opts, grpc.WithPerRPCCredentials(auth))

buckets, err = bc.NewClient(hubTarget, opts...)
if err != nil {
cmd.Fatal(err)
}
threads, err = tc.NewClient(threadstarget, opts...)
if err != nil {
cmd.Fatal(err)
}

user1, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
log.Println("error creating user1")
log.Fatal(err)
}

user2, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
log.Println("error creating user2")
log.Fatal(err)
}

// user 1 creates bucket and adds file

ctx := context.Background()
ctx = common.NewAPIKeyContext(ctx, key)

ctx, err = common.CreateAPISigContext(ctx, time.Now().Add(time.Minute*2), secret)
if err != nil {
log.Println("error creating APISigContext")
log.Fatal(err)
}

tok, err := threads.GetToken(ctx, thread.NewLibp2pIdentity(user1))
if err != nil {
log.Println("error calling GetToken")
log.Fatal(err)
}

ctx = thread.NewTokenContext(ctx, tok)

bucket1name := "testbucket1"

ctx = common.NewThreadNameContext(ctx, bucket1name)
dbID := thread.NewIDV1(thread.Raw, 32)
if err := threads.NewDB(ctx, dbID); err != nil {
log.Println("error calling threads.NewDB")
log.Fatal(err)
}

ctx = common.NewThreadIDContext(ctx, dbID)

buck, err := buckets.Create(ctx, bc.WithName(bucket1name), bc.WithPrivate(true))
log.Println("created bucket: " + buck.Root.Name)

filepath := "file1"
f := &bytes.Buffer{}
f.Write([]byte("hello space"))
_, _, err = buckets.PushPath(ctx, buck.Root.Key, filepath, f)

if err != nil {
log.Println("error pushing path")
log.Fatal(err)
}

roles := make(map[string]tb.Role)
tpk := thread.NewLibp2pPubKey(user2.GetPublic())
roles[tpk.String()] = tb.Admin
err = buckets.PushPathAccessRoles(ctx, buck.Root.Key, filepath, roles)
if err != nil {
log.Println("error sharing path")
log.Fatal(err)
}

// user 2 tries to access
ctx1 := context.Background()
ctx1 = common.NewAPIKeyContext(ctx1, key)
ctx1, err = common.CreateAPISigContext(ctx1, time.Now().Add(time.Minute*2), secret)
tok, err = threads.GetToken(ctx1, thread.NewLibp2pIdentity(user2))
ctx1 = thread.NewTokenContext(ctx1, tok)

if err != nil {
log.Println("error creating context")
log.Fatal(err)
}

ctx1 = common.NewThreadNameContext(ctx1, bucket1name)
ctx1 = common.NewThreadIDContext(ctx1, dbID)
var buf bytes.Buffer
err = buckets.PullPath(ctx1, buck.Root.Key, filepath, &buf)
if err != nil {
log.Println("error pulling path")
log.Fatal(err)
}

s := buf.String()
log.Println("fetch file content: " + s)
}
10 changes: 5 additions & 5 deletions examples/textileBucketsClient/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
netapiclient "github.com/textileio/go-threads/net/api/client"
netpb "github.com/textileio/go-threads/net/api/pb"
"github.com/textileio/go-threads/util"
bc "github.com/textileio/textile/api/buckets/client"
pb "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/api/common"
uc "github.com/textileio/textile/api/users/client"
"github.com/textileio/textile/cmd"
bc "github.com/textileio/textile/v2/api/buckets/client"
pb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/api/common"
uc "github.com/textileio/textile/v2/api/users/client"
"github.com/textileio/textile/v2/cmd"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/go-threads/db"
"github.com/textileio/textile/api/common"
"github.com/textileio/textile/cmd"
"github.com/textileio/textile/core"
"github.com/textileio/textile/v2/api/common"
"github.com/textileio/textile/v2/cmd"
"github.com/textileio/textile/v2/core"
"google.golang.org/grpc"
)

Expand Down
6 changes: 3 additions & 3 deletions examples/textileBucketsClient/join-thread/join-thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
ma "github.com/multiformats/go-multiaddr"
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/api/common"
"github.com/textileio/textile/cmd"
"github.com/textileio/textile/core"
"github.com/textileio/textile/v2/api/common"
"github.com/textileio/textile/v2/cmd"
"github.com/textileio/textile/v2/core"
"google.golang.org/grpc"
)

Expand Down
8 changes: 4 additions & 4 deletions examples/textileBucketsClient/local-buck/local-buck.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
nc "github.com/textileio/go-threads/net/api/client"
bc "github.com/textileio/textile/api/buckets/client"
"github.com/textileio/textile/api/common"
"github.com/textileio/textile/cmd"
"github.com/textileio/textile/core"
bc "github.com/textileio/textile/v2/api/buckets/client"
"github.com/textileio/textile/v2/api/common"
"github.com/textileio/textile/v2/cmd"
"github.com/textileio/textile/v2/core"
"google.golang.org/grpc"
)

Expand Down
10 changes: 5 additions & 5 deletions examples/textileBucketsClient/open-share-file/open-share-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/libp2p/go-libp2p-core/crypto"
tc "github.com/textileio/go-threads/api/client"
"github.com/textileio/go-threads/core/thread"
bc "github.com/textileio/textile/api/buckets/client"
buckets_pb "github.com/textileio/textile/api/buckets/pb"
"github.com/textileio/textile/api/common"
tb "github.com/textileio/textile/buckets"
"github.com/textileio/textile/cmd"
bc "github.com/textileio/textile/v2/api/buckets/client"
buckets_pb "github.com/textileio/textile/v2/api/buckets/pb"
"github.com/textileio/textile/v2/api/common"
tb "github.com/textileio/textile/v2/buckets"
"github.com/textileio/textile/v2/cmd"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand Down
Loading

0 comments on commit e2349fe

Please sign in to comment.