Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding storage account blob and table services #408

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/resources/azure_storage_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ Either one of the parameter sets can be provided for a valid query:
|----------------------------------------------|-------------|
| queues<superscript>*</superscript> | Lists all of the queues in a given storage account. See [here](https://docs.microsoft.com/en-us/rest/api/storageservices/list-queues1) for more.
| queue_properties<superscript>*</superscript> | gets the properties of a storage account’s Queue service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. See [here](https://docs.microsoft.com/en-us/rest/api/storageservices/get-queue-service-properties) for more.
| blobs<superscript>*</superscript> | Lists all of the blob containers in a given storage account. See [here](https://docs.microsoft.com/en-us/rest/api/storageservices/list-containers2) for more.
| blob_properties<superscript>*</superscript> | gets the properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. See [here](https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties) for more.
| table_properties<superscript>*</superscript> | gets the properties of a storage account’s Table service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. See [here](https://docs.microsoft.com/en-us/rest/api/storageservices/get-table-service-properties) for more.

<superscript>*</superscript>: Note that the Azure endpoints return data in XML format; however, they will be converted to Azure Resource Probe to make the properties accessible via dot notation.
The property names will be in snake case, `propety_name`. Therefore, `<EnumerationResults ServiceEndpoint="https://myaccount.queue.core.windows.net/">` can be tested via `its('enumeration_results.service_endpoint)`.

The property names will be in snake case, `propety_name`. Therefore, `<EnumerationResults ServiceEndpoint="https://myaccount.blob.core.windows.net/">` can be tested via `its('enumeration_results.service_endpoint)`.

For properties applicable to all resources, such as `type`, `name`, `id`, `properties`, refer to [`azure_generic_resource`](azure_generic_resource.md#properties).

Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts/getproperties#storageaccount) for other properties available.
Expand Down Expand Up @@ -89,12 +94,30 @@ describe azure_storage_account(resource_group: 'rg', name: 'mysa') do
its('queues.enumeration_results.service_endpoint') { should cmp 'https://mysa.queue.core.windows.net/' }
end
```
### Test Blobs Service Endpoint
```ruby
describe azure_storage_account(resource_group: 'rg', name: 'mysa') do
its('blobs.enumeration_results.service_endpoint') { should cmp 'https://mysa.blob.core.windows.net/' }
end
```
### Test Queue Properties Logging Version
```ruby
describe azure_storage_account(resource_group: 'rg', name: 'mysa') do
its('queue_properties.logging.version') { should cmp '1.0' }
end
```
### Test Blob Properties Logging Version
```ruby
describe azure_storage_account(resource_group: 'rg', name: 'mysa') do
its('blob_properties.logging.version') { should cmp '1.0' }
end
```
### Test Table Properties Logging Version
```ruby
describe azure_storage_account(resource_group: 'rg', name: 'mysa') do
its('table_properties.logging.version') { should cmp '1.0' }
end
```
## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://docs.chef.io/inspec/matchers/).
Expand Down
51 changes: 51 additions & 0 deletions libraries/azure_storage_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,57 @@ def queue_properties
end
end

def blobs
return unless exists?
url = "https://#{name}.blob#{@azure.storage_endpoint_suffix}"
params = { comp: 'list' }
# Calls to Azure Storage resources requires a special header `x-ms-version`
# https://docs.microsoft.com/en-us/rest/api/storageservices/versioning-for-the-azure-storage-services
headers = { 'x-ms-version' => @opts[:storage_service_endpoint_api_version] }
body = @azure.rest_api_call(url: url, params: params, headers: headers)
return unless body
body_hash = Hash.from_xml(body)
hash_with_snakecase_keys = RecursiveMethodHelper.method_recursive(body_hash, :snakecase)
if hash_with_snakecase_keys
create_resource_methods({ blobs: hash_with_snakecase_keys })
public_send(:blobs) if respond_to?(:blobs)
end
end

def blob_properties
return unless exists?
url = "https://#{name}.blob#{@azure.storage_endpoint_suffix}"
params = { restype: 'service', comp: 'properties' }
# @see #queues for the header `x-ms-version`
headers = { 'x-ms-version' => @opts[:storage_service_endpoint_api_version] }
body = @azure.rest_api_call(url: url, params: params, headers: headers)
return unless body
body_hash = Hash.from_xml(body)
hash_with_snakecase_keys = RecursiveMethodHelper.method_recursive(body_hash, :snakecase)
properties = hash_with_snakecase_keys['storage_service_properties']
if properties
create_resource_methods({ blob_properties: properties })
public_send(:blob_properties) if respond_to?(:blob_properties)
end
end

def table_properties
return unless exists?
url = "https://#{name}.table#{@azure.storage_endpoint_suffix}"
params = { restype: 'service', comp: 'properties' }
# @see #queues for the header `x-ms-version`
headers = { 'x-ms-version' => @opts[:storage_service_endpoint_api_version] }
body = @azure.rest_api_call(url: url, params: params, headers: headers)
return unless body
body_hash = Hash.from_xml(body)
hash_with_snakecase_keys = RecursiveMethodHelper.method_recursive(body_hash, :snakecase)
properties = hash_with_snakecase_keys['storage_service_properties']
if properties
create_resource_methods({ table_properties: properties })
public_send(:table_properties) if respond_to?(:table_properties)
end
end

private

# @see AzureKeyVault#diagnostic_settings for how to use #additional_resource_properties method.
Expand Down