Skip to content

Commit

Permalink
Merge branch 'master' into new-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
butonic committed May 25, 2021
2 parents d18452f + b1d57b9 commit 0d9cfe3
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 82 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/datatx-createtransfer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Create transfer type share

`transfer-create` creates a share of type transfer.

https://github.com/cs3org/reva/pull/1725
1 change: 1 addition & 0 deletions changelog/unreleased/update-share-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Enhancement: Add share to update response
After accepting or rejecting a share the API includes the updated share in the response.

https://github.com/cs3org/reva/pull/1685
https://github.com/cs3org/reva/pull/1724
4 changes: 2 additions & 2 deletions cmd/reva/ocm-share-list-received.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func ocmShareListReceivedCommand() *command {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State", "ShareType"})
for _, s := range shareRes.Shares {
t.AppendRows([]table.Row{
{s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.Ref.String(),
s.Share.Permissions.String(), s.Share.Grantee.Type.String(), s.Share.Grantee.GetUserId().Idp,
s.Share.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Share.Ctime.Seconds), 0),
time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String(), s.Share.ShareType.String()},
})
}
t.Render()
Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/ocm-share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func ocmShareListCommand() *command {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
"ShareType", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

for _, s := range shareRes.Shares {
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
s.Grantee.Type.String(), s.ShareType.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
}
Expand Down
125 changes: 116 additions & 9 deletions cmd/reva/transfer-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,149 @@
package main

import (
"errors"
"io"
"os"
"strconv"
"strings"
"time"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1"
ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
tx "github.com/cs3org/go-cs3apis/cs3/tx/v1beta1"
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/jedib0t/go-pretty/table"
"github.com/pkg/errors"
)

func transferCreateCommand() *command {
cmd := newCommand("transfer-create")
cmd.Description = func() string { return "create transfer between 2 remotes" }
cmd.Usage = func() string { return "Usage: transfer-create [-flags]" }
cmd.Description = func() string { return "create transfer between 2 sites" }
cmd.Usage = func() string { return "Usage: transfer-create [-flags] <path>" }
grantee := cmd.String("grantee", "", "the grantee, receiver of the transfer")
granteeType := cmd.String("granteeType", "user", "the grantee type, one of: user, group")
idp := cmd.String("idp", "", "the idp of the grantee, default to same idp as the user triggering the action")

cmd.Action = func(w ...io.Writer) error {
// validate flags
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}

if *grantee == "" {
return errors.New("Grantee cannot be empty: use -grantee flag\n" + cmd.Usage())
}
if *idp == "" {
return errors.New("Idp cannot be empty: use -idp flag\n" + cmd.Usage())
}

// the resource to transfer; the path
fn := cmd.Args()[0]

ctx := getAuthContext()
client, err := getClient()
if err != nil {
return err
}

transferRequest := &tx.CreateTransferRequest{}
// check if invitation has been accepted
acceptedUserRes, err := client.GetAcceptedUser(ctx, &invitepb.GetAcceptedUserRequest{
RemoteUserId: &userpb.UserId{OpaqueId: *grantee, Idp: *idp},
})
if err != nil {
return err
}
if acceptedUserRes.Status.Code != rpc.Code_CODE_OK {
return formatError(acceptedUserRes.Status)
}

transferResponse, err := client.CreateTransfer(ctx, transferRequest)
// verify resource stats
statReq := &provider.StatRequest{
Ref: &provider.Reference{Path: fn},
}
statRes, err := client.Stat(ctx, statReq)
if err != nil {
return err
}
if transferResponse.Status.Code != rpc.Code_CODE_OK {
return formatError(transferResponse.Status)
if statRes.Status.Code != rpc.Code_CODE_OK {
return formatError(statRes.Status)
}

providerInfoResp, err := client.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
Domain: *idp,
})
if err != nil {
return err
}

resourcePermissions, pint, err := getOCMSharePerm(editorPermission)
if err != nil {
return err
}

gt := provider.GranteeType_GRANTEE_TYPE_USER
if strings.ToLower(*granteeType) == "group" {
gt = provider.GranteeType_GRANTEE_TYPE_GROUP
}

createShareReq := &ocm.CreateOCMShareRequest{
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"permissions": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(strconv.Itoa(pint)),
},
"name": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(statRes.Info.Ref.Path),
},
"protocol": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("datatx"),
},
},
},
Ref: statRes.Info.Id,
Grant: &ocm.ShareGrant{
Grantee: &provider.Grantee{
Type: gt,
Id: &provider.Grantee_UserId{
UserId: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
},
},
},
Permissions: resourcePermissions,
},
RecipientMeshProvider: providerInfoResp.ProviderInfo,
}

createShareResponse, err := client.CreateOCMShare(ctx, createShareReq)
if err != nil {
return err
}
if createShareResponse.Status.Code != rpc.Code_CODE_OK {
if createShareResponse.Status.Code == rpc.Code_CODE_NOT_FOUND {
return formatError(statRes.Status)
}
return err
}

t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "ShareType", "Created", "Updated"})

s := createShareResponse.Share
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId, s.ShareType.String(),
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
t.Render()
return nil
}

return cmd
}
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/ReneKroon/ttlcache/v2 v2.4.0
github.com/ReneKroon/ttlcache/v2 v2.5.0
github.com/aws/aws-sdk-go v1.38.40
github.com/bluele/gcache v0.0.2
github.com/c-bata/go-prompt v0.2.5
Expand All @@ -18,8 +18,6 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/go-ldap/ldap/v3 v3.3.0
github.com/go-openapi/errors v0.19.6 // indirect
github.com/go-openapi/strfmt v0.19.2 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/protobuf v1.5.2
github.com/gomodule/redigo v1.8.4
Expand All @@ -36,7 +34,7 @@ require (
github.com/mitchellh/mapstructure v1.4.1
github.com/onsi/ginkgo v1.16.2
github.com/onsi/gomega v1.12.0
github.com/ory/fosite v0.39.0
github.com/ory/fosite v0.40.1
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.3
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
Expand Down
Loading

0 comments on commit 0d9cfe3

Please sign in to comment.