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

Stubs for storage spaces manipulation and make sql janitor configureable #1513

Merged
merged 5 commits into from
Mar 4, 2021
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
7 changes: 7 additions & 0 deletions changelog/unreleased/storage-space-stubs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add stubs for storage spaces manipulation

This PR adds stubs for the storage space CRUD methods in the storageprovider
service and makes the expired shares janitor configureable in the publicshares
SQL driver.

https://github.com/cs3org/reva/pull/1513
2 changes: 1 addition & 1 deletion cmd/reva/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func uploadCommand() *command {
}
defer httpRes.Body.Close()
if httpRes.StatusCode != http.StatusOK {
return err
return errors.New("upload: PUT request returned " + httpRes.Status)
}
} else {
// create the tus client.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20210209082852-35ace33082f5
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508
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.2.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJff
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20210209082852-35ace33082f5 h1:wy1oeyy6v9/65G97AkE5o4jC9J+sngPV9AZL5TbNsaY=
github.com/cs3org/go-cs3apis v0.0.0-20210209082852-35ace33082f5/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508 h1:AyeoeZZGPC1lTN7mhgh8HGwwRlvG8hXJ/06q9P+ad9I=
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
89 changes: 89 additions & 0 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,99 @@ func (s *svc) CreateHome(ctx context.Context, req *provider.CreateHomeRequest) (
Status: status.NewInternal(ctx, err, "error calling CreateHome"),
}, nil
}
return res, nil
}

func (s *svc) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
c, err := s.findByPath(ctx, req.Type)
if err != nil {
return &provider.CreateStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
}, nil
}

res, err := c.CreateStorageSpace(ctx, req)
if err != nil {
log.Err(err).Msg("gateway: error creating storage space on storage provider")
return &provider.CreateStorageSpaceResponse{
Status: status.NewInternal(ctx, err, "error calling CreateStorageSpace"),
}, nil
}
return res, nil
}

func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
var id *provider.StorageSpaceId
for _, f := range req.Filters {
if f.Type == provider.ListStorageSpacesRequest_Filter_TYPE_ID {
id = f.GetId()
}
}
c, err := s.findByID(ctx, &provider.ResourceId{
OpaqueId: id.OpaqueId,
})
if err != nil {
return &provider.ListStorageSpacesResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
}, nil
}

res, err := c.ListStorageSpaces(ctx, req)
if err != nil {
log.Err(err).Msg("gateway: error listing storage space on storage provider")
return &provider.ListStorageSpacesResponse{
Status: status.NewInternal(ctx, err, "error calling ListStorageSpaces"),
}, nil
}
return res, nil
}

func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
c, err := s.findByID(ctx, req.StorageSpace.Root)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding ID", err),
}, nil
}

res, err := c.UpdateStorageSpace(ctx, req)
if err != nil {
log.Err(err).Msg("gateway: error creating update space on storage provider")
return &provider.UpdateStorageSpaceResponse{
Status: status.NewInternal(ctx, err, "error calling UpdateStorageSpace"),
}, nil
}
return res, nil
}

func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
c, err := s.findByID(ctx, &provider.ResourceId{
OpaqueId: req.Id.OpaqueId,
})
if err != nil {
return &provider.DeleteStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
}, nil
}

res, err := c.DeleteStorageSpace(ctx, req)
if err != nil {
log.Err(err).Msg("gateway: error deleting storage space on storage provider")
return &provider.DeleteStorageSpaceResponse{
Status: status.NewInternal(ctx, err, "error calling DeleteStorageSpace"),
}, nil
}
return res, nil
}

func (s *svc) GetHome(ctx context.Context, _ *provider.GetHomeRequest) (*provider.GetHomeResponse, error) {
home := s.getHome(ctx)
homeRes := &provider.GetHomeResponse{Path: home, Status: status.NewOK(ctx)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ func (s *service) CreateHome(ctx context.Context, req *provider.CreateHomeReques
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
}

func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
}

func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
}

func (s *service) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
}

func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) {
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
}

func (s *service) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
ctx, span := trace.StartSpan(ctx, "CreateContainer")
defer span.End()
Expand Down
23 changes: 23 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,30 @@ func (s *service) CreateHome(ctx context.Context, req *provider.CreateHomeReques
Status: status.NewOK(ctx),
}
return res, nil
}

