Skip to content
Daniel Berger edited this page Oct 12, 2016 · 10 revisions

The StorageAccount model is specially tailored with custom methods over and above the auto-generated methods that other service classes use. This is because storage accounts are special entities within Microsoft Azure that contain blobs, queues and files. These contain things like images and metrics information, plus whatever else the end users have decided to put there.

Because these resources can be independently accessed, a separate authentication step was implemented by Microsoft. This is handled as transparently as possible within the azure-armrest gem, but it does require that you provide a key. The good news is that this key is very easy to get at.

Get Storage Account information

# Example:

# Create our storage account service object.
sas = Azure::Armrest::StorageAccountService.new(conf)

# Get the storage account object for the given account + resource group.
storage_account = sas.get(storage_acct_name, resource_group)

# Get the key for the storage account. There are two possible keys: key1 and key2
key = sas.list_account_keys(storage_account.name, resource_group).fetch('key1')

# Use that key to get information we want from the storage account
p storage_account.table_data(some_table, key)
p storage_account.containers(key)
p storage_account.blobs(some_container, key)

Create a Storage Account

sas = Azure::Armrest::StorageAccountService.new(conf)

options = {
  :location => "Central US",
  :tags     => {:redhat => true},
  :sku      => {:name => "Standard_LRS"},
  :kind     => "Storage"
}

# Your storage account name must be unique across all of your subscriptions.
sas.create('mystorage', group, options)

Future Plans

We plan to autogenerate custom Shared Access Signature (SAS) tokens if a key isn't explicitly provided so that you can skip that step.

More Information

For information on the StorageAccountService class, please see StorageAccountService.