Skip to content

Commit

Permalink
delete user home directory when deleting user
Browse files Browse the repository at this point in the history
Signed-off-by: David Christofas <[email protected]>
  • Loading branch information
David Christofas committed Oct 26, 2020
1 parent 7352ee4 commit 1bdde93
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/delete-user-home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Delete user home directory

Extended the delete user method to also delete the user home folder on top of deleting the user in the accounts service.

https://github.com/owncloud/ocis/pull/755
1 change: 0 additions & 1 deletion ocis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crewjam/httperr v0.0.0-20190612203328-a946449404da h1:WXnT88cFG2davqSFqvaFfzkSMC0lqh/8/rKZ+z7tYvI=
github.com/crewjam/httperr v0.0.0-20190612203328-a946449404da/go.mod h1:+rmNIXRvYMqLQeR4DHyTvs6y0MEMymTz4vyFpFkKTPs=
github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo=
github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4=
Expand Down
3 changes: 3 additions & 0 deletions ocs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
contrib.go.opencensus.io/exporter/ocagent v0.7.0
contrib.go.opencensus.io/exporter/zipkin v0.1.1
github.com/UnnoTed/fileb0x v1.1.4
github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d
github.com/cs3org/reva v1.3.1-0.20201021065855-dc400f81ecbc
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/render v1.0.1
Expand All @@ -20,12 +21,14 @@ require (
github.com/owncloud/ocis/ocis-pkg v0.0.0-20200918114005-1a0ddd2190ee
github.com/owncloud/ocis/settings v0.0.0-20200918114005-1a0ddd2190ee
github.com/owncloud/ocis/store v0.0.0-20200918125107-fcca9faa81c8
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1
github.com/restic/calens v0.2.0
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.1
go.opencensus.io v0.22.5
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0
)

Expand Down
5 changes: 5 additions & 0 deletions ocs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd h1:uMaudkC7znaiI
github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666 h1:E7VsSSN/2YZLSwrDMJJdAWU11lP7W1qkcXbrslb0PM0=
github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d h1:YDnGz3eTIYQDXzJd/zefEsl0qbz/P63e8KWjSjYlb5Q=
github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva v0.0.2-0.20200115110931-4c7513415ec5/go.mod h1:Hk3eCcdhtv4eIhKvRK736fQuOyS1HuHnUcz0Dq6NK1A=
github.com/cs3org/reva v0.1.0 h1:PYzDejKm/+xG3OTS2WgzBxcksVogEGmPgjJVegwSR2c=
Expand Down Expand Up @@ -699,6 +700,7 @@ github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
Expand Down Expand Up @@ -845,6 +847,7 @@ github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U=
github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
Expand Down Expand Up @@ -1605,6 +1608,7 @@ go.opencensus.io v0.22.3 h1:8sGtKOrtQqkN1bp2AtX+misvLIlOmsEsNd+9NIcPEm8=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down Expand Up @@ -1894,6 +1898,7 @@ golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
23 changes: 23 additions & 0 deletions ocs/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package command

import (
"context"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/token/manager/jwt"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -138,10 +140,31 @@ func Server(cfg *config.Config) *cli.Command {
metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1)

{
tm, err := jwt.New(map[string]interface{}{
"secret": cfg.TokenManager.JWTSecret,
"expires": int64(60),
})
if err != nil {
logger.Error().
Err(err).
Msg("could not create token manager")
return err
}

gwc, err := pool.GetGatewayServiceClient(cfg.RevaGateway.Address)
if err != nil {
logger.Error().
Err(err).
Msg("could not create reva gateway client")
return err
}

server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(cfg),
http.TokenManager(tm),
http.RevaClient(gwc),
http.Metrics(metrics),
http.Flags(flagset.RootWithConfig(config.New())),
http.Flags(flagset.ServerWithConfig(config.New())),
Expand Down
6 changes: 6 additions & 0 deletions ocs/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type TokenManager struct {
JWTSecret string
}

// RevaGateway is the config for using the reva token manager
type RevaGateway struct {
Address string
}

// Config combines all available configuration parts.
type Config struct {
File string
Expand All @@ -51,6 +56,7 @@ type Config struct {
Tracing Tracing
TokenManager TokenManager
Service Service
RevaGateway RevaGateway
}

// New initializes a new configuration with or without defaults.
Expand Down
7 changes: 7 additions & 0 deletions ocs/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"OCS_JWT_SECRET"},
Destination: &cfg.TokenManager.JWTSecret,
},
&cli.StringFlag{
Name: "reva-gateway-addr",
Value: "127.0.0.1:9142",
Usage: "REVA Gateway Endpoint",
EnvVars: []string{"OCS_REVA_GATEWAY_ADDR"},
Destination: &cfg.RevaGateway.Address,
},
}
}

Expand Down
20 changes: 19 additions & 1 deletion ocs/pkg/server/http/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package http

import (
"context"
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/pkg/token"

"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/metrics"
"github.com/owncloud/ocis/ocis-pkg/log"
)

// Option defines a single option function.
Expand All @@ -20,6 +22,8 @@ type Options struct {
Config *config.Config
Metrics *metrics.Metrics
Flags []cli.Flag
TokenManager token.Manager
RevaClient gatewayv1beta1.GatewayAPIClient
}

// newOptions initializes the available default options.
Expand Down Expand Up @@ -74,3 +78,17 @@ func Namespace(val string) Option {
o.Namespace = val
}
}

// TokenManager provides a function to set the TokenManager option.
func TokenManager(tm token.Manager) Option {
return func(o *Options) {
o.TokenManager = tm
}
}

// RevaClient provides a function to set the RevaClient option.
func RevaClient(c gatewayv1beta1.GatewayAPIClient) Option {
return func(o *Options) {
o.RevaClient = c
}
}
2 changes: 2 additions & 0 deletions ocs/pkg/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func Server(opts ...Option) (http.Service, error) {
handle := svc.NewService(
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.TokenManager(options.TokenManager),
svc.RevaClient(options.RevaClient),
svc.Middleware(
middleware.RealIP,
middleware.RequestID,
Expand Down
37 changes: 37 additions & 0 deletions ocs/pkg/server/http/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
ggrpc "google.golang.org/grpc"
"github.com/cs3org/reva/pkg/token/manager/jwt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -467,6 +471,29 @@ func sendRequest(method, endpoint, body, auth string) (*httptest.ResponseRecorde

return rr, nil
}
type mockRevaClient struct {
gatewayv1beta1.GatewayAPIClient
}

func(c mockRevaClient) GetHome(ctx context.Context, req *providerv1beta1.GetHomeRequest, options ...ggrpc.CallOption) (*providerv1beta1.GetHomeResponse, error){
return &providerv1beta1.GetHomeResponse{
Path: "/home",
}, nil
}

func(c mockRevaClient) Stat(ctx context.Context, req *providerv1beta1.StatRequest, options ...ggrpc.CallOption) (*providerv1beta1.StatResponse, error){
return &providerv1beta1.StatResponse{
Info: &providerv1beta1.ResourceInfo{Id: &providerv1beta1.ResourceId{
OpaqueId: "",
StorageId: "",
},
},
}, nil
}

func (o mockRevaClient) Delete(ctx context.Context, req * providerv1beta1.DeleteRequest, options ...ggrpc.CallOption) (*providerv1beta1.DeleteResponse, error) {
return nil, nil
}

func getService() svc.Service {
c := &config.Config{
Expand All @@ -484,9 +511,19 @@ func getService() svc.Service {

var logger ocisLog.Logger

tm, _ := jwt.New(map[string]interface{}{
"secret": c.TokenManager.JWTSecret,
"expires": int64(60),
})




return svc.NewService(
svc.Logger(logger),
svc.Config(c),
svc.TokenManager(tm),
svc.RevaClient(mockRevaClient{}),
)
}

Expand Down
18 changes: 18 additions & 0 deletions ocs/pkg/service/v0/option.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package svc

import (
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/pkg/token"
"net/http"

"github.com/owncloud/ocis/ocs/pkg/config"
Expand All @@ -15,6 +17,8 @@ type Options struct {
Logger log.Logger
Config *config.Config
Middleware []func(http.Handler) http.Handler
TokenManager token.Manager
RevaClient gatewayv1beta1.GatewayAPIClient
}

// newOptions initializes the available default options.
Expand Down Expand Up @@ -48,3 +52,17 @@ func Middleware(val ...func(http.Handler) http.Handler) Option {
o.Middleware = val
}
}

// TokenManager provides a function to set the TokenManager option.
func TokenManager(tm token.Manager) Option {
return func(o *Options) {
o.TokenManager = tm
}
}

// RevaClient provides a function to set the RevaClient option.
func RevaClient(c gatewayv1beta1.GatewayAPIClient) Option {
return func(o *Options) {
o.RevaClient = c
}
}
8 changes: 7 additions & 1 deletion ocs/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package svc

import (
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/pkg/token"
"net/http"

"github.com/go-chi/chi"
Expand All @@ -9,11 +11,11 @@ import (
"github.com/micro/go-micro/v2/client/grpc"

accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocs/pkg/config"
ocsm "github.com/owncloud/ocis/ocs/pkg/middleware"
"github.com/owncloud/ocis/ocs/pkg/service/v0/data"
"github.com/owncloud/ocis/ocs/pkg/service/v0/response"
"github.com/owncloud/ocis/ocis-pkg/log"
)

var defaultClient = grpc.NewClient()
Expand All @@ -35,6 +37,8 @@ func NewService(opts ...Option) Service {
config: options.Config,
mux: m,
logger: options.Logger,
tokenManager: options.TokenManager,
revaClient: options.RevaClient,
}

m.Route(options.Config.HTTP.Root, func(r chi.Router) {
Expand Down Expand Up @@ -89,6 +93,8 @@ type Ocs struct {
config *config.Config
logger log.Logger
mux *chi.Mux
tokenManager token.Manager
revaClient gatewayv1beta1.GatewayAPIClient
}

// ServeHTTP implements the Service interface.
Expand Down
Loading

0 comments on commit 1bdde93

Please sign in to comment.