func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
return &provider.CreateStorageSpaceResponse{
Status: status.NewUnimplemented(ctx, errors.New("CreateStorageSpace not implemented"), "CreateStorageSpace not implemented"),
}, nil
}

func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
return &provider.ListStorageSpacesResponse{
Status: status.NewUnimplemented(ctx, errors.New("ListStorageSpaces not implemented"), "ListStorageSpaces not implemented"),
}, nil
}

func (s *service) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
return &provider.UpdateStorageSpaceResponse{
Status: status.NewUnimplemented(ctx, errors.New("UpdateStorageSpace not implemented"), "UpdateStorageSpace not implemented"),
}, nil
}

func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) {
return &provider.DeleteStorageSpaceResponse{
Status: status.NewUnimplemented(ctx, errors.New("DeleteStorageSpace not implemented"), "DeleteStorageSpace not implemented"),
}, nil
}

func (s *service) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
Expand Down
18 changes: 9 additions & 9 deletions internal/http/services/owncloud/ocs/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func (r *Role) OCSPermissions() Permissions {
func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) string {
var b strings.Builder
//b.Grow(7)
if !isPublic && isShared {
fmt.Fprintf(&b, "S")
}
if r.ocsPermissions.Contain(PermissionShare) {
fmt.Fprintf(&b, "R")
}
if !isPublic && isMountpoint {
fmt.Fprintf(&b, "M")
}
if r.ocsPermissions.Contain(PermissionDelete) {
fmt.Fprintf(&b, "D") // TODO oc10 shows received shares as deletable
}
Expand All @@ -104,15 +113,6 @@ func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) s
if isDir && r.ocsPermissions.Contain(PermissionCreate) {
fmt.Fprintf(&b, "CK")
}
if !isPublic && isShared {
fmt.Fprintf(&b, "S")
}
if r.ocsPermissions.Contain(PermissionShare) {
fmt.Fprintf(&b, "R")
}
if !isPublic && isMountpoint {
fmt.Fprintf(&b, "M")
}
return b.String()
}

Expand Down
17 changes: 5 additions & 12 deletions pkg/cbox/group/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func init() {
}

var (
emailRegex = regexp.MustCompile(`^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$`)
groupNameRegex = regexp.MustCompile(`^[ a-zA-Z0-9._-]+$`)
emailRegex = regexp.MustCompile(`^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$`)
)

