From 59e78f3c4441d91e2755f7ba936b2db702faa6ec Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Tue, 12 Jul 2016 11:19:12 -0700 Subject: [PATCH] Make storage base host configurable Should allow support for foreign Azure clouds. Related: #41. Signed-off-by: Ahmet Alp Balkan --- .../systemd/azurefile-dockervolumedriver.default | 1 + .../init/upstart/azurefile-dockervolumedriver.conf | 2 ++ .../upstart/azurefile-dockervolumedriver.default | 1 + driver.go | 12 +++++++----- main.go | 10 +++++++++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/contrib/init/systemd/azurefile-dockervolumedriver.default b/contrib/init/systemd/azurefile-dockervolumedriver.default index 35c9e3f..b44545e 100644 --- a/contrib/init/systemd/azurefile-dockervolumedriver.default +++ b/contrib/init/systemd/azurefile-dockervolumedriver.default @@ -1,6 +1,7 @@ # Environment file for azurefile-dockervolumedriver.service # # AF_OPTS=--debug +# AZURE_STORAGE_BASE=core.windows.net AZURE_STORAGE_ACCOUNT=youraccount AZURE_STORAGE_ACCOUNT_KEY=yourkey diff --git a/contrib/init/upstart/azurefile-dockervolumedriver.conf b/contrib/init/upstart/azurefile-dockervolumedriver.conf index ebd771b..9e96790 100644 --- a/contrib/init/upstart/azurefile-dockervolumedriver.conf +++ b/contrib/init/upstart/azurefile-dockervolumedriver.conf @@ -33,5 +33,7 @@ script echo "Parsed configuration correctly." export AZURE_STORAGE_ACCOUNT="$AF_ACCOUNT_NAME" export AZURE_STORAGE_ACCOUNT_KEY="$AF_ACCOUNT_KEY" + export AZURE_STORAGE_BASE="$AZURE_STORAGE_BASE" + exec "$AF_CMD" $AF_OPTS 2>&1 end script diff --git a/contrib/init/upstart/azurefile-dockervolumedriver.default b/contrib/init/upstart/azurefile-dockervolumedriver.default index e26bdbb..caa05cc 100644 --- a/contrib/init/upstart/azurefile-dockervolumedriver.default +++ b/contrib/init/upstart/azurefile-dockervolumedriver.default @@ -9,6 +9,7 @@ # # Additional arguments to executable: # AF_OPTS=--debug +# AZURE_STORAGE_BASE=core.windows.net AF_ACCOUNT_NAME=youraccount AF_ACCOUNT_KEY=yourkey diff --git a/driver.go b/driver.go index 44923d1..9d358d4 100644 --- a/driver.go +++ b/driver.go @@ -21,12 +21,13 @@ type volumeDriver struct { meta *metadataDriver accountName string accountKey string + storageBase string mountpoint string removeShares bool } -func newVolumeDriver(accountName, accountKey, mountpoint, metadataRoot string, removeShares bool) (*volumeDriver, error) { - storageClient, err := azure.NewBasicClient(accountName, accountKey) +func newVolumeDriver(accountName, accountKey, storageBase, mountpoint, metadataRoot string, removeShares bool) (*volumeDriver, error) { + storageClient, err := azure.NewClient(accountName, accountKey, storageBase, azure.DefaultAPIVersion, true) if err != nil { return nil, fmt.Errorf("error creating azure client: %v", err) } @@ -39,6 +40,7 @@ func newVolumeDriver(accountName, accountKey, mountpoint, metadataRoot string, r meta: metaDriver, accountName: accountName, accountKey: accountKey, + storageBase: storageBase, mountpoint: mountpoint, removeShares: removeShares, }, nil @@ -133,7 +135,7 @@ func (v *volumeDriver) Mount(req volume.Request) (resp volume.Response) { return } - if err := mount(v.accountName, v.accountKey, path, meta.Options); err != nil { + if err := mount(v.accountName, v.accountKey, v.storageBase, path, meta.Options); err != nil { resp.Err = err.Error() logctx.Error(resp.Err) return @@ -281,7 +283,7 @@ func (v *volumeDriver) pathForVolume(name string) string { return filepath.Join(v.mountpoint, name) } -func mount(accountName, accountKey, mountpoint string, options VolumeOptions) error { +func mount(accountName, accountKey, shareName, storageBase string, options VolumeOptions) error { // Set defaults if len(options.FileMode) == 0 { options.FileMode = "0777" @@ -295,7 +297,7 @@ func mount(accountName, accountKey, mountpoint string, options VolumeOptions) er if len(options.GID) == 0 { options.GID = "0" } - mount := fmt.Sprintf("//%s.file.core.windows.net/%s", accountName, options.Share) + mount := fmt.Sprintf("//%s.file.%s/%s", accountName, storageBase, options.Share) opts := []string{ "vers=3.0", fmt.Sprintf("username=%s", accountName), diff --git a/main.go b/main.go index 749acd3..585ac1a 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "os" + azure "github.com/Azure/azure-sdk-for-go/storage" log "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" "github.com/docker/go-plugins-helpers/volume" @@ -32,6 +33,12 @@ func main() { Usage: "Azure storage account key", EnvVar: "AZURE_STORAGE_ACCOUNT_KEY", }, + cli.StringFlag{ + Name: "storage-base", + Usage: "Base domain for Azure Storage endpoint", + EnvVar: "AZURE_STORAGE_BASE", + Value: azure.DefaultBaseURL, + }, cli.BoolFlag{ Name: "remove-shares", Usage: "remove associated Azure File Share when volume is removed", @@ -59,6 +66,7 @@ func main() { accountName := c.String("account-name") accountKey := c.String("account-key") + storageBase := c.String("storage-base") mountpoint := c.String("mountpoint") metaDir := c.String("metadata") removeShares := c.Bool("remove-shares") @@ -73,7 +81,7 @@ func main() { "removeShares": removeShares, }).Debug("Starting server.") - driver, err := newVolumeDriver(accountName, accountKey, mountpoint, metaDir, removeShares) + driver, err := newVolumeDriver(accountName, accountKey, storageBase, mountpoint, metaDir, removeShares) if err != nil { log.Fatal(err) }