hosts_controller.rb
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class HostsController < ApplicationController
before_action :set_host,
only: [:auth, :add_key, :show, :edit, :update, :destroy]
# GET /hosts
# GET /hosts.json
def index
@hosts = Host.all
end
# GET /hosts/1
# GET /hosts/1.json
def show
end
# GET /hosts/new
def new
@host = Host.new
end
# GET /hosts/1/edit
def edit
end
# GET /hosts/1/auth
def auth
end
# PATCH/PUT /hosts/1/add_key
def add_key
cert = Lxd::Certificate.new api: @host.api
cert.add params[:hosts][:password]
redirect_to session.delete(:return_to)
end
# POST /hosts
# POST /hosts.json
def create
@host = Host.new(host_params)
respond_to do |format|
if @host.save
format.html { redirect_to @host, notice: 'Host was successfully created.' }
format.json { render :show, status: :created, location: @host }
else
format.html { render :new }
format.json { render json: @host.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /hosts/1
# PATCH/PUT /hosts/1.json
def update
respond_to do |format|
if @host.update(host_params)
format.html { redirect_to @host, notice: 'Host was successfully updated.' }
format.json { render :show, status: :ok, location: @host }
else
format.html { render :edit }
format.json { render json: @host.errors, status: :unprocessable_entity }
end
end
end
# DELETE /hosts/1
# DELETE /hosts/1.json
def destroy
@host.destroy
respond_to do |format|
format.html { redirect_to hosts_url, notice: 'Host was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_host
check_cert
@host = Host.find(params[:id])
@host.cert = @cert
end
# Never trust parameters from the scary internet, only allow the white list through.
def host_params
params.require(:host).permit(:name, :uri, :password, :password_confirmation)
end
end
# vim: set et ts=2 sw=2: