7 changed files with 83 additions and 60 deletions
-
29app/controllers/application_controller.rb
-
6app/controllers/dashboard_controller.rb
-
5app/controllers/hosts_controller.rb
-
41app/models/certificate.rb
-
41app/models/host.rb
-
6app/models/lxd/api.rb
-
13app/views/dashboard/index.html.erb
@ -1,18 +1,14 @@ |
|||||
class DashboardController < ApplicationController |
class DashboardController < ApplicationController |
||||
def index |
def index |
||||
check_cert |
|
||||
@hosts = Host.all |
@hosts = Host.all |
||||
|
|
||||
@hosts.map { |host| |
@hosts.map { |host| |
||||
host.cert = @cert |
|
||||
if host.config.auth == 'untrusted' |
|
||||
|
if host.lxd_config.auth == 'untrusted' |
||||
session[:return_to] = request.env["REQUEST_URI"] |
session[:return_to] = request.env["REQUEST_URI"] |
||||
redirect_to controller: 'hosts', action: 'auth', id: host.id |
redirect_to controller: 'hosts', action: 'auth', id: host.id |
||||
return |
return |
||||
end |
end |
||||
} |
} |
||||
|
|
||||
@certificates = Lxd::Certificate.all @hosts.first.api |
|
||||
end |
end |
||||
end |
end |
||||
# vim: set et ts=2 sw=2: |
# vim: set et ts=2 sw=2: |
||||
@ -1,14 +1,43 @@ |
|||||
class Host < ActiveRecord::Base |
class Host < ActiveRecord::Base |
||||
def cert=(cert) |
|
||||
@cert = cert |
|
||||
end |
|
||||
|
belongs_to :certificate |
||||
|
|
||||
def api |
|
||||
Lxd::API.get self, @cert |
|
||||
|
def certificate |
||||
|
# ensure that we always use a current, working non expired certificate. |
||||
|
case |
||||
|
when super.nil? |
||||
|
self.certificate_id = Certificate.get.id |
||||
|
self.save |
||||
|
super(true) |
||||
|
when super.expires_soon? |
||||
|
old = super |
||||
|
new = Certificate.get.update |
||||
|
Lxd::Certificate.new(api: api(old), certificate: new.to_s).add |
||||
|
self.certificate_id = new.id |
||||
|
self.save |
||||
|
@api = nil # enforce new api to get the new certificate used. |
||||
|
# finally remove the old certificate from lxd |
||||
|
Lxd::Certificate.new(api: api(new), fingerprint: old.cert_fpr).delete |
||||
|
super(true) |
||||
|
else |
||||
|
super |
||||
|
end |
||||
end |
end |
||||
|
|
||||
def config |
|
||||
|
def lxd_config |
||||
Lxd::Config.get api |
Lxd::Config.get api |
||||
end |
end |
||||
|
|
||||
|
def lxd_certificates |
||||
|
Lxd::Certificate.all api |
||||
|
end |
||||
|
|
||||
|
def lxd_authenticate password |
||||
|
Lxd::Certificate.new(api: api).add password |
||||
|
end |
||||
|
|
||||
|
private |
||||
|
def api certificate = nil |
||||
|
@api ||= Lxd::API.get self, certificate |
||||
|
end |
||||
end |
end |
||||
# vim: ts=2 sw=2: |
# vim: ts=2 sw=2: |
||||
@ -1,9 +1,12 @@ |
|||||
<h1>Dashboard#index</h1> |
<h1>Dashboard#index</h1> |
||||
<p><%= @cert.cert_fpr %></p> |
|
||||
<p>Serial: <%= @cert.cert.serial %></p> |
|
||||
|
<% Certificate.all.each do |cert| -%> |
||||
|
<p>Fingerprint: <%= cert.cert_fpr %> |
||||
|
Serial: <%= cert.cert.serial %></p> |
||||
|
<% end -%> |
||||
|
<hr/> |
||||
<% @hosts.each do |host| -%> |
<% @hosts.each do |host| -%> |
||||
<p><%= host.config.inspect %></p> |
|
||||
|
<p><%= host.lxd_config.inspect %></p> |
||||
|
<% host.lxd_certificates.each do |certificate| -%> |
||||
|
<p><%= certificate.fingerprint %></p> |
||||
<% end -%> |
<% end -%> |
||||
<% @certificates.each do |cert| -%> |
|
||||
<p><%= cert.fingerprint %></p> |
|
||||
<% end -%> |
<% end -%> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue