Skip to content

Commit

Permalink
URI.escape is obsolete in Ruby 2.7
Browse files Browse the repository at this point in the history
Make sure to not escape '/' like the original
  • Loading branch information
rkoster committed Mar 29, 2021
1 parent b3dd75d commit 759ad8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def initialize(azure_config, logger)

# Common
def rest_api_url(resource_provider, resource_type, resource_group_name: nil, name: nil, others: nil)
url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
resource_group_name = @azure_config.resource_group_name if resource_group_name.nil?
url += "/resourceGroups/#{URI.escape(resource_group_name)}"
url += "/resourceGroups/#{uri_escape(resource_group_name)}"
url += "/providers/#{resource_provider}"
url += "/#{resource_type}"
url += "/#{URI.escape(name)}" unless name.nil?
url += "/#{URI.escape(others)}" unless others.nil?
url += "/#{uri_escape(name)}" unless name.nil?
url += "/#{uri_escape(others)}" unless others.nil?
url
end

Expand Down Expand Up @@ -181,8 +181,8 @@ def get_resources_by_url(url, params = {})
# @See https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups#ResourceGroups_CreateOrUpdate
#
def create_resource_group(resource_group_name, location)
url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url += "/resourceGroups/#{URI.escape(resource_group_name)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
url += "/resourceGroups/#{uri_escape(resource_group_name)}"

resource_group = {
'name' => resource_group_name,
Expand All @@ -202,8 +202,8 @@ def create_resource_group(resource_group_name, location)
def get_resource_group(resource_group_name)
resource_group = nil

url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url += "/resourceGroups/#{URI.escape(resource_group_name)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
url += "/resourceGroups/#{uri_escape(resource_group_name)}"
result = get_resource_by_id(url)

unless result.nil?
Expand Down Expand Up @@ -453,7 +453,7 @@ def create_virtual_machine(resource_group_name, vm_params, network_interfaces, a
#
def list_available_virtual_machine_sizes_by_location(location)
vm_sizes = []
url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
url += "/providers/#{REST_API_PROVIDER_COMPUTE}"
url += "/locations/#{location}"
url += "/#{REST_API_VM_SIZES}"
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def delete_managed_snapshot(resource_group_name, name)
#
def list_platform_image_versions(location, publisher, offer, sku)
images = []
url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
url += "/providers/#{REST_API_PROVIDER_COMPUTE}"
url += "/locations/#{location}"
url += "/publishers/#{publisher}"
Expand Down Expand Up @@ -1831,7 +1831,7 @@ def create_storage_account(name, location, sku, kind, tags)
# https://github.com/Azure/azure-rest-api-specs/blob/master/specification/storage/resource-manager/Microsoft.Storage/stable/2016-01-01/storage.json
#
def check_storage_account_name_availability(name)
url = "/subscriptions/#{URI.escape(@azure_config.subscription_id)}"
url = "/subscriptions/#{uri_escape(@azure_config.subscription_id)}"
url += "/providers/#{REST_API_PROVIDER_STORAGE}"
url += '/checkNameAvailability'
storage_account = {
Expand Down
4 changes: 4 additions & 0 deletions src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,9 @@ def validate_idle_timeout(idle_timeout_in_minutes)
cloud_error('Minimum idle_timeout_in_minutes is 4 minutes') if idle_timeout_in_minutes < 4
cloud_error('Maximum idle_timeout_in_minutes is 30 minutes') if idle_timeout_in_minutes > 30
end

def uri_escape(raw_uri)
CGI.escape(raw_uri).sub("%2F", "/")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@

it 'encodes the password with special characters in the registry URL' do
registry_uri = URI(subject['cloud']['properties']['registry']['endpoint'])
expect(URI.decode(registry_uri.password)).to eq(special_chars_password)
expect(URI.decode_www_form_component(registry_uri.password)).to eq(special_chars_password)
end
end

Expand Down

0 comments on commit 759ad8f

Please sign in to comment.