Skip to content

Commit d3619d0

Browse files
authored
Merge pull request #10712 from aduffeck/cleanup-stale-shares
Cleanup stale shares
2 parents 92e6a9e + a925d09 commit d3619d0

File tree

32 files changed

+597
-60
lines changed

32 files changed

+597
-60
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/cenkalti/backoff v2.2.1+incompatible
1818
github.com/coreos/go-oidc/v3 v3.11.0
1919
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1
20-
github.com/cs3org/reva/v2 v2.26.7
20+
github.com/cs3org/reva/v2 v2.26.8-0.20241203081301-17f339546533
2121
github.com/davidbyttow/govips/v2 v2.15.0
2222
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
2323
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1 h1:RU6LT6mkD16xZ
257257
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1/go.mod h1:DedpcqXl193qF/08Y04IO0PpxyyMu8+GrkD6kWK2MEQ=
258258
github.com/cs3org/reva/v2 v2.26.7 h1:E5b1+H5ZsnmDgWWS/u3t4PtdmiMaY1bEEYVI/vE9xo8=
259259
github.com/cs3org/reva/v2 v2.26.7/go.mod h1:xC5N2XOrCRim/W55uyMsew8RwwFZbQ4hIaKshIbyToo=
260+
github.com/cs3org/reva/v2 v2.26.8-0.20241203081301-17f339546533 h1:QshDjljk44ASolJwlHxE9e7u+Slgdi/VfPKYvbfFu2g=
261+
github.com/cs3org/reva/v2 v2.26.8-0.20241203081301-17f339546533/go.mod h1:fJWmn7EkttWOWphZfiKdFOcHuthcUsU55aSN1VeTOhU=
260262
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
261263
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
262264
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=

ocis/pkg/command/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func revaShareConfig(cfg *sharing.Config) map[string]interface{} {
519519
"machine_auth_apikey": cfg.UserSharingDrivers.CS3.SystemUserAPIKey,
520520
},
521521
"jsoncs3": map[string]interface{}{
522-
"gateway_addr": cfg.UserSharingDrivers.JSONCS3.ProviderAddr,
522+
"gateway_addr": cfg.Reva.Address,
523523
"provider_addr": cfg.UserSharingDrivers.JSONCS3.ProviderAddr,
524524
"service_user_id": cfg.UserSharingDrivers.JSONCS3.SystemUserID,
525525
"service_user_idp": cfg.UserSharingDrivers.JSONCS3.SystemUserIDP,

ocis/pkg/command/shares.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package command
2+
3+
import (
4+
"errors"
5+
6+
"github.com/rs/zerolog"
7+
"github.com/urfave/cli/v2"
8+
9+
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
10+
"github.com/cs3org/reva/v2/pkg/share/manager/jsoncs3"
11+
"github.com/cs3org/reva/v2/pkg/share/manager/registry"
12+
"github.com/cs3org/reva/v2/pkg/utils"
13+
14+
"github.com/owncloud/ocis/v2/ocis-pkg/config"
15+
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
16+
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
17+
mregistry "github.com/owncloud/ocis/v2/ocis-pkg/registry"
18+
"github.com/owncloud/ocis/v2/ocis/pkg/register"
19+
sharingparser "github.com/owncloud/ocis/v2/services/sharing/pkg/config/parser"
20+
)
21+
22+
// SharesCommand is the entrypoint for the groups command.
23+
func SharesCommand(cfg *config.Config) *cli.Command {
24+
return &cli.Command{
25+
Name: "shares",
26+
Usage: `cli tools to manage entries in the share manager.`,
27+
Category: "maintenance",
28+
Before: func(c *cli.Context) error {
29+
// Parse base config
30+
if err := parser.ParseConfig(cfg, true); err != nil {
31+
return configlog.ReturnError(err)
32+
}
33+
34+
// Parse sharing config
35+
cfg.Sharing.Commons = cfg.Commons
36+
return configlog.ReturnError(sharingparser.ParseConfig(cfg.Sharing))
37+
},
38+
Subcommands: []*cli.Command{
39+
cleanupCmd(cfg),
40+
},
41+
}
42+
}
43+
44+
func init() {
45+
register.AddCommand(SharesCommand)
46+
}
47+
48+
func cleanupCmd(cfg *config.Config) *cli.Command {
49+
return &cli.Command{
50+
Name: "cleanup",
51+
Usage: `clean up stale entries in the share manager.`,
52+
Flags: []cli.Flag{
53+
&cli.StringFlag{
54+
Name: "service-account-id",
55+
Value: "",
56+
Usage: "Name of the service account to use for the cleanup",
57+
EnvVars: []string{"OCIS_SERVICE_ACCOUNT_ID"},
58+
Required: true,
59+
},
60+
&cli.StringFlag{
61+
Name: "service-account-secret",
62+
Value: "",
63+
Usage: "Secret for the service account",
64+
EnvVars: []string{"OCIS_SERVICE_ACCOUNT_SECRET"},
65+
Required: true,
66+
},
67+
},
68+
Before: func(c *cli.Context) error {
69+
// Parse base config
70+
if err := parser.ParseConfig(cfg, true); err != nil {
71+
return configlog.ReturnError(err)
72+
}
73+
74+
// Parse sharing config
75+
cfg.Sharing.Commons = cfg.Commons
76+
return configlog.ReturnError(sharingparser.ParseConfig(cfg.Sharing))
77+
},
78+
Action: func(c *cli.Context) error {
79+
return cleanup(c, cfg)
80+
},
81+
}
82+
}
83+
84+
func cleanup(c *cli.Context, cfg *config.Config) error {
85+
driver := cfg.Sharing.UserSharingDriver
86+
// cleanup is only implemented for the jsoncs3 share manager
87+
if driver != "jsoncs3" {
88+
return configlog.ReturnError(errors.New("cleanup is only implemented for the jsoncs3 share manager"))
89+
}
90+
91+
rcfg := revaShareConfig(cfg.Sharing)
92+
f, ok := registry.NewFuncs[driver]
93+
if !ok {
94+
return configlog.ReturnError(errors.New("Unknown share manager type '" + driver + "'"))
95+
}
96+
mgr, err := f(rcfg[driver].(map[string]interface{}))
97+
if err != nil {
98+
return configlog.ReturnError(err)
99+
}
100+
101+
// Initialize registry to make service lookup work
102+
_ = mregistry.GetRegistry()
103+
104+
// get an authenticated context
105+
gatewaySelector, err := pool.GatewaySelector(cfg.Sharing.Reva.Address)
106+
if err != nil {
107+
return configlog.ReturnError(err)
108+
}
109+
110+
client, err := gatewaySelector.Next()
111+
if err != nil {
112+
return configlog.ReturnError(err)
113+
}
114+
115+
serviceUserCtx, err := utils.GetServiceUserContext(c.String("service-account-id"), client, c.String("service-account-secret"))
116+
if err != nil {
117+
return configlog.ReturnError(err)
118+
}
119+
120+
l := logger()
121+
122+
zerolog.SetGlobalLevel(zerolog.InfoLevel)
123+
serviceUserCtx = l.WithContext(serviceUserCtx)
124+
125+
mgr.(*jsoncs3.Manager).CleanupStaleShares(serviceUserCtx)
126+
127+
return nil
128+
}

vendor/github.com/cs3org/reva/v2/internal/grpc/services/usershareprovider/usershareprovider.go

Lines changed: 37 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/proppatch.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)