Commit ca971539aa9d979d5dde3861c94c1cd1ec0904c6

Authored by Georg Hopp
1 parent 3225dd51

add certificate if untrusted

@@ -3,6 +3,11 @@ class DashboardController < ApplicationController @@ -3,6 +3,11 @@ class DashboardController < ApplicationController
3 @lxd_host = LxdHost.find(1) 3 @lxd_host = LxdHost.find(1)
4 @cert = Certificate.find(1) 4 @cert = Certificate.find(1)
5 @lxd = Lxd::Server.by_host @lxd_host, @cert 5 @lxd = Lxd::Server.by_host @lxd_host, @cert
  6 +
  7 + if @lxd.auth == 'untrusted'
  8 + Lxd::Certificate.new.save(@lxd_host, @cert)
  9 + @lxd = Lxd::Server.by_host @lxd_host, @cert
  10 + end
6 end 11 end
7 end 12 end
8 # vim: set et ts=2 sw=2: 13 # vim: set et ts=2 sw=2:
  1 +class Lxd::Certificate
  2 + include ActiveModel::Model
  3 +
  4 + def save(host, certificate)
  5 + all = Array.new;
  6 +
  7 + uri = URI.parse(host.uri + '/1.0/certificates')
  8 + http = Net::HTTP.new(uri.host, uri.port)
  9 + http.use_ssl = true
  10 + http.cert = OpenSSL::X509::Certificate.new(certificate.cert)
  11 + http.key = OpenSSL::PKey::RSA.new(certificate.key)
  12 + http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  13 +
  14 + request = Net::HTTP::Post.new(uri.request_uri)
  15 + request.body = {
  16 + :type => 'client',
  17 + :name => 'foo',
  18 + :password => '[where to get this from....]'
  19 + }.to_json
  20 + response = http.request(request)
  21 +
  22 + response.code
  23 + end
  24 +end
  25 +# vim: set ts=2 sw=2:
@@ -12,7 +12,7 @@ api_base_uri = 'https://192.168.30.1:8443/' @@ -12,7 +12,7 @@ api_base_uri = 'https://192.168.30.1:8443/'
12 cert = File.read(File.dirname(__FILE__) + '/client.crt') 12 cert = File.read(File.dirname(__FILE__) + '/client.crt')
13 key = File.read(File.dirname(__FILE__) + '/client.key') 13 key = File.read(File.dirname(__FILE__) + '/client.key')
14 14
15 -uri = URI.parse(api_base_uri + '1.0') 15 +uri = URI.parse(api_base_uri + '1.0/certificates')
16 http = Net::HTTP.new(uri.host, uri.port) 16 http = Net::HTTP.new(uri.host, uri.port)
17 http.use_ssl = true 17 http.use_ssl = true
18 http.cert = OpenSSL::X509::Certificate.new(cert) 18 http.cert = OpenSSL::X509::Certificate.new(cert)
Please register or login to post a comment