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 URI.escape deprecation warning #911

Merged
merged 3 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion lib/puppet/functions/foreman/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#
# Happy Foreman API-ing!

require "cgi"
require "yaml"
require "net/http"
require "net/https"
Expand All @@ -61,7 +62,7 @@ def foreman(item, search, per_page = "20", foreman_url = "https://localhost", fo
raise Puppet::ParseError, "Foreman: Invalid filter_result: #{filter_result}, must not be boolean true" if filter_result == true

begin
path = URI.escape("/api/#{item}?search=#{search}&per_page=#{per_page}")
path = "/api/#{CGI.escape(item)}?search=#{CGI.escape(search)}&per_page=#{CGI.escape(per_page)}"

req = Net::HTTP::Get.new(path)
req['Content-Type'] = 'application/json'
Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/functions/foreman/smartvar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Foreman holds all the value names and their possible values,
# this function simply ask foreman for the right value for this host.

require "cgi"
require "net/http"
require "net/https"
require "uri"
Expand All @@ -15,15 +16,15 @@
optional_param 'String', :foreman_pass
end

def smartvar(var, foreman_url = "http://foreman", foreman_user = "admin", foreman_pass = "changeme")
def smartvar(var, foreman_url = "http://foreman", foreman_user = "admin", foreman_pass = "changeme")
scope = closure_scope
fqdn = scope['facts']['fqdn']

uri = URI.parse(foreman_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'

path = URI.escape("/hosts/#{fqdn}/lookup_keys/#{var}")
path = "/hosts/#{CGI.escape(fqdn)}/lookup_keys/#{CGI.escape(var)}"
req = Net::HTTP::Get.new(path)
req.basic_auth(foreman_user, foreman_pass)
req['Content-Type'] = 'application/json'
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/parser/functions/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#
# Happy Foreman API-ing!

require "cgi"
require "yaml"
require "net/http"
require "net/https"
Expand Down Expand Up @@ -65,7 +66,7 @@ module Puppet::Parser::Functions
raise Puppet::ParseError, "Foreman: Invalid filter_result: #{filter_result}, must be a String or an Array" unless filter_result.is_a? String or filter_result.is_a? Array or filter_result.is_a? Hash or filter_result == false

begin
path = URI.escape("/api/#{item}?search=#{search}&per_page=#{per_page}")
path = "/api/#{CGI.escape(item)}?search=#{CGI.escape(search)}&per_page=#{CGI.escape(per_page)}"

req = Net::HTTP::Get.new(path)
req['Content-Type'] = 'application/json'
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/parser/functions/smartvar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# this function simply ask foreman for the right value for this host.


require "cgi"
require "net/http"
require "net/https"
require "uri"
Expand All @@ -24,7 +25,7 @@ module Puppet::Parser::Functions
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'

path = URI.escape("/hosts/#{fqdn}/lookup_keys/#{var}")
path = "/hosts/#{CGI.escape(fqdn)}/lookup_keys/#{CGI.escape(var)}"
req = Net::HTTP::Get.new(path)
req.basic_auth(foreman_user, foreman_pass)
req['Content-Type'] = 'application/json'
Expand Down
7 changes: 4 additions & 3 deletions lib/puppet/provider/foreman_resource/rest_v3.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Base provider for other Puppet types managing Foreman resources
#
# This provider uses Net::HTTP from Ruby stdlib, JSON (stdlib on 1.9+ or the
# gem on 1.8) and the oauth gem for auth, so requiring minimal dependencies.
# This provider uses Net::HTTP from Ruby stdlib, JSON and the oauth gem for
# auth, so requiring minimal dependencies.

require 'cgi'
require 'uri'

Puppet::Type.type(:foreman_resource).provide(:rest_v3) do
Expand Down Expand Up @@ -59,7 +60,7 @@ def request(method, path, params = {}, data = nil, headers = {})
base_url += '/' unless base_url.end_with?('/')

uri = URI.join(base_url, path)
uri.query = params.map { |p,v| "#{URI.escape(p.to_s)}=#{URI.escape(v.to_s)}" }.join('&') unless params.empty?
uri.query = params.map { |p,v| "#{CGI.escape(p.to_s)}=#{CGI.escape(v.to_s)}" }.join('&') unless params.empty?

headers = {
'Accept' => 'application/json',
Expand Down