Browse Source

add certificate if untrusted

master
Georg Hopp 10 years ago
parent
commit
ca971539aa
  1. 5
      app/controllers/dashboard_controller.rb
  2. 25
      app/models/lxd/certificate.rb
  3. 2
      doc/test.rb

5
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:

25
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:

2
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)

Loading…
Cancel
Save