Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OCM shares to last version of CS3APIs #3646

Merged
merged 46 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b66e85a
rewritten new share endpoint according to new ocm specs
gmgigi96 Jan 30, 2023
0802220
add go validator dependency
gmgigi96 Jan 30, 2023
f46b0c4
add new share to ocm client
gmgigi96 Jan 30, 2023
8eb474b
defined ocm repository
gmgigi96 Jan 30, 2023
ddfe37e
rewrote ocm core
gmgigi96 Feb 1, 2023
61df93c
rewrote ocm share provider
gmgigi96 Feb 1, 2023
75753ac
removed commented code
gmgigi96 Feb 1, 2023
4bef665
fixed app provider with new cs3apis
gmgigi96 Feb 2, 2023
cbe2c78
rewrote ocmshareprovider
gmgigi96 Feb 2, 2023
34fe2cd
fix commands
gmgigi96 Feb 2, 2023
4527da1
add share type
gmgigi96 Feb 2, 2023
f0eba5e
add token
gmgigi96 Feb 2, 2023
a51f50d
add expiration time to ocm shares
gmgigi96 Feb 2, 2023
17887a8
refactor
gmgigi96 Feb 2, 2023
4d6e591
do not set ctime and mtime of share in json driver
gmgigi96 Feb 2, 2023
7917435
set ctime and mtime of ocm share on creation
gmgigi96 Feb 2, 2023
f7faa3d
pass user obj
gmgigi96 Feb 2, 2023
2f56d72
removed old files
gmgigi96 Feb 2, 2023
3cce463
refactored nextcloud ocm share driver
gmgigi96 Feb 2, 2023
1ed8c94
removed unused variable
gmgigi96 Feb 2, 2023
6fea1bb
add commands to get info about ocm share
gmgigi96 Feb 3, 2023
fc858b1
generate crypto secure random string
gmgigi96 Feb 3, 2023
3d33767
fixes in json pkg
gmgigi96 Feb 3, 2023
d1d3f7c
fix linting
gmgigi96 Feb 3, 2023
4c20045
add randutil pkg
gmgigi96 Feb 3, 2023
4db441e
fixes
gmgigi96 Feb 6, 2023
2c48b56
expose recipient display name
gmgigi96 Feb 6, 2023
94b05df
fixes in json parsing
gmgigi96 Feb 8, 2023
5b9c17a
fix function name
gmgigi96 Feb 8, 2023
453c2b7
add helper functions for tests
gmgigi96 Feb 8, 2023
9977fea
fix response when creating new ocm share
gmgigi96 Feb 8, 2023
86ff859
fix errors in ocm share provider (still internal error)
gmgigi96 Feb 8, 2023
6a9c5f0
improved spawn revad daemons for testing. it's possible now define fi…
gmgigi96 Feb 8, 2023
a7f5580
defined integration tests for ocm shares
gmgigi96 Feb 8, 2023
719e37e
fixes in other tests
gmgigi96 Feb 8, 2023
f5a0ad5
use fork for go cs3 bindings
gmgigi96 Feb 8, 2023
770d919
fix typo
gmgigi96 Feb 8, 2023
a4ec227
fix linter
gmgigi96 Feb 8, 2023
0a2f57a
add changelog
gmgigi96 Feb 8, 2023
5101998
Merge branch 'master-upstream' into ocm-share
gmgigi96 Feb 8, 2023
c50d425
fix linter x2
gmgigi96 Feb 8, 2023
1a1b2e7
return correct errors according to specs
gmgigi96 Feb 8, 2023
174c247
add other tests and bugfixes
gmgigi96 Feb 8, 2023
e3d00d6
fix linter
gmgigi96 Feb 8, 2023
7880fdb
fix cmd for creating ocm shares
gmgigi96 Feb 8, 2023
64a7f55
Merge branch 'master' into ocm-share
gmgigi96 Feb 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/ocm-shares.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Enhancement: Update OCM shares to last version of CS3APIs

https://github.com/cs3org/reva/pull/3646
https://github.com/cs3org/cs3apis/pull/199
2 changes: 1 addition & 1 deletion cmd/reva/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *Completer) ocmShareReceivedArgumentCompleter() []prompt.Suggest {
}

