Skip to content

Commit

Permalink
Fix command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Feb 8, 2021
1 parent 0eb632d commit 7fe6bcd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/reva/ocm-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func ocmShareCreateCommand() *command {
Permissions: perm,
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: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
Expand Down
27 changes: 22 additions & 5 deletions cmd/reva/share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"time"

grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
Expand Down Expand Up @@ -89,12 +90,22 @@ func shareCreateCommand() *command {
},
Grantee: &provider.Grantee{
Type: gt,
Id: &provider.Grantee_UserId{UserId: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
}},
},
}
if *grantType == "user" {
grant.Grantee.Id = &provider.Grantee_UserId{UserId: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
}}
} else if *grantType == "group" {
grant.Grantee.Id = &provider.Grantee_GroupId{GroupId: &grouppb.GroupId{
Idp: *idp,
OpaqueId: *grantee,
}}
} else {
return errors.New("Invalid grantee type argument: " + *grantType)
}

shareRequest := &collaboration.CreateShareRequest{
ResourceInfo: res.Info,
Grant: grant,
Expand All @@ -114,9 +125,15 @@ func shareCreateCommand() *command {
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

s := shareRes.Share
var idp, opaque string
if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId
} else if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId
}
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
s.Grantee.Type.String(), idp, opaque,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
t.Render()
Expand Down
11 changes: 9 additions & 2 deletions cmd/reva/share-list-received.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/jedib0t/go-pretty/table"
)

Expand Down Expand Up @@ -57,10 +58,16 @@ func shareListReceivedCommand() *command {
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
for _, s := range shareRes.Shares {
var idp, opaque string
if s.Share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Share.Grantee.GetUserId().Idp, s.Share.Grantee.GetUserId().OpaqueId
} else if s.Share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Share.Grantee.GetGroupId().Idp, s.Share.Grantee.GetGroupId().OpaqueId
}
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),
s.Share.Permissions.String(), s.Share.Grantee.Type.String(), idp,
opaque, time.Unix(int64(s.Share.Ctime.Seconds), 0),
time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
})
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/reva/share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ func shareListCommand() *command {
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

for _, s := range shareRes.Shares {
var idp, opaque string
if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId
} else if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId
}
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
s.Grantee.Type.String(), idp, opaque,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
}
Expand Down

0 comments on commit 7fe6bcd

Please sign in to comment.