mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 15:10:23 +00:00
add fs providers hook
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
81433e00d1
commit
954c36c0a2
5 changed files with 34 additions and 8 deletions
|
@ -157,6 +157,9 @@ 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)
|
||||
|
|
|
@ -514,6 +514,7 @@ 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...)
|
||||
|
|
|
@ -16,10 +16,17 @@ package vfs
|
|||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"github.com/sftpgo/sdk"
|
||||
|
||||
"github.com/drakkan/sftpgo/v2/internal/kms"
|
||||
"github.com/drakkan/sftpgo/v2/internal/util"
|
||||
)
|
||||
|
||||
var (
|
||||
disabledFilesystemProviders []sdk.FilesystemProvider
|
||||
loadDisabledProvidersFn func()
|
||||
)
|
||||
|
||||
// Filesystem defines filesystem details
|
||||
|
@ -232,8 +239,7 @@ func (f *Filesystem) Validate(additionalData string) error {
|
|||
f.CryptConfig = CryptFsConfig{}
|
||||
f.SFTPConfig = SFTPFsConfig{}
|
||||
return nil
|
||||
default:
|
||||
f.Provider = sdk.LocalFilesystemProvider
|
||||
case sdk.LocalFilesystemProvider:
|
||||
f.S3Config = S3FsConfig{}
|
||||
f.GCSConfig = GCSFsConfig{}
|
||||
f.AzBlobConfig = AzBlobFsConfig{}
|
||||
|
@ -241,6 +247,11 @@ func (f *Filesystem) Validate(additionalData string) error {
|
|||
f.SFTPConfig = SFTPFsConfig{}
|
||||
f.HTTPConfig = HTTPFsConfig{}
|
||||
return validateOSFsConfig(&f.OSConfig)
|
||||
default:
|
||||
return util.NewI18nError(
|
||||
util.NewValidationError("invalid filesystem provider"),
|
||||
util.I18nErrorFsValidation,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,3 +401,11 @@ 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,6 +140,9 @@ 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,12 +24,12 @@ 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>
|
||||
<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>
|
||||
{{- 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}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue