diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index dc3e4a4..cad83ba 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -3,6 +3,11 @@ class DashboardController < ApplicationController @lxd_host = LxdHost.find(1) @cert = Certificate.find(1) @lxd = Lxd::Server.by_host @lxd_host, @cert + + if @lxd.auth == 'untrusted' + Lxd::Certificate.new.save(@lxd_host, @cert) + @lxd = Lxd::Server.by_host @lxd_host, @cert + end end end # vim: set et ts=2 sw=2: diff --git a/app/models/lxd/certificate.rb b/app/models/lxd/certificate.rb new file mode 100644 index 0000000..6f1748f --- /dev/null +++ b/app/models/lxd/certificate.rb @@ -0,0 +1,25 @@ +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: diff --git a/doc/test.rb b/doc/test.rb index 2c7d7bf..10d4c5c 100644 --- a/doc/test.rb +++ b/doc/test.rb @@ -12,7 +12,7 @@ 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') +uri = URI.parse(api_base_uri + '1.0/certificates') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.cert = OpenSSL::X509::Certificate.new(cert)