Skip to content

Commit 4dd0090

Browse files
committedDec 4, 2023
Initial commit
0 parents  commit 4dd0090

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
keys/
2+
.idea/

‎Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ruby '3.0.0'
2+
source 'https://rubygems.org'
3+
4+
gem 'puma'
5+
gem 'sinatra'

‎Gemfile.lock

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
mustermann (3.0.0)
5+
ruby2_keywords (~> 0.0.1)
6+
nio4r (2.7.0)
7+
puma (6.4.0)
8+
nio4r (~> 2.0)
9+
rack (2.2.8)
10+
rack-protection (3.1.0)
11+
rack (~> 2.2, >= 2.2.4)
12+
ruby2_keywords (0.0.5)
13+
sinatra (3.1.0)
14+
mustermann (~> 3.0)
15+
rack (~> 2.2, >= 2.2.4)
16+
rack-protection (= 3.1.0)
17+
tilt (~> 2.0)
18+
tilt (2.3.0)
19+
20+
PLATFORMS
21+
x86_64-linux
22+
23+
DEPENDENCIES
24+
puma
25+
sinatra
26+
27+
RUBY VERSION
28+
ruby 3.0.0p0
29+
30+
BUNDLED WITH
31+
2.4.13

‎app.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'openssl'
2+
require 'securerandom'
3+
require 'sinatra'
4+
5+
set :public_folder, __dir__ + '/static'
6+
7+
get '/' do
8+
@messages = []
9+
erb :index
10+
end
11+
12+
post '/deploy' do
13+
unless params[:key].is_a?(Hash) && !params[:key][:filename].nil? && !params[:key][:tempfile].nil?
14+
halt 400
15+
end
16+
17+
begin
18+
key = OpenSSL::PKey.read params[:key][:tempfile].read
19+
verified = Dir['keys/*'].any? do |filename|
20+
pubkey = OpenSSL::PKey.read File.read(filename)
21+
test_data = SecureRandom.alphanumeric(128)
22+
digest = OpenSSL::Digest::SHA256.new
23+
pubkey.verify(digest, key.sign(digest, test_data), test_data)
24+
end
25+
if verified
26+
pid = spawn '/var/apps/qpixel/deploy'
27+
Process.detach pid
28+
@status = true
29+
erb :index
30+
else
31+
@status = false
32+
@messages = ['Unrecognized key provided.']
33+
erb :index
34+
end
35+
rescue => ex
36+
@status = false
37+
@messages = [ex.message]
38+
erb :index
39+
end
40+
end

‎static/style.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.header--site-name {
2+
color: #333;
3+
margin: 0;
4+
}
5+
6+
.form-group {
7+
margin-bottom: 1em;
8+
}

‎views/index.erb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!doctype html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Deploy | Codidact</title>
6+
<link rel="stylesheet" href="https://unpkg.com/@codidact/co-design@latest/dist/codidact.css" />
7+
<link rel="stylesheet" href="style.css" />
8+
<script src="https://unpkg.com/@codidact/co-design@latest/js/co-design.js" defer></script>
9+
</head>
10+
<body>
11+
<header class="header">
12+
<div class="header--container container">
13+
<div class="header--brand">
14+
<h1 class="header--site-name">Deploy</h1>
15+
</div>
16+
</div>
17+
</header>
18+
19+
<main class="container has-padding-2">
20+
<% if !@status.nil? && !@status && !@messages.empty? %>
21+
<div class="notice is-danger has-color-red-900">
22+
<p>There were errors while trying to deploy:</p>
23+
<ul>
24+
<% @messages.each do |msg| %>
25+
<li><%= msg %></li>
26+
<% end %>
27+
</ul>
28+
</div>
29+
<% elsif !@status.nil? && @status %>
30+
<div class="notice is-success has-color-green-900">
31+
Deploy started successfully.
32+
</div>
33+
<% end %>
34+
<form method="post" action="/deploy" enctype="multipart/form-data">
35+
<div class="form-group">
36+
<label for="key" class="form-element">Select private key</label>
37+
<input type="file" name="key" id="key" />
38+
</div>
39+
<button type="submit" class="button is-green is-filled">Deploy</button>
40+
</form>
41+
</main>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.