Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created April 21, 2016 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/58e63a1fafdda3761106b41569a988d8 to your computer and use it in GitHub Desktop.
Save anonymous/58e63a1fafdda3761106b41569a988d8 to your computer and use it in GitHub Desktop.
# Pastebin JZkBjUFr
uri = URI.parse("https://secure.com/")
pem = File.read("/path/to/my.pem")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(pem)
http.key = OpenSSL::PKey::RSA.new(pem)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
@flaf
Copy link

flaf commented Apr 21, 2016

I got it:

#!/opt/puppetlabs/puppet/bin/ruby

require 'net/http'
require 'openssl'
require 'json'

cert    = File.read('/etc/puppetlabs/puppet/ssl/certs/puppet.athome.priv.pem')
privkey = File.read('/etc/puppetlabs/puppet/ssl/private_keys/puppet.athome.priv.pem')
ca_file = '/etc/puppetlabs/puppet/ssl/certs/ca.pem'

query  = 'resources[parameters, certname]{ title = "Puppetserver::Params" and type = "Class" }'
params = { :query => query }

uri       = URI('https://puppet.athome.priv:8081/pdb/query/v4')
uri.query = URI.encode_www_form(params)

Net::HTTP.start(
  uri.host, uri.port,
  :use_ssl     => uri.scheme == 'https',
  :cert        => OpenSSL::X509::Certificate.new(cert),
  :key         => OpenSSL::PKey.read(privkey),
  :ca_file     => ca_file,
  :verify_mode => OpenSSL::SSL::VERIFY_PEER,
) do |http|

  request  = Net::HTTP::Get.new(uri)
  response = http.request request

  p JSON.parse(response.body)

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment