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

Public Shares CRUD, File Public Shares Manager #681

Merged
merged 50 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c3e9ef4
set permissions from phoenix
refs Apr 20, 2020
7ac248a
CRUD operations on public shares
refs Apr 23, 2020
41676b3
WIP persistent shares storage
refs Apr 23, 2020
bee35ad
json public share manager
refs Apr 23, 2020
5f8a0df
fix filter, add locally scoped var
refs Apr 23, 2020
a7bb4e6
liberate mutex on defer
refs Apr 24, 2020
9b6cc77
correct time parsing on creation
refs Apr 24, 2020
b7499d5
hide expired public shares
refs Apr 24, 2020
613e636
use correct timestamp on create and update
refs Apr 24, 2020
9cdada6
add comment for future generations
refs Apr 24, 2020
c1cb793
get shares by token working
refs Apr 27, 2020
bb642fa
defer mutex unlock, refactor GetShare
refs Apr 27, 2020
2ad8bf1
use mutex on get public share
refs Apr 27, 2020
8503ee3
code style
refs Apr 27, 2020
6e53187
Merge branch 'master' into public-shares
refs Apr 27, 2020
ac9ab44
address linter
refs Apr 27, 2020
6c84f2a
navigation working
refs Apr 28, 2020
6c118b2
folder navigation on a public share is now supported
refs Apr 28, 2020
a8fe9ee
remove spurious lines
refs Apr 29, 2020
da5a7d2
attempt to create db file if not exists
refs Apr 29, 2020
b160fcd
base64 encode password
refs Apr 29, 2020
52c9d2d
in memory grant manager as a proof of concept
refs May 8, 2020
20dfb8b
remove spurious code
refs May 8, 2020
8bfcc03
make use of err, get rid of ineffectual assignment
refs May 12, 2020
2baa43e
run go mod tidy
refs May 12, 2020
8159d06
Merge branch 'master' into public-shares
refs May 12, 2020
e46fb64
update golangci to 1.26.0
refs May 13, 2020
ef3549a
update golangci-lint counterpart on Makefile
refs May 13, 2020
e071712
force cache invalidation for golangci-lint
refs May 13, 2020
d918fa7
add user to request context, handlePropfind depends on the context user
refs May 14, 2020
9729151
use [public] share manager driver instead of the gateway, as it is an…
refs May 14, 2020
40ab8cb
update golangci-lint on build-onlly and build-and-publish-docker pipe…
refs May 14, 2020
575fee7
ignore jsonpb on golangci.yaml
refs May 14, 2020
4cff37e
get rid of metadata-password-passing hack
refs May 19, 2020
5a0a73a
remove comments
refs May 19, 2020
a7746f0
Merge branch 'master' into public-shares
refs May 19, 2020
9b6adc7
use a db file for link.Grant
refs May 26, 2020
455e6da
fix linter
refs May 26, 2020
58e0b25
Merge branch 'master' into public-shares
refs May 26, 2020
21dbf29
fix propfind stack
refs May 27, 2020
a07b579
defer usage of ref
refs May 27, 2020
39f3fc5
Fix PROPFIND with Depth 1
May 27, 2020
7fd06cf
Merge pull request #1 from PVince81/public-shares
refs May 27, 2020
72fba4b
Merge branch 'master' into public-shares
refs May 28, 2020
68c1932
publicshare: commit grant
labkode May 28, 2020
f395902
Merge pull request #2 from labkode/refs-hugo
refs May 28, 2020
df39963
adapt db json file marshal / unmarshal
refs May 28, 2020
d6eaa1c
remove deadcode
refs May 28, 2020
91bf637
remove yet more dead code
refs May 28, 2020
e42564b
remove unused config parameter
refs May 28, 2020
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: 4 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ steps:
- make ci

- name: lint
image: golangci/golangci-lint:v1.21.0
image: golangci/golangci-lint:latest
commands:
- golangci-lint run

Expand Down Expand Up @@ -118,7 +118,7 @@ steps:
- make ci

