Skip to content

Instantly share code, notes, and snippets.

@Vasu1105
Created December 10, 2015 15:12
Show Gist options
  • Save Vasu1105/ee247cd4e47fe7c7f697 to your computer and use it in GitHub Desktop.
Save Vasu1105/ee247cd4e47fe7c7f697 to your computer and use it in GitHub Desktop.
Gist of code changes & specs for the http url issue
diff --git a/lib/azure/rest.rb b/lib/azure/rest.rb
index 2135475..2b91068 100755
--- a/lib/azure/rest.rb
+++ b/lib/azure/rest.rb
@@ -36,8 +36,7 @@ module AzureAPI
services = true)
svc_str = services ? '/services' : ''
uri = URI.parse("#{@host_name}/#{@subscription_id}#{svc_str}/#{service_name}")
- scheme = !uri.scheme ? "https://" : ""
- request_url = "#{scheme}#{@host_name}/#{@subscription_id}#{svc_str}/#{service_name}"
+ request_url = "#{Rest.get_scheme_for_request_url(uri)}#{@host_name}/#{@subscription_id}#{svc_str}/#{service_name}"
print '.'
response = http_query(request_url, verb, body, params)
if response.code.to_i == 307
@@ -60,8 +59,7 @@ module AzureAPI
def query_for_completion()
uri = URI.parse("#{@host_name}/#{@subscription_id}/operations/#{@last_request_id}")
- scheme = !uri.scheme ? "https://" : ""
- request_url = "#{scheme}#{@host_name}/#{@subscription_id}/operations/#{@last_request_id}"
+ request_url = "#{Rest.get_scheme_for_request_url(uri)}#{@host_name}/#{@subscription_id}/operations/#{@last_request_id}"
response = http_query(request_url, 'get', '', '')
if response.code.to_i == 307
Chef::Log.debug "Redirect to #{response['Location']}"
@@ -117,5 +115,10 @@ module AzureAPI
puts "=== all of the headers ==="
puts response.each_header { |h, j| puts h.inspect + ' : ' + j.inspect}
end
+
+ private
+ def self.get_scheme_for_request_url(uri)
+ !uri.scheme ? "https://" : ""
+ end
end
end
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
new file mode 100644
index 0000000..dc0c7f7
--- /dev/null
+++ b/spec/unit/rest_spec.rb
@@ -0,0 +1,15 @@
+describe AzureAPI::Rest do
+
+ context 'get scheme for request url' do
+ it "should return https if there is no scheme present in the url" do
+ uri = URI.parse("management.core.windows.net")
+ expect(AzureAPI::Rest.get_scheme_for_request_url(uri)).to eq("https://")
+ end
+
+ it "should return blank string if scheme is present in the url" do
+ uri = URI.parse("https://management.core.windows.net")
+ expect(AzureAPI::Rest.get_scheme_for_request_url(uri)).to eq("")
+ end
+ end
+
+end
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment