class Inspec::Resources::AzureResourceGroup
def create_has_methods
- Private: -
Other tags:
- Author: - Russell Seymour
def create_has_methods return if failed_resource? # Create the has methods for each of the mappings # This is a quick test to show that the resource group has at least one of these things mapping.each do |name, type| # Determine the name of the method name method_name = format("has_%ss?", name) namespace, type_name = type.split(/\./) # use the namespace and the type_name to determine if the resource group has this type or not result = send(namespace).methods.include?(type_name.to_sym) ? true : false define_singleton_method method_name do result end end end
def initialize(opts)
- Author: - Russell Seymour
def initialize(opts) opts.key?(:name) ? opts[:group_name] = opts[:name] : false # Ensure that the opts only have the name of the resource group set opts.select! { |k, _v| k == :group_name } super(opts) # set the mapping for the Azure Resources @mapping = { nic: "Microsoft.Network/networkInterfaces", vm: "Microsoft.Compute/virtualMachines", extension: "Microsoft.Compute/virtualMachines/extensions", nsg: "Microsoft.Network/networkSecurityGroups", vnet: "Microsoft.Network/virtualNetworks", managed_disk: "Microsoft.Compute/disks", managed_disk_image: "Microsoft.Compute/images", sa: "Microsoft.Storage/storageAccounts", public_ip: "Microsoft.Network/publicIPAddresses", } # Get information about the resource group itself resource_group # Get information about the resources in the resource group resources # Call method to create the has_xxxx? methods create_has_methods # Call method to allow access to the tag values create_tag_methods end
def method_missing(method_id)
-
method_id(Symbol) -- The name of the method that was called
Other tags:
- Author: - Russell Seymour
def method_missing(method_id) # Determine the mapping_key based on the method_id mapping_key = method_id.to_s.chomp("_count").to_sym if mapping.key?(mapping_key) # based on the method id get the namespace, type_name = mapping[mapping_key].split(/\./) # check that the type_name is defined, if not return 0 if send(namespace).methods.include?(type_name.to_sym) # return the count for the method id send(namespace).send(type_name) else 0 end else msg = format("undefined method `%s` for %s", method_id, self.class) raise NoMethodError, msg end end
def parse_resource(resource)
-
resource(Hash) -- A hashtable representing the resource group
Other tags:
- Author: - Russell Seymour
def parse_resource(resource) # return a hash of information parsed = { "name" => resource.name, "type" => resource.type, } parsed end
def provisioning_state
- Author: - Russell Seymour
def provisioning_state properties.provisioningState end
def subscription_id
- Author: - Russell Seymour
def subscription_id id.split(%r{\/}).reject(&:empty?)[1] end