Skip to content

Commit

Permalink
portable mode: add Azure Blob support
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Oct 25, 2020
1 parent 9b49f63 commit f2acde7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
41 changes: 38 additions & 3 deletions cmd/portable.go
Expand Up @@ -55,6 +55,15 @@ var (
portableWebDAVPort int
portableWebDAVCert string
portableWebDAVKey string
portableAzContainer string
portableAzAccountName string
portableAzAccountKey string
portableAzEndpoint string
portableAzSASURL string
portableAzKeyPrefix string
portableAzULPartSize int
portableAzULConcurrency int
portableAzUseEmulator bool
portableCmd = &cobra.Command{
Use: "portable",
Short: "Serve a single directory",
Expand Down Expand Up @@ -150,6 +159,17 @@ Please take a look at the usage below to customize the serving parameters`,
StorageClass: portableGCSStorageClass,
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{
FileExtensions: parseFileExtensionsFilters(),
Expand Down Expand Up @@ -213,9 +233,10 @@ multicast DNS`)
advertised via multicast DNS, this
flag allows to put username/password
inside the advertised TXT record`)
portableCmd.Flags().IntVarP(&portableFsProvider, "fs-provider", "f", int(dataprovider.LocalFilesystemProvider), `0 means local filesystem,
1 Amazon S3 compatible,
2 Google Cloud Storage`)
portableCmd.Flags().IntVarP(&portableFsProvider, "fs-provider", "f", int(dataprovider.LocalFilesystemProvider), `0 => local filesystem
1 => Amazon S3 compatible
2 => Google Cloud Storage
3 => Azure Blob Storage`)
portableCmd.Flags().StringVar(&portableS3Bucket, "s3-bucket", "", "")
portableCmd.Flags().StringVar(&portableS3Region, "s3-region", "", "")
portableCmd.Flags().StringVar(&portableS3AccessKey, "s3-access-key", "", "")
Expand Down Expand Up @@ -245,6 +266,20 @@ a JSON credentials file, 1 automatic
over HTTPS`)
portableCmd.Flags().StringVar(&portableWebDAVKey, "webdav-key", "", `Path to the key file for WebDAV over
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)
}

Expand Down
21 changes: 18 additions & 3 deletions docs/portable-mode.md
Expand Up @@ -25,6 +25,20 @@ Flags:
insensitive. The format is
/dir::ext1,ext2.
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
insensitive. The format is
/dir::ext1,ext2.
Expand All @@ -33,9 +47,10 @@ Flags:
This can be an absolute path or a path
relative to the current directory
(default ".")
-f, --fs-provider int 0 means local filesystem,
1 Amazon S3 compatible,
2 Google Cloud Storage
-f, --fs-provider int 0 => local filesystem
1 => Amazon S3 compatible
2 => Google Cloud Storage
3 => Azure Blob Storage
--ftpd-cert string Path to the certificate file for FTPS
--ftpd-key string Path to the key file for FTPS
--ftpd-port int 0 means a random unprivileged port,
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Expand Up @@ -60,7 +60,7 @@ func (s *Service) Start() error {
logger.InitLogger(s.LogFilePath, s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogCompress, logLevel)
if s.PortableMode == 1 {
logger.EnableConsoleLogger(logLevel)
if len(s.LogFilePath) == 0 {
if s.LogFilePath == "" {
logger.DisableLogger()
}
}
Expand Down
5 changes: 4 additions & 1 deletion service/service_portable.go
Expand Up @@ -27,8 +27,11 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledS
if s.PortableMode != 1 {
return fmt.Errorf("service is not configured for portable mode")
}
var err error
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 {
s.PortableUser.Username = "user"
}
Expand Down
1 change: 1 addition & 0 deletions vfs/azblobfs.go
Expand Up @@ -767,6 +767,7 @@ func (fs *AzureBlobFs) handleMultipartUpload(ctx context.Context, reader io.Read
finished = true
} else if err != nil {
pool.releaseBuffer(buf)
pool.free()
return err
}

Expand Down

0 comments on commit f2acde7

Please sign in to comment.