- name: lint
image: golangci/golangci-lint:v1.21.0
image: golangci/golangci-lint:latest
commands:
- golangci-lint run

Expand Down Expand Up @@ -162,7 +162,8 @@ steps:
- make ci

- name: lint
image: golangci/golangci-lint:v1.21.0
# will slow down build slightly. In order to get jsonpb deprecation.
image: golangci/golangci-lint:latest
commands:
- golangci-lint run

Expand Down
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ issues:
text: "SA1019:"
linters:
- staticcheck
- path: pkg/publicshare/manager/json/json.go
text: "SA1019:"
linters:
- staticcheck
linters:
enable:
- bodyclose
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contrib:

# for manual building only
deps:
cd /tmp && rm -rf golangci-lint && git clone --quiet -b 'v1.24.0' --single-branch --depth 1 https://github.com/golangci/golangci-lint &> /dev/null && cd golangci-lint/cmd/golangci-lint && go install
cd /tmp && rm -rf golangci-lint && git clone --quiet -b 'v1.26.0' --single-branch --depth 1 https://github.com/golangci/golangci-lint &> /dev/null && cd golangci-lint/cmd/golangci-lint && go install
cd /tmp && go get golang.org/x/tools/cmd/goimports

build-ci: off
Expand Down
19 changes: 13 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ require (
github.com/huandu/xstrings v1.3.0 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.3.0
github.com/mitchellh/mapstructure v1.2.2
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/ory/fosite v0.31.0
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v0.9.3 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.18.0
github.com/tus/tusd v1.1.1-0.20200416115059-9deabf9d80c2
go.opencensus.io v0.22.3
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/grpc v1.29.1
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e // indirect
google.golang.org/grpc v1.29.0
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.27 // indirect
gopkg.in/ldap.v2 v2.5.1
gopkg.in/square/go-jose.v2 v2.2.2 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

go 1.13
Expand Down
65 changes: 43 additions & 22 deletions go.sum

Large diffs are not rendered by default.

51 changes: 38 additions & 13 deletions internal/grpc/services/gateway/publicshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package gateway

import (
"context"
"fmt"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
Expand All @@ -29,6 +30,11 @@ import (
"github.com/pkg/errors"
)

var (
// maps public share tokens to its grants.
grants = map[string]*link.Grant{}
)

func (s *svc) CreatePublicShare(ctx context.Context, req *link.CreatePublicShareRequest) (*link.CreatePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("create public share")
Expand All @@ -43,7 +49,9 @@ func (s *svc) CreatePublicShare(ctx context.Context, req *link.CreatePublicShare
return nil, err
}

// TODO(refs) commit to storage if configured
// WIP store the grant in memory, as a proof of concept.
grants[res.Share.Token] = req.Grant

return res, nil
}

Expand All @@ -60,17 +68,23 @@ func (s *svc) GetPublicShareByToken(ctx context.Context, req *link.GetPublicShar
log := appctx.GetLogger(ctx)
log.Info().Msg("get public share by token")

pClient, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
driver, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
if err != nil {
log.Err(err).Msg("error connecting to a public share provider")
return &link.GetPublicShareByTokenResponse{
Status: &rpc.Status{
Code: rpc.Code_CODE_INTERNAL,
},
}, nil
return nil, err
}

// TODO(refs) once https://github.com/cs3org/cs3apis/pull/73 is merged, password will be present in the request, not on the opaque field.
pass := string(req.Opaque.GetMap()["password"].GetValue())
res, err := driver.GetPublicShareByToken(ctx, req)
if err != nil {
return nil, err
}

return pClient.GetPublicShareByToken(ctx, req)
if res.Share.PasswordProtected && (grants[req.Token].Password != pass) {
return nil, fmt.Errorf("public share password missmatch")
}

return res, nil
}

func (s *svc) GetPublicShare(ctx context.Context, req *link.GetPublicShareRequest) (*link.GetPublicShareResponse, error) {
Expand Down Expand Up @@ -106,18 +120,29 @@ func (s *svc) ListPublicShares(ctx context.Context, req *link.ListPublicSharesRe

res, err := pClient.ListPublicShares(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "error calling ListShares")
return nil, errors.Wrap(err, "error listing shares")
}

return res, nil
}

func (s *svc) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicShareRequest) (*link.UpdatePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("list public share")
log.Info().Msg("update public share")

res := &link.UpdatePublicShareResponse{
Status: status.NewOK(ctx),
pClient, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
if err != nil {
log.Err(err).Msg("error connecting to a public share provider")
return &link.UpdatePublicShareResponse{
Status: &rpc.Status{
Code: rpc.Code_CODE_INTERNAL,
},
}, nil
}

res, err := pClient.UpdatePublicShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "error updating share")
}
return res, nil
}
26 changes: 23 additions & 3 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,30 @@ func (s *svc) initiateFileUpload(ctx context.Context, req *provider.InitiateFile
}

