From b48e01155c107c63aefd125b3a8b9f38896f0c6d Mon Sep 17 00:00:00 2001 From: Manuel Reithuber Date: Sat, 5 Jun 2021 17:15:02 +0200 Subject: [PATCH] FilesystemProvider: added .Name() which reverses vfs.GetProviderByName(), and added .ShortInfo(); using .ShortInfo() in User.GetInfoString() --- dataprovider/user.go | 13 ++----------- vfs/filesystem.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/dataprovider/user.go b/dataprovider/user.go index ee21dc3b..76de9c40 100644 --- a/dataprovider/user.go +++ b/dataprovider/user.go @@ -1005,17 +1005,8 @@ func (u *User) GetInfoString() string { t := utils.GetTimeFromMsecSinceEpoch(u.LastLogin) result += fmt.Sprintf("Last login: %v ", t.Format("2006-01-02 15:04")) // YYYY-MM-DD HH:MM } - switch u.FsConfig.Provider { - case vfs.S3FilesystemProvider: - result += "Storage: S3 " - case vfs.GCSFilesystemProvider: - result += "Storage: GCS " - case vfs.AzureBlobFilesystemProvider: - result += "Storage: AzBlob " - case vfs.CryptedFilesystemProvider: - result += "Storage: Encrypted " - case vfs.SFTPFilesystemProvider: - result += "Storage: SFTP " + if u.FsConfig.Provider != vfs.LocalFilesystemProvider { + result += fmt.Sprintf("Storage: %s ", u.FsConfig.Provider.ShortInfo()) } if len(u.PublicKeys) > 0 { result += fmt.Sprintf("Public keys: %v ", len(u.PublicKeys)) diff --git a/vfs/filesystem.go b/vfs/filesystem.go index cfcea058..ec1ba3c9 100644 --- a/vfs/filesystem.go +++ b/vfs/filesystem.go @@ -43,6 +43,44 @@ func GetProviderByName(name string) FilesystemProvider { return LocalFilesystemProvider } +// Name returns the Provider's unique name +func (p FilesystemProvider) Name() string { + switch p { + case LocalFilesystemProvider: + return "osfs" + case S3FilesystemProvider: + return "s3fs" + case GCSFilesystemProvider: + return "gcsfs" + case AzureBlobFilesystemProvider: + return "azblobfs" + case CryptedFilesystemProvider: + return "cryptfs" + case SFTPFilesystemProvider: + return "sftpfs" + } + return "" // let's not claim to be +} + +// ShortInfo returns a human readable, short description for the given FilesystemProvider +func (p FilesystemProvider) ShortInfo() string { + switch p { + case LocalFilesystemProvider: + return "Local" + case S3FilesystemProvider: + return "S3" + case GCSFilesystemProvider: + return "GCS" + case AzureBlobFilesystemProvider: + return "AzBlob" + case CryptedFilesystemProvider: + return "Encrypted" + case SFTPFilesystemProvider: + return "SFTP" + } + return "" +} + // ValidatorHelper implements methods we need for Filesystem.ValidateConfig. // It is implemented by vfs.Folder and dataprovider.User type ValidatorHelper interface {