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

SQL driver for share manager #1224

Merged
merged 7 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion changelog/1.3.0_2020-10-08/eos-version-invariant.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ versions of a file by returning the inode of the version folder which remains
constant. It requires extra metadata operations so a flag is provided to disable
it.

https://github.com/cs3org/reva/pull/1174.
https://github.com/cs3org/reva/pull/1174
6 changes: 6 additions & 0 deletions changelog/unreleased/shares-sql-driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add SQL driver for share manager

This PR adds an SQL driver for the shares manager which expects a schema
equivalent to the one used in production for CERNBox.

https://github.com/cs3org/reva/pull/1224
1 change: 1 addition & 0 deletions cmd/revad/runtime/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
_ "github.com/cs3org/reva/internal/http/services/loader"
_ "github.com/cs3org/reva/pkg/auth/manager/loader"
_ "github.com/cs3org/reva/pkg/auth/registry/loader"
_ "github.com/cs3org/reva/pkg/cbox/loader"
_ "github.com/cs3org/reva/pkg/metrics/driver/loader"
_ "github.com/cs3org/reva/pkg/ocm/invite/manager/loader"
_ "github.com/cs3org/reva/pkg/ocm/provider/authorizer/loader"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/go-ldap/ldap/v3 v3.2.4
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.5.0
github.com/gofrs/uuid v3.3.0+incompatible
github.com/golang/protobuf v1.4.3
github.com/gomodule/redigo v1.8.2
Expand Down
99 changes: 2 additions & 97 deletions go.sum

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions pkg/cbox/loader/loader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018-2020 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 loader

import (
// Load cbox specific drivers.
_ "github.com/cs3org/reva/pkg/cbox/share/sql"
_ "github.com/cs3org/reva/pkg/cbox/user/rest"
)
165 changes: 165 additions & 0 deletions pkg/cbox/share/sql/conversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2018-2020 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 sql

import (
"fmt"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
)

func granteeTypeToInt(g provider.GranteeType) int {
switch g {
case provider.GranteeType_GRANTEE_TYPE_USER:
return 0
case provider.GranteeType_GRANTEE_TYPE_GROUP:
return 1
default:
return -1
}
}

func intToGranteeType(g int) provider.GranteeType {
switch g {
case 0:
return provider.GranteeType_GRANTEE_TYPE_USER
case 1:
return provider.GranteeType_GRANTEE_TYPE_GROUP
default:
return provider.GranteeType_GRANTEE_TYPE_INVALID
}
}

func resourceTypeToItem(r provider.ResourceType) string {
switch r {
case provider.ResourceType_RESOURCE_TYPE_FILE:
return "file"
case provider.ResourceType_RESOURCE_TYPE_CONTAINER:
return "folder"
case provider.ResourceType_RESOURCE_TYPE_REFERENCE:
return "reference"
case provider.ResourceType_RESOURCE_TYPE_SYMLINK:
return "symlink"
default:
return ""
}
}

func sharePermToInt(p *provider.ResourcePermissions) int {
var perm int
if p.CreateContainer {
perm = 15
} else if p.ListContainer {
perm = 1
}
return perm
}

func intTosharePerm(p int) *provider.ResourcePermissions {
switch p {
case 1:
return &provider.ResourcePermissions{
ListContainer: true,
ListGrants: true,
ListFileVersions: true,
ListRecycle: true,
Stat: true,
GetPath: true,
GetQuota: true,
InitiateFileDownload: true,
}
case 15:
return &provider.ResourcePermissions{
ListContainer: true,
ListGrants: true,
ListFileVersions: true,
ListRecycle: true,
Stat: true,
GetPath: true,
GetQuota: true,
InitiateFileDownload: true,

Move: true,
InitiateFileUpload: true,
RestoreFileVersion: true,
RestoreRecycleItem: true,
CreateContainer: true,
Delete: true,
PurgeRecycle: true,
}
default:
return &provider.ResourcePermissions{}
}
}

func intToShareState(g int) collaboration.ShareState {
switch g {
case 0:
return collaboration.ShareState_SHARE_STATE_PENDING
case 1:
return collaboration.ShareState_SHARE_STATE_ACCEPTED
default:
return collaboration.ShareState_SHARE_STATE_INVALID
}
}

func formatUserID(u *userpb.UserId) string {
if u.Idp != "" {
return fmt.Sprintf("%s:%s", u.OpaqueId, u.Idp)
}
return u.OpaqueId
}

func extractUserID(u string) *userpb.UserId {
parts := strings.Split(u, ":")
if len(parts) > 1 {
return &userpb.UserId{OpaqueId: parts[0], Idp: parts[1]}
}
return &userpb.UserId{OpaqueId: parts[0]}
}

func convertToCS3Share(s dbShare) *collaboration.Share {
ts := &typespb.Timestamp{
Seconds: uint64(s.STime),
}
return &collaboration.Share{
Id: &collaboration.ShareId{
OpaqueId: s.ID,
},
ResourceId: &provider.ResourceId{OpaqueId: s.ItemSource, StorageId: s.Prefix},
Permissions: &collaboration.SharePermissions{Permissions: intTosharePerm(s.Permissions)},
Grantee: &provider.Grantee{Type: intToGranteeType(s.ShareType), Id: extractUserID(s.ShareWith)},
Owner: extractUserID(s.UIDOwner),
Creator: extractUserID(s.UIDInitiator),
Ctime: ts,
Mtime: ts,
}
}

func convertToCS3ReceivedShare(s dbShare) *collaboration.ReceivedShare {
share := convertToCS3Share(s)
return &collaboration.ReceivedShare{
Share: share,
State: intToShareState(s.State),
}
}
Loading