Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environment parameters #290

Merged
merged 3 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 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,13 @@ 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 = "#{@azure.resource_manager_endpoint_url}subscriptions/#{@azure.credentials[:subscription_id]}/providers/#{provider}"
rmoles marked this conversation as resolved.
Show resolved Hide resolved
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