for _, r := range info {
suggests = append(suggests, prompt.Suggest{Text: r.Share.Id.OpaqueId})
suggests = append(suggests, prompt.Suggest{Text: r.Id.OpaqueId})
}
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ var (
ocmShareListCommand(),
ocmShareRemoveCommand(),
ocmShareUpdateCommand(),
ocmShareGetCommand(),
ocmShareListReceivedCommand(),
ocmShareUpdateReceivedCommand(),
ocmShareGetReceivedCommand(),
openInAppCommand(),
preferencesCommand(),
publicShareCreateCommand(),
Expand Down
97 changes: 57 additions & 40 deletions cmd/reva/ocm-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ package main
import (
"io"
"os"
"strconv"
"time"

appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
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"
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/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
ocmshare "github.com/cs3org/reva/pkg/ocm/share"
"github.com/cs3org/reva/pkg/utils"
"github.com/jedib0t/go-pretty/table"
"github.com/pkg/errors"
Expand All @@ -45,10 +45,15 @@ func ocmShareCreateCommand() *command {
grantee := cmd.String("grantee", "", "the grantee")
idp := cmd.String("idp", "", "the idp of the grantee, default to same idp as the user triggering the action")
userType := cmd.String("user-type", "primary", "the type of user account, defaults to primary")
rol := cmd.String("rol", "viewer", "the permission for the share (viewer or editor)")

webdav := cmd.Bool("webdav", false, "create a share with webdav access")
webapp := cmd.Bool("webapp", false, "create a share for app access")
transfer := cmd.Bool("transfer", false, "create a share for a data transfer")

rol := cmd.String("rol", "viewer", "the permission for the share (viewer or editor) / applies to webdav and webapp")

cmd.ResetFlags = func() {
*grantType, *grantee, *idp, *rol, *userType = "user", "", "", "viewer", "primary"
*grantType, *grantee, *idp, *rol, *userType, *webdav, *webapp, *transfer = "user", "", "", "viewer", "primary", false, false, false
}

cmd.Action = func(w ...io.Writer) error {
Expand Down Expand Up @@ -101,40 +106,22 @@ func ocmShareCreateCommand() *command {
return formatError(res.Status)
}

perm, pint, err := getOCMSharePerm(*rol)
gt := getGrantType(*grantType)
am, err := getAccessMethods(*webdav, *webapp, *transfer, *rol)
if err != nil {
return err
}

gt := getGrantType(*grantType)
grant := &ocm.ShareGrant{
Permissions: perm,
shareRequest := &ocm.CreateOCMShareRequest{
ResourceId: res.Info.Id,
Grantee: &provider.Grantee{
Type: gt,
// For now, we only support user shares.
// TODO (ishank011): To be updated once this is decided.
Id: &provider.Grantee_UserId{UserId: u},
},
}

opaqueObj := &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"permissions": {
Decoder: "plain",
Value: []byte(strconv.Itoa(pint)),
},
"name": {
Decoder: "plain",
Value: []byte(res.Info.Path),
},
Id: &provider.Grantee_UserId{UserId: remoteUserRes.RemoteUser.Id},
},
}

shareRequest := &ocm.CreateOCMShareRequest{
Opaque: opaqueObj,
ResourceId: res.Info.Id,
Grant: grant,
RecipientMeshProvider: providerInfo.ProviderInfo,
AccessMethods: am,
}

shareRes, err := client.CreateOCMShare(ctx, shareRequest)
Expand All @@ -148,11 +135,12 @@ func ocmShareCreateCommand() *command {

t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
// TODO (gdelmont): expose protocols info

s := shareRes.Share
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
Expand All @@ -163,15 +151,44 @@ func ocmShareCreateCommand() *command {
return cmd
}

func getOCMSharePerm(p string) (*ocm.SharePermissions, int, error) {
if p == viewerPermission {
return &ocm.SharePermissions{
Permissions: conversions.NewViewerRole().CS3ResourcePermissions(),
}, 1, nil
} else if p == editorPermission {
return &ocm.SharePermissions{
Permissions: conversions.NewEditorRole().CS3ResourcePermissions(),
}, 15, nil
func getAccessMethods(webdav, webapp, transfer bool, rol string) ([]*ocm.AccessMethod, error) {
var m []*ocm.AccessMethod
if webdav {
perm, err := getOCMSharePerm(rol)
if err != nil {
return nil, err
}
m = append(m, ocmshare.NewWebDavAccessMethod(perm))
}
if webapp {
v, err := getOCMViewMode(rol)
if err != nil {
return nil, err
}
m = append(m, ocmshare.NewWebappAccessMethod(v))
}
if transfer {
m = append(m, ocmshare.NewTransferAccessMethod())
}
return m, nil
}

func getOCMSharePerm(p string) (*provider.ResourcePermissions, error) {
switch p {
case viewerPermission:
return conversions.NewViewerRole().CS3ResourcePermissions(), nil
case editorPermission:
return conversions.NewEditorRole().CS3ResourcePermissions(), nil
}
return nil, errors.New("invalid rol: " + p)
}

func getOCMViewMode(p string) (appprovider.ViewMode, error) {
switch p {
case viewerPermission:
return appprovider.ViewMode_VIEW_MODE_READ_ONLY, nil
case editorPermission:
return appprovider.ViewMode_VIEW_MODE_READ_WRITE, nil
}
return nil, 0, errors.New("invalid rol: " + p)
return 0, errors.New("invalid rol: " + p)
}
74 changes: 74 additions & 0 deletions cmd/reva/ocm-share-get-received.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"errors"
"fmt"
"io"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
"github.com/cs3org/reva/pkg/utils"
)

func ocmShareGetReceivedCommand() *command {
cmd := newCommand("ocm-share-get-received")
cmd.Description = func() string { return "get the info of the OCM share you have received" }
cmd.Usage = func() string { return "Usage: ocm-share-get-received" }
cmd.Action = func(w ...io.Writer) error {
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}

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

id := cmd.Arg(0)

shareRes, err := client.GetReceivedOCMShare(ctx, &ocm.GetReceivedOCMShareRequest{
Ref: &ocm.ShareReference{
Spec: &ocm.ShareReference_Id{
Id: &ocm.ShareId{
OpaqueId: id,
},
},
},
})
if err != nil {
return err
}
if shareRes.Status.Code != rpc.Code_CODE_OK {
return formatError(shareRes.Status)
}

d, err := utils.MarshalProtoV1ToJSON(shareRes.Share)
if err != nil {
return err
}

fmt.Println(string(d))

return nil
}
return cmd
}
74 changes: 74 additions & 0 deletions cmd/reva/ocm-share-get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"errors"
"fmt"
"io"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
"github.com/cs3org/reva/pkg/utils"
)

func ocmShareGetCommand() *command {
cmd := newCommand("ocm-share-get")
cmd.Description = func() string { return "get the info of the OCM share" }
cmd.Usage = func() string { return "Usage: ocm-share-get" }
cmd.Action = func(w ...io.Writer) error {
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}

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

id := cmd.Arg(0)

shareRes, err := client.GetOCMShare(ctx, &ocm.GetOCMShareRequest{
Ref: &ocm.ShareReference{
Spec: &ocm.ShareReference_Id{
Id: &ocm.ShareId{
OpaqueId: id,
},
},
},
})
if err != nil {
return err
}
if shareRes.Status.Code != rpc.Code_CODE_OK {
return formatError(shareRes.Status)
}

d, err := utils.MarshalProtoV1ToJSON(shareRes.Share)
if err != nil {
return err
}

fmt.Println(string(d))

return nil
}
return cmd
}
10 changes: 5 additions & 5 deletions cmd/reva/ocm-share-list-received.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func ocmShareListReceivedCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Type",
"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.ResourceId.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(), s.Share.ShareType.String()},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp,
s.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0),
time.Unix(int64(s.Mtime.Seconds), 0), s.State.String(), s.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 @@ -76,12 +76,12 @@ func ocmShareListCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Type",
"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.ResourceId.String(), s.Permissions.String(),
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(),
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
6 changes: 4 additions & 2 deletions cmd/reva/ocm-share-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ocmShareUpdateCommand() *command {
return err
}

perm, _, err := getOCMSharePerm(*rol)
perm, err := getOCMSharePerm(*rol)
if err != nil {
return err
}
Expand All @@ -69,7 +69,9 @@ func ocmShareUpdateCommand() *command {
},
Field: &ocm.UpdateOCMShareRequest_UpdateField{
Field: &ocm.UpdateOCMShareRequest_UpdateField_Permissions{
Permissions: perm,
Permissions: &ocm.SharePermissions{
Permissions: perm,
},
},
},
}
Expand Down
Loading