Skip to content

Commit a81a249

Browse files
authored
Merge pull request #53 from alces-software/develop
Overware 1.2.1
2 parents dd90390 + f21208d commit a81a249

19 files changed

+296
-160
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
11.2. Create the user with `User.create(username: '<USERNAME HERE>', password: '<PASSWORD HERE>')`
6363

64-
12. Precompile assets using `RAILS_ENV=production bin/rails assets:precompile`
64+
12. Precompile assets using `rake assets:precompile`
6565

6666
13. Launch server using `bin/rails -s -p 80 -e production`
6767

app/assets/stylesheets/application.scss

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,3 @@ textarea {
5151
max-width: initial;
5252
max-width: max-content;
5353
}
54-
55-
.btn-bordered {
56-
border-style: solid;
57-
border-color: black;
58-
border-width: 1px;
59-
}
60-
61-
.bordered {
62-
border-style: solid;
63-
border-color: black;
64-
border-width: 1px;
65-
background-color: #2794d8;
66-
}

app/assets/stylesheets/assets.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
.parent-div {
1+
.relative-row {
22
position: relative;
3+
display: flex;
4+
flex-wrap: wrap;
35
}
46

57
.filter-bar {
68
position: absolute;
7-
top: 0;
9+
top: 10%;
810
right: 0;
911
}
1012

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
@import "bootstrap/functions";
2+
@import "bootstrap/variables";
3+
@import "bootstrap/mixins";
4+
@import "bootstrap/tables";
5+
6+
7+
.markdown {
8+
h1 {
9+
font-size: 1.75rem;
10+
.emoji-icon {
11+
width: 1.75rem;
12+
height: 1.75rem;
13+
}
14+
}
15+
16+
h2 {
17+
font-size: 1.25rem;
18+
.emoji-icon {
19+
width: 1.25rem;
20+
height: 1.25rem;
21+
}
22+
}
23+
24+
h3 {
25+
font-size: 1rem;
26+
.emoji-icon {
27+
width: 1rem;
28+
height: 1rem;
29+
}
30+
}
31+
32+
h4 {
33+
font-size: 0.75rem;
34+
.emoji-icon {
35+
width: 0.75rem;
36+
height: 0.75rem;
37+
}
38+
}
39+
40+
table {
41+
@extend .table;
42+
@extend .table-bordered;
43+
@extend .table-sm;
44+
width: unset;
45+
}
46+
47+
// thead {
48+
// @extend .thead-dark;
49+
// }
50+
51+
pre {
52+
display: block;
53+
color: #212529;
54+
background: #f0f0f0;
55+
padding: 5px;
56+
border-radius: 5px;
57+
}
58+
59+
code {
60+
color: #212529;
61+
word-break: break-word;
62+
background-color: #f0f0f0;
63+
padding: 3px;
64+
border-radius: 5px;
65+
}
66+
67+
pre code {
68+
word-break: break-all;
69+
white-space: pre-wrap;
70+
padding: 0;
71+
}
72+
73+
img {
74+
max-width: 100%;
75+
}
76+
77+
blockquote {
78+
padding: 0 1em;
79+
border-left: 0.25em solid #f0f0f0;
80+
}
81+
82+
table.rouge-table {
83+
border-radius: 5px;
84+
background: #f0f0f0;
85+
border: none;
86+
width: 100%;
87+
88+
pre {
89+
background: none;
90+
margin-bottom: 0;
91+
}
92+
93+
td:first-child {
94+
width: 40px;
95+
text-align: right;
96+
border-right: 1px solid #dee2e6;
97+
pre {
98+
font-style: italic;
99+
color: #999;
100+
font-size: 10px;
101+
line-height: 21px;
102+
}
103+
}
104+
105+
td, tr, tbody {
106+
border: none;
107+
}
108+
}
109+
}

app/controllers/application_controller.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
55
require 'open3'
66

77
helper_method :bolt_on_enabled
8+
helper_method :format_markdown
89

910
def authenticate(params)
1011
User.authenticate(
@@ -13,24 +14,28 @@ def authenticate(params)
1314
)
1415
end
1516

16-
# Deprecated and will be removed once run_global_script has been utilised
1717
def run_shell_command(command)
1818
system(command, out: File::NULL)
1919
end
2020

2121
def run_global_script(command, *args)
22-
Open3.capture3("bash #{ENV['ENTRYPOINT']} #{command} #{args.join(' ')}")
22+
out, err, sta = Open3.capture3(
23+
"bash #{ENV['ENTRYPOINT']} #{command} #{args.join(' ')}"
24+
)
25+
26+
return { output: out, error: err, status: sta }
2327
end
2428

2529
def bolt_on_enabled(name)
26-
BoltOn.find_by(name: name).enabled?
30+
bolt_on = BoltOn.find_by(name: name)
31+
bolt_on.nil? ? true : bolt_on.enabled?
2732
end
2833

2934
def redirect_unless_bolt_on(bolt_on)
3035
redirect_to root_path unless bolt_on_enabled(bolt_on)
3136
end
3237

33-
def render_as_markdown(html)
34-
CommonMarker.render_html(html, :DEFAULT, [:table])
38+
def format_markdown(text)
39+
MarkdownRenderer.render(text)
3540
end
3641
end

app/controllers/assets_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def single_asset
2424
asset_list.concat(value)
2525
end
2626

27-
parts[0] = render_as_markdown(parts[0])
28-
parts[2] = render_as_markdown(parts[2])
27+
parts[0] = format_markdown(parts[0])
28+
parts[2] = format_markdown(parts[2])
2929

3030
[parts[0], parts[2]].each do |p|
3131
p.scan(/[\w-]+/).each do |w|
@@ -37,7 +37,7 @@ def single_asset
3737

3838
@content = parts.reduce{ |a, b| a + b }
3939
else
40-
@content = render_as_markdown(@asset_data)
40+
@content = format_markdown(@asset_data)
4141
end
4242
end
4343

app/controllers/cluster_controller.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ def index
44
@vpn = {
55
enabled: bolt_on_enabled('VPN'),
66
status: vpn_status,
7-
name: vpn_name[0]
7+
name: vpn_name
88
}
99

1010
@content = appliance_information
1111
end
1212

1313
def restart
14-
if run_global_script(ENV['POWER_RESTART'])[2].success?
14+
if run_global_script(ENV['POWER_RESTART'])[:status].success?
1515
flash[:success] = 'Restarting machine'
1616
else
1717
flash[:danger] = 'Encountered an error whilst trying to restart the machine'
@@ -21,7 +21,7 @@ def restart
2121
end
2222

2323
def stop
24-
if run_global_script(ENV['POWER_OFF'])[2].success?
24+
if run_global_script(ENV['POWER_OFF'])[:status].success?
2525
flash[:success] = 'Stopping the machine'
2626
else
2727
flash[:danger] = 'Encountered an error whilst trying to stop the machine'
@@ -36,16 +36,14 @@ def appliance_information
3636
file = Rails.application.config.appliance_information
3737
file_data = IO.binread(file) if File.exist? file
3838

39-
if file_data
40-
render_as_markdown(file_data)
41-
end
39+
format_markdown(file_data)
4240
end
4341

4442
def vpn_status
45-
run_global_script(ENV['VPN_STATUS'])[2].success?
43+
run_global_script(ENV['VPN_STATUS'])[:status].success?
4644
end
4745

4846
def vpn_name
49-
run_global_script(ENV['VPN_NAME'])
47+
run_global_script(ENV['VPN_NAME'])[:output]
5048
end
5149
end

app/controllers/keys_controller.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def index
1010
end
1111

1212
def create
13-
if run_global_script(ENV['SSH_ADD'], ssh_keys, new_key)[2].success?
13+
if run_global_script(ENV['SSH_ADD'], ssh_keys, new_key)[:status].success?
1414
flash[:success] = 'SSH key successfully added'
1515
else
1616
flash[:danger] = 'Encountered an error whilst trying to add the SSH key'
@@ -20,7 +20,7 @@ def create
2020
end
2121

2222
def delete
23-
if run_global_script(ENV['SSH_REMOVE'], ssh_keys, "'#{params[:key]}'")[2].success?
23+
if run_global_script(ENV['SSH_REMOVE'], ssh_keys, "'#{params[:key]}'")[:status].success?
2424
flash[:success] = 'SSH key successfully removed'
2525
else
2626
flash[:danger] = 'Encountered an error whilst trying to remove the SSH key'
@@ -32,7 +32,11 @@ def delete
3232
private
3333

3434
def file_data
35-
run_global_script(ENV['SSH_GET'], ssh_keys)[0].lines.map
35+
if File.exist? ssh_keys
36+
run_global_script(ENV['SSH_GET'], ssh_keys)[:output].lines.map
37+
else
38+
"No SSH keys file defined"
39+
end
3640
end
3741

3842
def new_key

app/controllers/network_controller.rb

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,45 @@ def index
1111
def edit
1212
tmp = Tempfile.new("temp_vars")
1313

14-
file_data.each do |line|
15-
if line.include?("INTERNAL") || line.include?("EXTERNAL")
16-
content = line.split("=")
17-
variable = content[0].remove("export ")
18-
original_value = content[1].split('"')[1]
19-
20-
if original_value.empty?
21-
line = line.insert(line.index('"') + 1, network_params[variable])
22-
else
23-
line = line.sub original_value, network_params[variable]
14+
if File.exist? network_variables
15+
file_data.each do |line|
16+
if line.include?("INTERNAL") || line.include?("EXTERNAL")
17+
content = line.split("=")
18+
variable = content[0].remove("export ")
19+
original_value = content[1].split('"')[1]
20+
21+
if original_value.empty?
22+
line = line.insert(line.index('"') + 1, network_params[variable])
23+
else
24+
line = line.sub original_value, network_params[variable]
25+
end
2426
end
27+
28+
tmp << line
2529
end
2630

27-
tmp << line
28-
end
31+
tmp.close
2932

30-
tmp.close
31-
if run_shell_command("cp --no-preserve=mode,ownership #{tmp.path} #{network_variables}")
32-
out, err, status = run_global_script(ENV['NETWORK_SET'])
33-
if status.success?
34-
flash[:success] = 'Network configuration successfully modified'
33+
if run_shell_command("cp --no-preserve=mode,ownership #{tmp.path} #{network_variables}")
34+
if run_global_script(ENV['NETWORK_SET'])[:status].success?
35+
flash[:success] = 'Network configuration successfully modified'
36+
else
37+
flash[:danger] = 'Encountered an error whilst trying to run the setup script'
38+
end
3539
else
36-
flash[:danger] = 'Encountered an error whilst trying to run the setup script'
40+
flash[:danger] = 'Encountered an error whilst trying to modify the network configuration'
3741
end
42+
43+
tmp.delete
3844
else
39-
flash[:danger] = 'Encountered an error whilst trying to modify the network configuration'
45+
flash[:danger] = 'No network variables file defined'
4046
end
4147

42-
tmp.delete
43-
4448
redirect_to network_path
4549
end
4650

4751
def add_ssh_service
48-
if run_global_script(ENV['SSH_ENABLE'])[2].success?
52+
if run_global_script(ENV['SSH_ENABLE'])[:status].success?
4953
flash[:success] = 'SSH enabled on the external interface'
5054
else
5155
flash[:danger] = 'Encountered an error whilst trying to enable SSH'
@@ -55,7 +59,7 @@ def add_ssh_service
5559
end
5660

5761
def remove_ssh_service
58-
if run_global_script(ENV['SSH_DISABLE'])[2].success?
62+
if run_global_script(ENV['SSH_DISABLE'])[:status].success?
5963
flash[:success] = 'SSH disabled on the external interface'
6064
else
6165
flash[:danger] = 'Encountered an error whilst trying to disable SSH'
@@ -71,16 +75,15 @@ def network_params
7175
end
7276

7377
def network_get_output
74-
out, err, status = run_global_script(ENV['NETWORK_GET'])
75-
out.lines.map
78+
run_global_script(ENV['NETWORK_GET'])[:output].lines.map
7679
end
7780

7881
def network_show_output
79-
out, err, status = run_global_script(ENV['NETWORK_SHOW'])
80-
out.split("\n\n").map { |n| n.split("\n") }
82+
run_global_script(ENV['NETWORK_SHOW'])[:output].split("\n\n")
83+
.map { |n| n.split("\n") }
8184
end
8285

8386
def file_data
84-
IO.binread(Rails.application.config.network_variables).lines.map
87+
IO.binread(network_variables).lines.map
8588
end
8689
end

0 commit comments

Comments
 (0)