storage/driver/azure: Allow non-default realms
This enables Azure storage driver to be used with non-default cloud endpoints like Azure China or Azure Government that does not use `.blob.core.windows.net` FQDN suffix. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>master
							parent
							
								
									af4f5aa7d2
								
							
						
					
					
						commit
						594f733e03
					
				| 
						 | 
					@ -24,6 +24,7 @@ const (
 | 
				
			||||||
	paramAccountName = "accountname"
 | 
						paramAccountName = "accountname"
 | 
				
			||||||
	paramAccountKey  = "accountkey"
 | 
						paramAccountKey  = "accountkey"
 | 
				
			||||||
	paramContainer   = "container"
 | 
						paramContainer   = "container"
 | 
				
			||||||
 | 
						paramRealm       = "realm"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type driver struct {
 | 
					type driver struct {
 | 
				
			||||||
| 
						 | 
					@ -64,12 +65,17 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
 | 
				
			||||||
		return nil, fmt.Errorf("No %s parameter provided", paramContainer)
 | 
							return nil, fmt.Errorf("No %s parameter provided", paramContainer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return New(fmt.Sprint(accountName), fmt.Sprint(accountKey), fmt.Sprint(container))
 | 
						realm, ok := parameters[paramRealm]
 | 
				
			||||||
 | 
						if !ok || fmt.Sprint(realm) == "" {
 | 
				
			||||||
 | 
							realm = azure.DefaultBaseUrl
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return New(fmt.Sprint(accountName), fmt.Sprint(accountKey), fmt.Sprint(container), fmt.Sprint(realm))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// New constructs a new Driver with the given Azure Storage Account credentials
 | 
					// New constructs a new Driver with the given Azure Storage Account credentials
 | 
				
			||||||
func New(accountName, accountKey, container string) (*Driver, error) {
 | 
					func New(accountName, accountKey, container, realm string) (*Driver, error) {
 | 
				
			||||||
	api, err := azure.NewBasicClient(accountName, accountKey)
 | 
						api, err := azure.NewClient(accountName, accountKey, realm, azure.DefaultApiVersion, true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -343,5 +349,5 @@ func (d *driver) listBlobs(container, virtPath string) ([]string, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func is404(err error) bool {
 | 
					func is404(err error) bool {
 | 
				
			||||||
	e, ok := err.(azure.StorageServiceError)
 | 
						e, ok := err.(azure.StorageServiceError)
 | 
				
			||||||
	return ok && e.StatusCode == 404
 | 
						return ok && e.StatusCode == http.StatusNotFound
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ const (
 | 
				
			||||||
	envAccountName = "AZURE_STORAGE_ACCOUNT_NAME"
 | 
						envAccountName = "AZURE_STORAGE_ACCOUNT_NAME"
 | 
				
			||||||
	envAccountKey  = "AZURE_STORAGE_ACCOUNT_KEY"
 | 
						envAccountKey  = "AZURE_STORAGE_ACCOUNT_KEY"
 | 
				
			||||||
	envContainer   = "AZURE_STORAGE_CONTAINER"
 | 
						envContainer   = "AZURE_STORAGE_CONTAINER"
 | 
				
			||||||
 | 
						envRealm       = "AZURE_STORAGE_REALM"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Hook up gocheck into the "go test" runner.
 | 
					// Hook up gocheck into the "go test" runner.
 | 
				
			||||||
| 
						 | 
					@ -25,6 +26,7 @@ func init() {
 | 
				
			||||||
		accountName string
 | 
							accountName string
 | 
				
			||||||
		accountKey  string
 | 
							accountKey  string
 | 
				
			||||||
		container   string
 | 
							container   string
 | 
				
			||||||
 | 
							realm       string
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config := []struct {
 | 
						config := []struct {
 | 
				
			||||||
| 
						 | 
					@ -34,6 +36,7 @@ func init() {
 | 
				
			||||||
		{envAccountName, &accountName},
 | 
							{envAccountName, &accountName},
 | 
				
			||||||
		{envAccountKey, &accountKey},
 | 
							{envAccountKey, &accountKey},
 | 
				
			||||||
		{envContainer, &container},
 | 
							{envContainer, &container},
 | 
				
			||||||
 | 
							{envRealm, &realm},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	missing := []string{}
 | 
						missing := []string{}
 | 
				
			||||||
| 
						 | 
					@ -45,7 +48,7 @@ func init() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	azureDriverConstructor := func() (storagedriver.StorageDriver, error) {
 | 
						azureDriverConstructor := func() (storagedriver.StorageDriver, error) {
 | 
				
			||||||
		return New(accountName, accountKey, container)
 | 
							return New(accountName, accountKey, container, realm)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Skip Azure storage driver tests if environment variable parameters are not provided
 | 
						// Skip Azure storage driver tests if environment variable parameters are not provided
 | 
				
			||||||
| 
						 | 
					@ -61,5 +64,6 @@ func init() {
 | 
				
			||||||
	// 	paramAccountName: accountName,
 | 
						// 	paramAccountName: accountName,
 | 
				
			||||||
	// 	paramAccountKey:  accountKey,
 | 
						// 	paramAccountKey:  accountKey,
 | 
				
			||||||
	// 	paramContainer:   container,
 | 
						// 	paramContainer:   container,
 | 
				
			||||||
 | 
						// 	paramRealm:       realm,
 | 
				
			||||||
	// }, skipCheck)
 | 
						// }, skipCheck)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue