mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-24 00:20:25 +00:00
remove some useless hooks
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
eeef23139d
commit
126cb1ee0d
9 changed files with 9 additions and 139 deletions
|
@ -70,7 +70,6 @@ var (
|
|||
// eventManager handle the supported event rules actions
|
||||
eventManager eventRulesContainer
|
||||
multipartQuoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
||||
loadBuiltinRulesFn func() []dataprovider.EventRule
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -279,9 +278,6 @@ func (r *eventRulesContainer) loadRules() {
|
|||
eventManagerLog(logger.LevelError, "unable to load event rules: %v", err)
|
||||
return
|
||||
}
|
||||
if loadBuiltinRulesFn != nil {
|
||||
rules = append(rules, loadBuiltinRulesFn()...)
|
||||
}
|
||||
eventManagerLog(logger.LevelDebug, "recently updated event rules loaded: %d", len(rules))
|
||||
|
||||
if len(rules) > 0 {
|
||||
|
@ -2792,20 +2788,9 @@ func (j *eventCronJob) getTask(rule *dataprovider.EventRule) (dataprovider.Task,
|
|||
return dataprovider.Task{}, nil
|
||||
}
|
||||
|
||||
func (j *eventCronJob) getEventRule() (dataprovider.EventRule, error) {
|
||||
if loadBuiltinRulesFn != nil {
|
||||
for _, rule := range loadBuiltinRulesFn() {
|
||||
if rule.Name == j.ruleName {
|
||||
return rule, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataprovider.EventRuleExists(j.ruleName)
|
||||
}
|
||||
|
||||
func (j *eventCronJob) Run() {
|
||||
eventManagerLog(logger.LevelDebug, "executing scheduled rule %q", j.ruleName)
|
||||
rule, err := j.getEventRule()
|
||||
rule, err := dataprovider.EventRuleExists(j.ruleName)
|
||||
if err != nil {
|
||||
eventManagerLog(logger.LevelError, "unable to load rule with name %q", j.ruleName)
|
||||
return
|
||||
|
|
|
@ -800,75 +800,6 @@ func TestEventManagerErrors(t *testing.T) {
|
|||
stopEventScheduler()
|
||||
}
|
||||
|
||||
func TestBuiltinRules(t *testing.T) {
|
||||
startEventScheduler()
|
||||
rule1 := util.GenerateUniqueID()
|
||||
loadBuiltinRulesFn = func() []dataprovider.EventRule {
|
||||
return []dataprovider.EventRule{
|
||||
{
|
||||
Name: rule1,
|
||||
Status: 1,
|
||||
CreatedAt: util.GetTimeAsMsSinceEpoch(time.Now()),
|
||||
UpdatedAt: util.GetTimeAsMsSinceEpoch(time.Now()),
|
||||
Trigger: dataprovider.EventTriggerSchedule,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
Schedules: []dataprovider.Schedule{
|
||||
{
|
||||
Hours: "0",
|
||||
DayOfWeek: "*",
|
||||
DayOfMonth: "*",
|
||||
Month: "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Actions: []dataprovider.EventAction{
|
||||
{
|
||||
BaseEventAction: dataprovider.BaseEventAction{
|
||||
Name: "backup",
|
||||
Type: dataprovider.ActionTypeBackup,
|
||||
Options: dataprovider.BaseEventActionOptions{},
|
||||
},
|
||||
Order: 1,
|
||||
Options: dataprovider.EventActionOptions{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
eventManager.loadRules()
|
||||
|
||||
eventManager.RLock()
|
||||
assert.Len(t, eventManager.FsEvents, 0)
|
||||
assert.Len(t, eventManager.ProviderEvents, 0)
|
||||
assert.Len(t, eventManager.Schedules, 1)
|
||||
eventManager.RUnlock()
|
||||
|
||||
cronJob := eventCronJob{
|
||||
ruleName: rule1,
|
||||
}
|
||||
r, err := cronJob.getEventRule()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, rule1, r.Name)
|
||||
assert.Len(t, r.Actions, 1)
|
||||
assert.Equal(t, dataprovider.EventTriggerSchedule, r.Trigger)
|
||||
|
||||
eventManager.RLock()
|
||||
eventManager.Schedules = nil
|
||||
eventManager.RUnlock()
|
||||
|
||||
loadBuiltinRulesFn = nil
|
||||
|
||||
eventManager.loadRules()
|
||||
|
||||
eventManager.RLock()
|
||||
assert.Len(t, eventManager.FsEvents, 0)
|
||||
assert.Len(t, eventManager.ProviderEvents, 0)
|
||||
assert.Len(t, eventManager.Schedules, 0)
|
||||
eventManager.RUnlock()
|
||||
stopEventScheduler()
|
||||
}
|
||||
|
||||
func TestEventRuleActions(t *testing.T) {
|
||||
actionName := "test rule action"
|
||||
action := dataprovider.BaseEventAction{
|
||||
|
|
|
@ -236,20 +236,8 @@ var (
|
|||
fnReloadRules FnReloadRules
|
||||
fnRemoveRule FnRemoveRule
|
||||
fnHandleRuleForProviderEvent FnHandleRuleForProviderEvent
|
||||
fnCanSetHomeDir func() bool
|
||||
fnPreUserValidation func(u *User)
|
||||
fnPreFolderValidation func(f *vfs.BaseVirtualFolder)
|
||||
fnPreGroupValidation func(g *Group)
|
||||
)
|
||||
|
||||
// CanSetHomeDir returns true if the home directory can be changed
|
||||
func CanSetHomeDir() bool {
|
||||
if fnCanSetHomeDir != nil {
|
||||
return fnCanSetHomeDir()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func initSQLTables() {
|
||||
sqlTableUsers = "users"
|
||||
sqlTableFolders = "folders"
|
||||
|
@ -3334,9 +3322,6 @@ func createUserPasswordHash(user *User) error {
|
|||
// FIXME: this should be defined as Folder struct method
|
||||
func ValidateFolder(folder *vfs.BaseVirtualFolder) error {
|
||||
folder.FsConfig.SetEmptySecretsIfNil()
|
||||
if fnPreFolderValidation != nil {
|
||||
fnPreFolderValidation(folder)
|
||||
}
|
||||
if folder.Name == "" {
|
||||
return util.NewI18nError(util.NewValidationError("folder name is mandatory"), util.I18nErrorNameRequired)
|
||||
}
|
||||
|
@ -3369,9 +3354,6 @@ func ValidateUser(user *User) error {
|
|||
user.OIDCCustomFields = nil
|
||||
user.HasPassword = false
|
||||
user.SetEmptySecretsIfNil()
|
||||
if fnPreUserValidation != nil {
|
||||
fnPreUserValidation(user)
|
||||
}
|
||||
buildUserHomeDir(user)
|
||||
if err := validateBaseParams(user); err != nil {
|
||||
return err
|
||||
|
|
|
@ -134,9 +134,6 @@ func (g *Group) hasRedactedSecret() bool {
|
|||
|
||||
func (g *Group) validate() error {
|
||||
g.SetEmptySecretsIfNil()
|
||||
if fnPreGroupValidation != nil {
|
||||
fnPreGroupValidation(g)
|
||||
}
|
||||
if g.Name == "" {
|
||||
return util.NewI18nError(util.NewValidationError("name is mandatory"), util.I18nErrorNameRequired)
|
||||
}
|
||||
|
|
|
@ -157,9 +157,6 @@ func (u *User) GetFilesystem(connectionID string) (fs vfs.Fs, err error) {
|
|||
}
|
||||
|
||||
func (u *User) getRootFs(connectionID string) (fs vfs.Fs, err error) {
|
||||
if vfs.IsFsDisabled(u.FsConfig.Provider) {
|
||||
return nil, fmt.Errorf("filesystem provider %d is disabled", u.FsConfig.Provider)
|
||||
}
|
||||
switch u.FsConfig.Provider {
|
||||
case sdk.S3FilesystemProvider:
|
||||
return vfs.NewS3Fs(connectionID, u.GetHomeDir(), "", u.FsConfig.S3Config)
|
||||
|
|
|
@ -168,7 +168,6 @@ type fsWrapper struct {
|
|||
IsHidden bool
|
||||
HasUsersBaseDir bool
|
||||
DirPath string
|
||||
CanSetHomeDir bool
|
||||
}
|
||||
|
||||
type userPage struct {
|
||||
|
@ -515,7 +514,6 @@ func loadAdminTemplates(templatesPath string) {
|
|||
|
||||
fsBaseTpl := template.New("fsBaseTemplate").Funcs(template.FuncMap{
|
||||
"HumanizeBytes": util.ByteCountSI,
|
||||
"IsFsDisabled": vfs.IsFsDisabled,
|
||||
})
|
||||
usersTmpl := util.LoadTemplate(nil, usersPaths...)
|
||||
userTmpl := util.LoadTemplate(fsBaseTpl, userPaths...)
|
||||
|
@ -971,7 +969,6 @@ func (s *httpdServer) renderUserPage(w http.ResponseWriter, r *http.Request, use
|
|||
IsHidden: basePage.LoggedUser.Filters.Preferences.HideFilesystem(),
|
||||
HasUsersBaseDir: dataprovider.HasUsersBaseDir(),
|
||||
DirPath: user.HomeDir,
|
||||
CanSetHomeDir: dataprovider.CanSetHomeDir(),
|
||||
},
|
||||
}
|
||||
renderAdminTemplate(w, templateUser, data)
|
||||
|
@ -1057,7 +1054,6 @@ func (s *httpdServer) renderGroupPage(w http.ResponseWriter, r *http.Request, gr
|
|||
IsGroupPage: true,
|
||||
HasUsersBaseDir: false,
|
||||
DirPath: group.UserSettings.HomeDir,
|
||||
CanSetHomeDir: dataprovider.CanSetHomeDir(),
|
||||
},
|
||||
}
|
||||
renderAdminTemplate(w, templateGroup, data)
|
||||
|
@ -1161,7 +1157,6 @@ func (s *httpdServer) renderFolderPage(w http.ResponseWriter, r *http.Request, f
|
|||
IsGroupPage: false,
|
||||
HasUsersBaseDir: false,
|
||||
DirPath: folder.MappedPath,
|
||||
CanSetHomeDir: dataprovider.CanSetHomeDir(),
|
||||
},
|
||||
}
|
||||
renderAdminTemplate(w, templateFolder, data)
|
||||
|
|
|
@ -16,7 +16,6 @@ package vfs
|
|||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"github.com/sftpgo/sdk"
|
||||
|
||||
|
@ -24,11 +23,6 @@ import (
|
|||
"github.com/drakkan/sftpgo/v2/internal/util"
|
||||
)
|
||||
|
||||
var (
|
||||
disabledFilesystemProviders []sdk.FilesystemProvider
|
||||
loadDisabledProvidersFn func()
|
||||
)
|
||||
|
||||
// Filesystem defines filesystem details
|
||||
type Filesystem struct {
|
||||
RedactedSecret string `json:"-"`
|
||||
|
@ -412,11 +406,3 @@ func (f *Filesystem) GetACopy() Filesystem {
|
|||
}
|
||||
return fs
|
||||
}
|
||||
|
||||
// IsFsDisabled returns if a filesystem provider is disabled
|
||||
func IsFsDisabled(provider sdk.FilesystemProvider) bool {
|
||||
if loadDisabledProvidersFn != nil {
|
||||
loadDisabledProvidersFn()
|
||||
}
|
||||
return slices.Contains(disabledFilesystemProviders, provider)
|
||||
}
|
||||
|
|
|
@ -140,9 +140,6 @@ type VirtualFolder struct {
|
|||
|
||||
// GetFilesystem returns the filesystem for this folder
|
||||
func (v *VirtualFolder) GetFilesystem(connectionID string, forbiddenSelfUsers []string) (Fs, error) {
|
||||
if IsFsDisabled(v.FsConfig.Provider) {
|
||||
return nil, fmt.Errorf("filesystem provider %d is disabled", v.FsConfig.Provider)
|
||||
}
|
||||
switch v.FsConfig.Provider {
|
||||
case sdk.S3FilesystemProvider:
|
||||
return NewS3Fs(connectionID, v.MappedPath, v.VirtualPath, v.FsConfig.S3Config)
|
||||
|
|
|
@ -24,17 +24,17 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
|||
<div class="col-md-9">
|
||||
<select id="idFilesystem" name="fs_provider" class="form-select" data-control="i18n-select2" data-hide-search="true">
|
||||
<option value="0" data-i18n="storage.local" {{if eq .Provider 0 }}selected{{end}}>Local</option>
|
||||
{{- if not (IsFsDisabled 4) }}<option value="4" data-i18n="storage.encrypted" {{if eq .Provider 4 }}selected{{end}}>Local encrypted</option>{{- end}}
|
||||
{{- if not (IsFsDisabled 1) }}<option value="1" data-i18n="storage.s3" {{if eq .Provider 1 }}selected{{end}}>AWS S3 (Compatible)</option>{{- end}}
|
||||
{{- if not (IsFsDisabled 2) }}<option value="2" data-i18n="storage.gcs" {{if eq .Provider 2 }}selected{{end}}>Google Cloud Storage</option>{{- end}}
|
||||
{{- if not (IsFsDisabled 3) }}<option value="3" data-i18n="storage.azblob" {{if eq .Provider 3 }}selected{{end}}>Azure Blob Storage</option>{{- end}}
|
||||
{{- if not (IsFsDisabled 5) }}<option value="5" data-i18n="storage.sftp" {{if eq .Provider 5 }}selected{{end}}>SFTP</option>{{- end}}
|
||||
{{- if not (IsFsDisabled 6) }}<option value="6" data-i18n="storage.http" {{if eq .Provider 6 }}selected{{end}}>HTTP</option>{{- end}}
|
||||
<option value="4" data-i18n="storage.encrypted" {{if eq .Provider 4 }}selected{{end}}>Local encrypted</option>
|
||||
<option value="1" data-i18n="storage.s3" {{if eq .Provider 1 }}selected{{end}}>AWS S3 (Compatible)</option>
|
||||
<option value="2" data-i18n="storage.gcs" {{if eq .Provider 2 }}selected{{end}}>Google Cloud Storage</option>
|
||||
<option value="3" data-i18n="storage.azblob" {{if eq .Provider 3 }}selected{{end}}>Azure Blob Storage</option>
|
||||
<option value="5" data-i18n="storage.sftp" {{if eq .Provider 5 }}selected{{end}}>SFTP</option>
|
||||
<option value="6" data-i18n="storage.http" {{if eq .Provider 6 }}selected{{end}}>HTTP</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{{- if or .IsUserPage .IsGroupPage}}
|
||||
<div class="form-group row mt-10 {{if not .CanSetHomeDir}}d-none{{end}}">
|
||||
<div class="form-group row mt-10">
|
||||
<label for="idHomeDir" data-i18n="storage.home_dir" class="col-md-3 col-form-label">Home Dir</label>
|
||||
<div class="col-md-9">
|
||||
<input id="idHomeDir" type="text" data-i18n="[placeholder]storage.home_dir_placeholder" class="form-control" name="home_dir" value="{{.DirPath}}" aria-describedby="idHomeDirHelp" />
|
||||
|
@ -42,7 +42,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
|||
</div>
|
||||
</div>
|
||||
{{- else}}
|
||||
<div class="form-group row mt-10 {{if not .CanSetHomeDir}}d-none{{end}}">
|
||||
<div class="form-group row mt-10">
|
||||
<label for="idMappedPath" data-i18n="storage.home_dir" class="col-md-3 col-form-label">Home Dir</label>
|
||||
<div class="col-md-9">
|
||||
<input id="idMappedPath" type="text" data-i18n="[placeholder]storage.home_dir_placeholder" class="form-control" name="mapped_path" value="{{.DirPath}}" aria-describedby="idMappedPathHelp" />
|
||||
|
|
Loading…
Reference in a new issue