test.rb 734 Bytes
require "net/http"
require "uri"
require "openssl"
require "json"
require "yaml"

# curl -k -E lxd-client.crt -X GET https://192.168.30.1:8443/1.0/
# where lxd-client contains both, cert and key.
#
api_base_uri = 'https://192.168.30.1:8443/'

cert = File.read(File.dirname(__FILE__) + '/client.crt')
key = File.read(File.dirname(__FILE__) + '/client.key')

uri = URI.parse(api_base_uri + '1.0')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(cert)
http.key = OpenSSL::PKey::RSA.new(key)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)

puts JSON.parse(response.body).to_yaml

# vim: set ts=2 sw=2: