Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post create home hook for eos storage driver #3234

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/post-create-home-hook-eos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add post create home hook for eos storage driver

https://github.com/cs3org/reva/pull/3234
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