Class: AzureResourceProbe

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/azure/azure_backend.rb

Overview

Class object that is created for each element that is returned by Azure. This is what is interogated by Inspec. If they are nested hashes, then this results in nested AzureResourceProbe objects.

For example, if the following was seen in an Azure Resource

properties -> storageProfile -> imageReference

Would result in the following nestec classes

AzureResource -> AzureResourceProbe -> AzureResourceProbe

The methods for each of the classes are dynamically defined at run time and will match the items that are retrieved from Azure. See the ‘test/integration/verify/controls’ for examples

This class will not be called externally

Author:

  • Russell Seymour

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Object

Initialize method for the class. Accepts an item, be it a scalar value, hash or Azure object It will then create the necessary dynamic methods so that they can be called in the tests This is accomplished by call the AzureResourceDynamicMethods

Parameters:

  • varaint

    The item from which the class will be initialized

Since:

  • 0.2.0



340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/resources/azure/azure_backend.rb', line 340

def initialize(item)
  dm = AzureResourceDynamicMethods.new
  dm.create_methods(self, item)

  # Set the item as a property on the class
  # This is so that it is possible to interrogate what has been added to the class and isolate them from
  # the standard methods that a Ruby class has.
  # This used for checking Tags on a resource for example
  # It also allows direct access if so required
  @item = item

  # Set how many items have been set
  @count = item.length
end

Instance Attribute Details

#countObject (readonly)

Since:

  • 0.2.0



331
332
333
# File 'lib/resources/azure/azure_backend.rb', line 331

def count
  @count
end

#itemObject (readonly)

Since:

  • 0.2.0



331
332
333
# File 'lib/resources/azure/azure_backend.rb', line 331

def item
  @item
end

#locationObject (readonly)

Since:

  • 0.2.0



331
332
333
# File 'lib/resources/azure/azure_backend.rb', line 331

def location
  @location
end

#nameObject (readonly)

Since:

  • 0.2.0



331
332
333
# File 'lib/resources/azure/azure_backend.rb', line 331

def name
  @name
end

#stringObject (readonly)

name Name of the Azure resource

Returns:

  • (Object)

    the current value of string



330
331
332
# File 'lib/resources/azure/azure_backend.rb', line 330

def string
  @string
end

#typeObject (readonly)

Since:

  • 0.2.0



331
332
333
# File 'lib/resources/azure/azure_backend.rb', line 331

def type
  @type
end

Instance Method Details

#camel_case(data) ⇒ Object

Give a sting like ‘computer_name` return the camelCase version, e.g. computerName

Parameters:

  • string

    data Data that needs to be converted from snake_case to camelCase

Returns:

  • string

Since:

  • 0.2.0



371
372
373
374
375
376
# File 'lib/resources/azure/azure_backend.rb', line 371

def camel_case(data)
  camel_case_data = data.split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join

  # Ensure that gb (as in gigabytes) is uppercased
  camel_case_data.gsub(/[gb]/, &:upcase)
end

#include?(key) ⇒ Boolean

Allows resources to respond to the include test This means that things like tags can be checked for and then their value tested

Parameters:

  • key (String)

    Name of the item to look for in the @item property

Returns:

  • (Boolean)

Author:

  • Russell Seymour

Since:

  • 0.2.0



361
362
363
# File 'lib/resources/azure/azure_backend.rb', line 361

def include?(key)
  @item.key?(key)
end