func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) {
res := &provider.GetPathResponse{
Status: status.NewUnimplemented(ctx, nil, "GetPath not yet implemented"),
ref := &provider.Reference{
Spec: &provider.Reference_Id{
Id: req.ResourceId,
},
}
return res, nil

statReq := &provider.StatRequest{
Ref: ref,
}
res, err := s.stat(ctx, statReq)
if err != nil {
err = errors.Wrap(err, "gateway: error stating ref:"+ref.String())
return nil, err
}

if res.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(res.Status.Code, "gateway")
return nil, err
}

return &provider.GetPathResponse{
Status: res.Status,
Path: res.GetInfo().GetPath(),
}, nil
}

func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {

func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicShareRequest) (*link.CreatePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("create public share")
log.Info().Str("publicshareprovider", "create").Msg("create public share")

u, ok := user.ContextGetUser(ctx)
if !ok {
Expand All @@ -121,7 +121,7 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS

func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicShareRequest) (*link.RemovePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("remove public share")
log.Info().Str("publicshareprovider", "remove").Msg("remove public share")

return &link.RemovePublicShareResponse{
Status: status.NewOK(ctx),
Expand All @@ -145,17 +145,27 @@ func (s *service) GetPublicShareByToken(ctx context.Context, req *link.GetPublic

func (s *service) GetPublicShare(ctx context.Context, req *link.GetPublicShareRequest) (*link.GetPublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("get public share")
log.Info().Str("publicshareprovider", "get").Msg("get public share")

u, ok := user.ContextGetUser(ctx)
if !ok {
log.Error().Msg("error getting user from context")
}

found, err := s.sm.GetPublicShare(ctx, u, req.Ref)
if err != nil {
return nil, err
}

return &link.GetPublicShareResponse{
Status: status.NewOK(ctx),
// Share: share,
Share: found,
}, nil
}

func (s *service) ListPublicShares(ctx context.Context, req *link.ListPublicSharesRequest) (*link.ListPublicSharesResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("list public share")
log.Info().Str("publicshareprovider", "list").Msg("list public share")
user, _ := user.ContextGetUser(ctx)

shares, err := s.sm.ListPublicShares(ctx, user, req.Filters, &provider.ResourceInfo{})
Expand All @@ -175,10 +185,21 @@ func (s *service) ListPublicShares(ctx context.Context, req *link.ListPublicShar

func (s *service) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicShareRequest) (*link.UpdatePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("list public share")
log.Info().Str("publicshareprovider", "update").Msg("update public share")

u, ok := user.ContextGetUser(ctx)
if !ok {
log.Error().Msg("error getting user from context")
}

updateR, err := s.sm.UpdatePublicShare(ctx, u, req, nil)
if err != nil {
log.Err(err).Msgf("error updating public shares: %v", err)
}

res := &link.UpdatePublicShareResponse{
Status: status.NewOK(ctx),
Share: updateR,
}
return res, nil
}
Loading