From c01a4d7d1054127a8d02174de11d1e9ca681e880 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Tue, 13 Sep 2022 17:00:15 +0200 Subject: [PATCH] add possibility to define a script to run after an home folder has been created --- pkg/storage/utils/eosfs/config.go | 5 +++++ pkg/storage/utils/eosfs/eosfs.go | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/storage/utils/eosfs/config.go b/pkg/storage/utils/eosfs/config.go index 5b6838e696..6dc6270ab7 100644 --- a/pkg/storage/utils/eosfs/config.go +++ b/pkg/storage/utils/eosfs/config.go @@ -168,4 +168,9 @@ 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"` + // Whether to enable the post create home hook + EnablePostCreateHomeHook bool `mapstructure:"enable_post_create_home_hook"` } diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 197bbcf1da..263d154084 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" @@ -1478,7 +1479,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 { @@ -1497,6 +1504,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 {