Initial Chef repository
This commit is contained in:
43
cookbooks/packagecloud/libraries/helper.rb
Normal file
43
cookbooks/packagecloud/libraries/helper.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'net/https'
|
||||
|
||||
module PackageCloud
|
||||
module Helper
|
||||
def get(uri, params)
|
||||
uri.query = URI.encode_www_form(params)
|
||||
req = Net::HTTP::Get.new(uri.request_uri)
|
||||
|
||||
req.basic_auth uri.user, uri.password if uri.user
|
||||
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
http.use_ssl = true
|
||||
|
||||
resp = http.start { |h| h.request(req) }
|
||||
|
||||
case resp
|
||||
when Net::HTTPSuccess
|
||||
resp
|
||||
else
|
||||
raise resp.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def post(uri, params)
|
||||
req = Net::HTTP::Post.new(uri.request_uri)
|
||||
req.form_data = params
|
||||
|
||||
req.basic_auth uri.user, uri.password if uri.user
|
||||
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
http.use_ssl = true
|
||||
|
||||
resp = http.start { |h| h.request(req) }
|
||||
|
||||
case resp
|
||||
when Net::HTTPSuccess
|
||||
resp
|
||||
else
|
||||
raise resp.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
7
cookbooks/packagecloud/libraries/matcher.rb
Normal file
7
cookbooks/packagecloud/libraries/matcher.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
if defined?(ChefSpec)
|
||||
|
||||
def create_packagecloud_repo(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:packagecloud_repo, :add, resource_name)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user