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



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

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



333
334
335
# File 'lib/resources/azure/azure_backend.rb', line 333

def count
  @count
end

#itemObject (readonly)

Since:

  • 0.2.0



333
334
335
# File 'lib/resources/azure/azure_backend.rb', line 333

def item
  @item
end

#locationObject (readonly)

Since:

  • 0.2.0



333
334
335
# File 'lib/resources/azure/azure_backend.rb', line 333

def location
  @location
end

#nameObject (readonly)

Since:

  • 0.2.0



333
334
335
# File 'lib/resources/azure/azure_backend.rb', line 333

def name
  @name
end

#stringObject (readonly)

name Name of the Azure resource

Returns:

  • (Object)

    the current value of string



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

def string
  @string
end

#typeObject (readonly)

Since:

  • 0.2.0



333
334
335
# File 'lib/resources/azure/azure_backend.rb', line 333

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



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

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



363
364
365
# File 'lib/resources/azure/azure_backend.rb', line 363

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