type manager struct {
Expand Down Expand Up @@ -404,16 +403,10 @@ func (m *manager) findGroupsByFilter(ctx context.Context, url string, groups map
}

func (m *manager) FindGroups(ctx context.Context, query string) ([]*grouppb.Group, error) {

var filters []string
switch {
case groupNameRegex.MatchString(query):
filters = []string{"groupidentifier", "displayName"}
case emailRegex.MatchString(query):
filters = []string{"groupidentifier"}
query = strings.TrimSuffix(query, "@cern.ch")
default:
return nil, errors.New("rest: illegal characters present in query")
filters := []string{"groupIdentifier"}
if emailRegex.MatchString(query) {
parts := strings.Split(query, "@")
query = parts[0]
}

groups := make(map[string]*grouppb.Group)
Expand Down
23 changes: 16 additions & 7 deletions pkg/cbox/publicshare/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ func init() {
}

type config struct {
SharePasswordHashCost int `mapstructure:"password_hash_cost"`
JanitorRunInterval int `mapstructure:"janitor_run_interval"`
DbUsername string `mapstructure:"db_username"`
DbPassword string `mapstructure:"db_password"`
DbHost string `mapstructure:"db_host"`
DbPort int `mapstructure:"db_port"`
DbName string `mapstructure:"db_name"`
SharePasswordHashCost int `mapstructure:"password_hash_cost"`
JanitorRunInterval int `mapstructure:"janitor_run_interval"`
EnableExpiredSharesCleanup bool `mapstructure:"enable_expired_shares_cleanup"`
DbUsername string `mapstructure:"db_username"`
DbPassword string `mapstructure:"db_password"`
DbHost string `mapstructure:"db_host"`
DbPort int `mapstructure:"db_port"`
DbName string `mapstructure:"db_name"`
}

type manager struct {
Expand All @@ -75,6 +76,10 @@ func (c *config) init() {
}

func (m *manager) startJanitorRun() {
if !m.c.EnableExpiredSharesCleanup {
return
}

ticker := time.NewTicker(time.Duration(m.c.JanitorRunInterval) * time.Second)
work := make(chan os.Signal, 1)
signal.Notify(work, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT)
Expand Down Expand Up @@ -415,6 +420,10 @@ func (m *manager) GetPublicShareByToken(ctx context.Context, token, password str
}

func (m *manager) cleanupExpiredShares() error {
if !m.c.EnableExpiredSharesCleanup {
return nil
}

query := "delete from oc_share where expiration IS NOT NULL AND expiration < ?"
params := []interface{}{time.Now().Format("2006-01-02 03:04:05")}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cbox/utils/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func FormatUserID(u *userpb.UserId) string {

// ExtractUserID retrieves a CS3API user ID from a string
func ExtractUserID(u string) *userpb.UserId {
parts := strings.Split(u, ":")
parts := strings.SplitN(u, ":", 2)
if len(parts) > 1 {
return &userpb.UserId{OpaqueId: parts[0], Idp: parts[1]}
}
Expand All @@ -186,7 +186,7 @@ func FormatGroupID(u *grouppb.GroupId) string {

// ExtractGroupID retrieves a CS3API group ID from a string
func ExtractGroupID(u string) *grouppb.GroupId {
parts := strings.Split(u, ":")
parts := strings.SplitN(u, ":", 2)
if len(parts) > 1 {
return &grouppb.GroupId{OpaqueId: parts[0], Idp: parts[1]}
}
Expand Down
37 changes: 24 additions & 13 deletions pkg/publicshare/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ func New(c map[string]interface{}) (publicshare.Manager, error) {
conf.init()

m := manager{
mutex: &sync.Mutex{},
marshaler: jsonpb.Marshaler{},
unmarshaler: jsonpb.Unmarshaler{},
file: conf.File,
passwordHashCost: conf.SharePasswordHashCost,
janitorRunInterval: conf.JanitorRunInterval,
mutex: &sync.Mutex{},
marshaler: jsonpb.Marshaler{},
unmarshaler: jsonpb.Unmarshaler{},
file: conf.File,
passwordHashCost: conf.SharePasswordHashCost,
janitorRunInterval: conf.JanitorRunInterval,
enableExpiredSharesCleanup: conf.EnableExpiredSharesCleanup,
}

// attempt to create the db file
Expand Down Expand Up @@ -97,9 +98,10 @@ func New(c map[string]interface{}) (publicshare.Manager, error) {
}

type config struct {
File string `mapstructure:"file"`
SharePasswordHashCost int `mapstructure:"password_hash_cost"`
JanitorRunInterval int `mapstructure:"janitor_run_interval"`
File string `mapstructure:"file"`
SharePasswordHashCost int `mapstructure:"password_hash_cost"`
JanitorRunInterval int `mapstructure:"janitor_run_interval"`
EnableExpiredSharesCleanup bool `mapstructure:"enable_expired_shares_cleanup"`
}

func (c *config) init() {
Expand All @@ -118,13 +120,18 @@ type manager struct {
mutex *sync.Mutex
file string

marshaler jsonpb.Marshaler
unmarshaler jsonpb.Unmarshaler
passwordHashCost int
janitorRunInterval int
marshaler jsonpb.Marshaler
unmarshaler jsonpb.Unmarshaler
passwordHashCost int
janitorRunInterval int
enableExpiredSharesCleanup bool
}

func (m *manager) startJanitorRun() {
if !m.enableExpiredSharesCleanup {
return
}

ticker := time.NewTicker(time.Duration(m.janitorRunInterval) * time.Second)
work := make(chan os.Signal, 1)
signal.Notify(work, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT)
Expand Down Expand Up @@ -414,6 +421,10 @@ func (m *manager) cleanupExpiredShares() {
}

func (m *manager) revokeExpiredPublicShare(ctx context.Context, s *link.PublicShare, u *user.User) error {
if !m.enableExpiredSharesCleanup {
return nil
}

m.mutex.Unlock()
defer m.mutex.Lock()

Expand Down
Loading