-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from inspec/f/express_route
F/express route
- Loading branch information
Showing
7 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
require 'azure_generic_resources' | ||
|
||
class AzureExpressRouteServiceProviders < AzureGenericResources | ||
name 'azure_express_route_providers' | ||
desc 'Verifies settings for Azure Virtual Machines' | ||
example <<-EXAMPLE | ||
describe azure_express_route_providers(resource_group: 'example') do | ||
it{ should exist } | ||
end | ||
EXAMPLE | ||
|
||
attr_reader :table | ||
|
||
def initialize(opts = {}) | ||
# Options should be Hash type. Otherwise Ruby will raise an error when we try to access the keys. | ||
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash) | ||
|
||
# Azure REST API endpoint URL format listing the all resources for a given subscription: | ||
# GET https://management.azure.com/subscriptions/{subscriptionId}/ | ||
# providers/Microsoft.Network/expressRouteServiceProviders?api-version=2020-11-01 | ||
# | ||
# or in a resource group only | ||
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/ | ||
# Microsoft.Network/expressRouteServiceProviders?api-version=2019-12-01 | ||
# | ||
# The dynamic part that has to be created for this resource: | ||
# Microsoft.Network/expressRouteServiceProviders?api-version=2019-12-01 | ||
# | ||
# Parameters acquired from environment variables: | ||
# - {subscriptionId} => Required parameter. It will be acquired by the backend from environment variables. | ||
# | ||
# For parameters applicable to all resources, see project's README. | ||
# | ||
# User supplied parameters: | ||
# - resource_group => Optional parameter. | ||
# - api_version => Optional parameter. The latest version will be used unless provided. | ||
# | ||
# **`resource_group` will be used in the backend appropriately. | ||
# We don't have to do anything here. | ||
# | ||
# Following resource parameters have to be defined/created here. | ||
# resource_provider => Microsoft.Network/expressRouteServiceProviders | ||
# The `specific_resource_constraint` method will validate the user input | ||
# not to accept a different `resource_provider`. | ||
# | ||
opts[:resource_provider] = specific_resource_constraint('Microsoft.Network/expressRouteServiceProviders', opts) | ||
|
||
# static_resource parameter must be true for setting the resource_provider in the backend. | ||
super(opts, true) | ||
|
||
# Check if the resource is failed. | ||
# It is recommended to check that after every usage of superclass methods or API calls. | ||
return if failed_resource? | ||
|
||
# Define the column and field names for FilterTable. | ||
# - column: It is defined as an instance method, callable on the resource, and present `field` values in a list. | ||
# - field: It has to be identical with the `key` names in @table items that will be presented in the FilterTable. | ||
# @see https://github.com/inspec/inspec/blob/master/docs/dev/filtertable-usage.md | ||
table_schema = [ | ||
{ column: :names, field: :name }, | ||
{ column: :types, field: :type }, | ||
{ column: :ids, field: :id }, | ||
{ column: :tags, field: :tags }, | ||
{ column: :provisioning_states, field: :provisioningState }, | ||
{ column: :peering_locations_list, field: :peeringLocations }, | ||
{ column: :bandwidths_offered_list, field: :bandwidthsOffered }, | ||
] | ||
# FilterTable is populated at the very end due to being an expensive operation. | ||
AzureGenericResources.populate_filter_table(:table, table_schema) | ||
end | ||
|
||
def to_s | ||
super(AzureExpressRouteServiceProviders) | ||
end | ||
|
||
private | ||
|
||
# Populate the @table with the resource attributes. | ||
# @table has been declared in the super class as an empty array. | ||
# Each item in the @table | ||
# - should be a Hash object | ||
# - should have the exact key names defined in the @table_schema as `field`. | ||
def populate_table | ||
# If @resources empty than @table should stay as an empty array as declared in superclass. | ||
# This will ensure constructing resource and passing `should_not exist` test. | ||
return [] if @resources.empty? | ||
|
||
@resources.each do |resource| | ||
@table << { | ||
id: resource[:id], | ||
name: resource[:name], | ||
type: resource[:type], | ||
tags: resource[:tags], | ||
provisioningState: resource[:properties][:provisioningState], | ||
peeringLocations: resource[:properties][:peeringLocations], | ||
bandwidthsOffered: resource[:properties][:bandwidthsOffered], | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/integration/verify/controls/azure_express_route_providers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
express_route_name = input('express_route_name', value: nil) | ||
|
||
control 'azure_express_route_providers' do | ||
describe azure_express_route_providers do | ||
its('names') { should include express_route_name } | ||
its('types') { should include 'Microsoft.Network/expressRouteServiceProviders' } | ||
its('provisioning_states') { should include('Succeeded') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require_relative 'helper' | ||
require 'azure_express_route_providers' | ||
|
||
class AzureExpressRouteServiceProvidersConstructorTest < Minitest::Test | ||
def test_resource_type_not_ok | ||
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(resource_provider: 'some_type') } | ||
end | ||
|
||
def tag_value_not_ok | ||
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(tag_value: 'some_tag_value') } | ||
end | ||
|
||
def tag_name_not_ok | ||
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(tag_name: 'some_tag_name') } | ||
end | ||
|
||
def test_resource_id_not_ok | ||
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(resource_id: 'some_id') } | ||
end | ||
|
||
def test_name_not_ok | ||
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(name: 'some_name') } | ||
end | ||
end |