// Region is specified in the HasRegion interface. func (env *azureEnviron) Region() (simplestreams.CloudSpec, error) { ecfg := env.getSnapshot().ecfg return simplestreams.CloudSpec{ Region: ecfg.location(), Endpoint: string(gwacl.GetEndpoint(ecfg.location())), }, nil }
func (*storageSuite) TestURL(c *gc.C) { container := "container" filename := "blobname" account := "account" key := "bWFkZXlvdWxvb2sK" azStorage, _ := makeFakeStorage(container, account, key) // Use a realistic service endpoint for this test, so that we can see // that we're really getting the expected kind of URL. setStorageEndpoint(azStorage, gwacl.GetEndpoint("West US")) URL, err := azStorage.URL(filename) c.Assert(err, gc.IsNil) parsedURL, err := url.Parse(URL) c.Assert(err, gc.IsNil) c.Check(parsedURL.Host, gc.Matches, fmt.Sprintf("%s.blob.core.windows.net", account)) c.Check(parsedURL.Path, gc.Matches, fmt.Sprintf("/%s/%s", container, filename)) values, err := url.ParseQuery(parsedURL.RawQuery) c.Assert(err, gc.IsNil) signature := values.Get("sig") // The query string contains a non-empty signature. c.Check(signature, gc.Not(gc.HasLen), 0) // The signature is base64-encoded. _, err = base64.StdEncoding.DecodeString(signature) c.Assert(err, gc.IsNil) // If Key is empty, query string does not contain a signature. key = "" azStorage, _ = makeFakeStorage(container, account, key) URL, err = azStorage.URL(filename) c.Assert(err, gc.IsNil) parsedURL, err = url.Parse(URL) c.Assert(err, gc.IsNil) values, err = url.ParseQuery(parsedURL.RawQuery) c.Assert(err, gc.IsNil) c.Check(values.Get("sig"), gc.HasLen, 0) }
func (*environSuite) TestGetStorageContextCreatesStorageContext(c *C) { env := makeEnviron(c) storage, err := env.getStorageContext() c.Assert(err, IsNil) c.Assert(storage, NotNil) c.Check(storage.Account, Equals, env.ecfg.storageAccountName()) c.Check(storage.AzureEndpoint, Equals, gwacl.GetEndpoint(env.ecfg.location())) }
// getPublicStorageContext obtains a context object for interfacing with // Azure's storage API (public storage). func (env *azureEnviron) getPublicStorageContext() (*gwacl.StorageContext, error) { ecfg := env.getSnapshot().ecfg context := gwacl.StorageContext{ Account: ecfg.publicStorageAccountName(), Key: "", // Empty string means anonymous access. AzureEndpoint: gwacl.GetEndpoint(ecfg.location()), } // There is currently no way for this to fail. return &context, nil }
// getStorageContext obtains a context object for interfacing with Azure's // storage API. // For now, each invocation just returns a separate object. This is probably // wasteful (each context gets its own SSL connection) and may need optimizing // later. func (env *azureEnviron) getStorageContext() (*gwacl.StorageContext, error) { snap := env.getSnapshot() key := snap.storageAccountKey if key == "" { // We don't know the storage-account key yet. Request it. var err error key, err = env.updateStorageAccountKey(snap) if err != nil { return nil, err } } context := gwacl.StorageContext{ Account: snap.ecfg.storageAccountName(), Key: key, AzureEndpoint: gwacl.GetEndpoint(snap.ecfg.location()), } return &context, nil }
// getEndpoint returns the simplestreams endpoint to use for the given Azure // location (e.g. West Europe or China North). func getEndpoint(location string) string { // Simplestreams uses the management-API endpoint for the image, not // the base managent API URL. return gwacl.GetEndpoint(location).ManagementAPI() }