~jtv/gwacl/storage-tool-command-line

« back to all changes in this revision

Viewing changes to storage_base.go

  • Committer: Tarmac
  • Author(s): jtv at canonical
  • Date: 2013-08-06 08:01:43 UTC
  • mfrom: (211.2.13 service-endpoints)
  • Revision ID: tarmac-20130806080143-8tg75f6zw3fdvemq
[r=julian-edwards][bug=][author=jtv] Support Chinese Azure endpoints, as well as the international ones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
// request to the storage services API.  It also has an HTTP Client to allow
203
203
// overriding for custom behaviour, during testing for example.
204
204
type StorageContext struct {
 
205
    // Account is a storage account name.
205
206
    Account string
206
 
    // Access key: access will be anonymous if the key is the empty string.
207
 
    Key    string
 
207
 
 
208
    // Key authenticates the storage account.  Access will be anonymous if this
 
209
    // is left empty.
 
210
    Key string
 
211
 
 
212
    // AzureEndpoint specifies a base service endpoint URL for the Azure APIs.
 
213
    // If this is not set, it will default to the international endpoint which
 
214
    // will not work in mainland China.
 
215
    //
 
216
    // Try to set this if at all possible.  Use GetEndpoint() to obtain the
 
217
    // endpoint associated with a given service location, e.g. "West US" or
 
218
    // "North Europe" or "East China".
 
219
    AzureEndpoint APIEndpoint
 
220
 
208
221
    client *http.Client
209
222
}
210
223
 
321
334
// getAccountURL returns the base URL for the context's storage account.
322
335
// (The result ends in a slash.)
323
336
func (context *StorageContext) getAccountURL() string {
324
 
    escapedAccount := url.QueryEscape(context.Account)
325
 
    // Use https.  This does not suffer from the "no renegotiation" bug in
326
 
    // Go's implementation.  It's optional, but it gets around spurious
327
 
    // authentication failures when working through a proxy that messes with
328
 
    // our requests instead of passing them on verbatim.
329
 
    return fmt.Sprintf("https://%s.blob.core.windows.net/", escapedAccount)
 
337
    endpoint := context.AzureEndpoint
 
338
    if endpoint == "" {
 
339
        // No API endpoint specified.  Default to the international one.
 
340
        // This will not work for mainland China.
 
341
        endpoint = GetEndpoint("West US")
 
342
    }
 
343
    return prefixHost(context.Account, endpoint.BlobStorageAPI())
330
344
}
331
345
 
332
346
// getContainerURL returns the URL for a given storage container.