certificate.rb 631 Bytes
class Lxd::Certificate
	include ActiveModel::Model

	def save(host, certificate)
		all = Array.new;

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

		request = Net::HTTP::Post.new(uri.request_uri)
		request.body = {
			:type => 'client',
			:name => 'foo',
			:password => '[where to get this from....]'
		}.to_json
		response = http.request(request)

		response.code
	end
end
# vim: set ts=2 sw=2: