portable mode: add Azure Blob support

This commit is contained in:
Nicola Murino
2020-10-25 21:42:43 +01:00
parent 9b49f63a97
commit f2acde789d
5 changed files with 62 additions and 8 deletions

View File

@@ -55,6 +55,15 @@ var (
portableWebDAVPort int portableWebDAVPort int
portableWebDAVCert string portableWebDAVCert string
portableWebDAVKey string portableWebDAVKey string
portableAzContainer string
portableAzAccountName string
portableAzAccountKey string
portableAzEndpoint string
portableAzSASURL string
portableAzKeyPrefix string
portableAzULPartSize int
portableAzULConcurrency int
portableAzUseEmulator bool
portableCmd = &cobra.Command{ portableCmd = &cobra.Command{
Use: "portable", Use: "portable",
Short: "Serve a single directory", Short: "Serve a single directory",
@@ -150,6 +159,17 @@ Please take a look at the usage below to customize the serving parameters`,
StorageClass: portableGCSStorageClass, StorageClass: portableGCSStorageClass,
KeyPrefix: portableGCSKeyPrefix, KeyPrefix: portableGCSKeyPrefix,
}, },
AzBlobConfig: vfs.AzBlobFsConfig{
Container: portableAzContainer,
AccountName: portableAzAccountName,
AccountKey: portableAzAccountKey,
Endpoint: portableAzEndpoint,
SASURL: portableAzSASURL,
KeyPrefix: portableAzKeyPrefix,
UseEmulator: portableAzUseEmulator,
UploadPartSize: int64(portableAzULPartSize),
UploadConcurrency: portableAzULConcurrency,
},
}, },
Filters: dataprovider.UserFilters{ Filters: dataprovider.UserFilters{
FileExtensions: parseFileExtensionsFilters(), FileExtensions: parseFileExtensionsFilters(),
@@ -213,9 +233,10 @@ multicast DNS`)
advertised via multicast DNS, this advertised via multicast DNS, this
flag allows to put username/password flag allows to put username/password
inside the advertised TXT record`) inside the advertised TXT record`)
portableCmd.Flags().IntVarP(&portableFsProvider, "fs-provider", "f", int(dataprovider.LocalFilesystemProvider), `0 means local filesystem, portableCmd.Flags().IntVarP(&portableFsProvider, "fs-provider", "f", int(dataprovider.LocalFilesystemProvider), `0 => local filesystem
1 Amazon S3 compatible, 1 => Amazon S3 compatible
2 Google Cloud Storage`) 2 => Google Cloud Storage
3 => Azure Blob Storage`)
portableCmd.Flags().StringVar(&portableS3Bucket, "s3-bucket", "", "") portableCmd.Flags().StringVar(&portableS3Bucket, "s3-bucket", "", "")
portableCmd.Flags().StringVar(&portableS3Region, "s3-region", "", "") portableCmd.Flags().StringVar(&portableS3Region, "s3-region", "", "")
portableCmd.Flags().StringVar(&portableS3AccessKey, "s3-access-key", "", "") portableCmd.Flags().StringVar(&portableS3AccessKey, "s3-access-key", "", "")
@@ -245,6 +266,20 @@ a JSON credentials file, 1 automatic
over HTTPS`) over HTTPS`)
portableCmd.Flags().StringVar(&portableWebDAVKey, "webdav-key", "", `Path to the key file for WebDAV over portableCmd.Flags().StringVar(&portableWebDAVKey, "webdav-key", "", `Path to the key file for WebDAV over
HTTPS`) HTTPS`)
portableCmd.Flags().StringVar(&portableAzContainer, "az-container", "", "")
portableCmd.Flags().StringVar(&portableAzAccountName, "az-account-name", "", "")
portableCmd.Flags().StringVar(&portableAzAccountKey, "az-account-key", "", "")
portableCmd.Flags().StringVar(&portableAzSASURL, "az-sas-url", "", `Shared access signature URL`)
portableCmd.Flags().StringVar(&portableAzEndpoint, "az-endpoint", "", `Leave empty to use the default:
"blob.core.windows.net"`)
portableCmd.Flags().StringVar(&portableAzKeyPrefix, "az-key-prefix", "", `Allows to restrict access to the
virtual folder identified by this
prefix and its contents`)
portableCmd.Flags().IntVar(&portableAzULPartSize, "az-upload-part-size", 4, `The buffer size for multipart uploads
(MB)`)
portableCmd.Flags().IntVar(&portableAzULConcurrency, "az-upload-concurrency", 2, `How many parts are uploaded in
parallel`)
portableCmd.Flags().BoolVar(&portableAzUseEmulator, "az-use-emulator", false, "")
rootCmd.AddCommand(portableCmd) rootCmd.AddCommand(portableCmd)
} }

View File

@@ -25,6 +25,20 @@ Flags:
insensitive. The format is insensitive. The format is
/dir::ext1,ext2. /dir::ext1,ext2.
For example: "/somedir::.jpg,.png" For example: "/somedir::.jpg,.png"
--az-account-key string
--az-account-name string
--az-container string
--az-endpoint string Leave empty to use the default:
"blob.core.windows.net"
--az-key-prefix string Allows to restrict access to the
virtual folder identified by this
prefix and its contents
--az-sas-url string Shared access signature URL
--az-upload-concurrency int How many parts are uploaded in
parallel (default 2)
--az-upload-part-size int The buffer size for multipart uploads
(MB) (default 4)
--az-use-emulator
--denied-extensions stringArray Denied file extensions case --denied-extensions stringArray Denied file extensions case
insensitive. The format is insensitive. The format is
/dir::ext1,ext2. /dir::ext1,ext2.
@@ -33,9 +47,10 @@ Flags:
This can be an absolute path or a path This can be an absolute path or a path
relative to the current directory relative to the current directory
(default ".") (default ".")
-f, --fs-provider int 0 means local filesystem, -f, --fs-provider int 0 => local filesystem
1 Amazon S3 compatible, 1 => Amazon S3 compatible
2 Google Cloud Storage 2 => Google Cloud Storage
3 => Azure Blob Storage
--ftpd-cert string Path to the certificate file for FTPS --ftpd-cert string Path to the certificate file for FTPS
--ftpd-key string Path to the key file for FTPS --ftpd-key string Path to the key file for FTPS
--ftpd-port int 0 means a random unprivileged port, --ftpd-port int 0 means a random unprivileged port,

View File

@@ -60,7 +60,7 @@ func (s *Service) Start() error {
logger.InitLogger(s.LogFilePath, s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogCompress, logLevel) logger.InitLogger(s.LogFilePath, s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogCompress, logLevel)
if s.PortableMode == 1 { if s.PortableMode == 1 {
logger.EnableConsoleLogger(logLevel) logger.EnableConsoleLogger(logLevel)
if len(s.LogFilePath) == 0 { if s.LogFilePath == "" {
logger.DisableLogger() logger.DisableLogger()
} }
} }

View File

@@ -27,8 +27,11 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledS
if s.PortableMode != 1 { if s.PortableMode != 1 {
return fmt.Errorf("service is not configured for portable mode") return fmt.Errorf("service is not configured for portable mode")
} }
var err error
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
err := config.LoadConfig(s.ConfigDir, s.ConfigFile)
if err != nil {
fmt.Printf("error loading configuration file: %v using defaults\n", err)
}
if len(s.PortableUser.Username) == 0 { if len(s.PortableUser.Username) == 0 {
s.PortableUser.Username = "user" s.PortableUser.Username = "user"
} }

View File

@@ -767,6 +767,7 @@ func (fs *AzureBlobFs) handleMultipartUpload(ctx context.Context, reader io.Read
finished = true finished = true
} else if err != nil { } else if err != nil {
pool.releaseBuffer(buf) pool.releaseBuffer(buf)
pool.free()
return err return err
} }