Skip to content

Commit

Permalink
Merge pull request #290 from inspec/fix_environment_parameters
Browse files Browse the repository at this point in the history
Fix environment parameters
  • Loading branch information
rmoles authored Sep 7, 2020
2 parents 5723892 + c0e650f commit d078580
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libraries/azure_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ def resource_from_graph_api(opts)
# $filter=resourceGroup eq '{resource_group}' and name eq '{resource_name}'
def resource_short(opts)
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)
url = "#{@azure.resource_manager_endpoint_url}subscriptions/#{@azure.credentials[:subscription_id]}/resources"
url = Helpers.construct_url([
@azure.resource_manager_endpoint_url,
'subscriptions',
@azure.credentials[:subscription_id], 'resources'
])
api_version = @azure.resource_manager_endpoint_api_version
params = {
'$filter' => Helpers.odata_query(opts),
Expand Down Expand Up @@ -303,7 +307,12 @@ def get_api_version(provider, resource_type, api_version_status = 'latest')

# If the resource manager api version is updated earlier, use that.
api_version_mgm = @resource_manager_endpoint_api || @azure.resource_manager_endpoint_api_version
url = "#{@azure.resource_manager_endpoint_url}subscriptions/#{@azure.credentials[:subscription_id]}/providers/#{provider}"
url = Helpers.construct_url([
@azure.resource_manager_endpoint_url,
'subscriptions',
@azure.credentials[:subscription_id], 'providers',
provider
])
provider_details, suggested_api_version = rescue_wrong_api_call(url, { 'api-version' => api_version_mgm })
# If suggested_api_version is not nil, then the resource manager api version should be updated.
unless suggested_api_version.nil?
Expand Down
5 changes: 5 additions & 0 deletions libraries/backend/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,9 @@ def self.resource_deprecation_message(old_resource_name, new_resource_class)
"#{old_resource_name} will be deprecated soon and it is advised to switch to the fully backward compatible new resource. "\
'Please see the documentation for the additional features available.'
end

def self.construct_url(input_list)
raise ArgumentError, "An array has to be provided. Found: #{input_list.class}." unless input_list.is_a?(Array)
input_list.each_with_object([]) { |input, list| list << input.delete_suffix('/').delete_prefix('/') }.join('/')
end
end

0 comments on commit d078580

Please sign in to comment.