Skip to content

Commit

Permalink
add possibility to define a script to run after an home folder has be…
Browse files Browse the repository at this point in the history
…en created
  • Loading branch information
gmgigi96 committed Sep 13, 2022
1 parent 10caf12 commit c01a4d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/storage/utils/eosfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
14 changes: 13 additions & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io"
"net/url"
"os"
"os/exec"
"path"
"regexp"
"strconv"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit c01a4d7

Please sign in to comment.