From 9c1f5884f0457844feef46c7f9c20e041c58cd8a Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte <39946305+gmgigi96@users.noreply.github.com> Date: Fri, 14 Oct 2022 16:18:13 +0200 Subject: [PATCH] Add post create home hook for eos storage driver (#3234) --- changelog/unreleased/post-create-home-hook-eos.md | 3 +++ pkg/storage/utils/eosfs/config.go | 6 ++++++ pkg/storage/utils/eosfs/eosfs.go | 14 +++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/post-create-home-hook-eos.md diff --git a/changelog/unreleased/post-create-home-hook-eos.md b/changelog/unreleased/post-create-home-hook-eos.md new file mode 100644 index 00000000000..433a83d1310 --- /dev/null +++ b/changelog/unreleased/post-create-home-hook-eos.md @@ -0,0 +1,3 @@ +Enhancement: Add post create home hook for eos storage driver + +https://github.com/cs3org/reva/pull/3234 diff --git a/pkg/storage/utils/eosfs/config.go b/pkg/storage/utils/eosfs/config.go index 5b6838e6967..aac127c74cd 100644 --- a/pkg/storage/utils/eosfs/config.go +++ b/pkg/storage/utils/eosfs/config.go @@ -144,6 +144,9 @@ type Config struct { // revisions-related operations. ImpersonateOwnerforRevisions bool `mapstructure:"impersonate_owner_for_revisions"` + // Whether to enable the post create home hook + EnablePostCreateHomeHook bool `mapstructure:"enable_post_create_home_hook"` + // HTTP connections to EOS: max number of idle conns MaxIdleConns int `mapstructure:"max_idle_conns"` @@ -168,4 +171,7 @@ type Config struct { // TokenExpiry stores in seconds the time after which generated tokens will expire // Default is 3600 TokenExpiry int + + // Path of the script to run after an user home folder has been created + OnPostCreateHomeHook string `mapstructure:"on_post_create_home_hook"` } diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 64f8981b25d..cb0fadc5fe2 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -25,6 +25,7 @@ import ( "io" "net/url" "os" + "os/exec" "path" "regexp" "strconv" @@ -1480,7 +1481,13 @@ func (fs *eosfs) createNominalHome(ctx context.Context) error { return err } - return err + if fs.conf.EnablePostCreateHomeHook { + if err := fs.runPostCreateHomeHook(ctx); err != nil { + return errors.Wrap(err, "eosfs: error running post create home hook") + } + } + + return nil } func (fs *eosfs) CreateHome(ctx context.Context) error { @@ -1499,6 +1506,11 @@ func (fs *eosfs) CreateHome(ctx context.Context) error { return nil } +func (fs *eosfs) runPostCreateHomeHook(ctx context.Context) error { + user := ctxpkg.ContextMustGetUser(ctx) + return exec.Command(fs.conf.OnPostCreateHomeHook, user.Username).Run() +} + func (fs *eosfs) createUserDir(ctx context.Context, u *userpb.User, path string, recursiveAttr bool) error { rootAuth, err := fs.getRootAuth(ctx) if err != nil {