Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Add post create home hook for eos storage driver (cs3org#3234)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored and vascoguita committed Oct 20, 2022
1 parent ff1dee3 commit e1297a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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
6 changes: 6 additions & 0 deletions pkg/storage/utils/eosfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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"`
}
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 @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit e1297a4

Please sign in to comment.