FilesystemProvider: added .Name() which reverses vfs.GetProviderByName(), and added .ShortInfo(); using .ShortInfo() in User.GetInfoString()

This commit is contained in:
Manuel Reithuber 2021-06-05 17:15:02 +02:00 committed by Nicola Murino
parent 0ff010cc94
commit b48e01155c
2 changed files with 40 additions and 11 deletions

View file

@ -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))

View file

@ -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 {