Fix lint errors
This commit is contained in:
parent
dba544db71
commit
9fab7393f7
4
Gemfile
4
Gemfile
@ -1,7 +1,7 @@
|
|||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "sinatra"
|
gem "sinatra"
|
||||||
gem 'sinatra-contrib'
|
gem "sinatra-contrib"
|
||||||
gem "puma"
|
gem "puma"
|
||||||
gem "rackup"
|
gem "rackup"
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ gem "nanoid"
|
|||||||
gem "ulid"
|
gem "ulid"
|
||||||
gem "uuid7"
|
gem "uuid7"
|
||||||
|
|
||||||
gem 'jwt'
|
gem "jwt"
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem "ruby-lsp"
|
gem "ruby-lsp"
|
||||||
|
23
app.rb
23
app.rb
@ -15,7 +15,7 @@ require "jwt"
|
|||||||
|
|
||||||
SESSION_SECRET_HEX_LENGTH = 64
|
SESSION_SECRET_HEX_LENGTH = 64
|
||||||
|
|
||||||
set :session_secret, ENV.fetch('SESSION_SECRET') { SecureRandom.hex(SESSION_SECRET_HEX_LENGTH) }
|
set :session_secret, ENV.fetch("SESSION_SECRET") { SecureRandom.hex(SESSION_SECRET_HEX_LENGTH) }
|
||||||
|
|
||||||
CLK_TCK = 100
|
CLK_TCK = 100
|
||||||
PID_FILE_PATH = "/run/app/pid".freeze
|
PID_FILE_PATH = "/run/app/pid".freeze
|
||||||
@ -35,7 +35,7 @@ DURATION_PARTS = [
|
|||||||
[SECONDS_PER_DAY, "day", "d"],
|
[SECONDS_PER_DAY, "day", "d"],
|
||||||
[SECONDS_PER_HOUR, "hour", "h"],
|
[SECONDS_PER_HOUR, "hour", "h"],
|
||||||
[SECONDS_PER_MINUTE, "minute", "m"],
|
[SECONDS_PER_MINUTE, "minute", "m"],
|
||||||
[1, "second", "s"],
|
[1, "second", "s"]
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
JWT_SECRET = SecureRandom.bytes(64).freeze
|
JWT_SECRET = SecureRandom.bytes(64).freeze
|
||||||
@ -44,8 +44,8 @@ module Sinatra
|
|||||||
module RequestHeadersHelper
|
module RequestHeadersHelper
|
||||||
def req_headers
|
def req_headers
|
||||||
hash = request.env.select { |k, _| k.start_with? "HTTP_" }
|
hash = request.env.select { |k, _| k.start_with? "HTTP_" }
|
||||||
.collect { |k, v| [k.gsub(/^HTTP_/, "").gsub(/_/, "-").downcase, v] }
|
.collect { |k, v| [k.gsub(/^HTTP_/, "").tr("_", "-").downcase, v] }
|
||||||
.sort
|
.sort
|
||||||
h = Rack::Headers.new
|
h = Rack::Headers.new
|
||||||
h.merge hash
|
h.merge hash
|
||||||
end
|
end
|
||||||
@ -90,7 +90,7 @@ module UpDown
|
|||||||
def to_json(*_args)
|
def to_json(*_args)
|
||||||
return unless enabled?
|
return unless enabled?
|
||||||
|
|
||||||
JSON.generate({ "status" => "ok" })
|
JSON.generate({"status" => "ok"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ end
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
# content_type 'text/plain'
|
# content_type 'text/plain'
|
||||||
sleep(1) while Sleep.instance.asleep? unless request.path_info == "/livez/sleep"
|
sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/" do
|
get "/" do
|
||||||
@ -249,7 +249,7 @@ end
|
|||||||
|
|
||||||
get "/livez/uptime" do
|
get "/livez/uptime" do
|
||||||
tt = TickTock.new
|
tt = TickTock.new
|
||||||
x = { started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i) }
|
x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)}
|
||||||
json x
|
json x
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -304,16 +304,15 @@ post "/halt" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
get "/pid" do
|
get "/pid" do
|
||||||
JSON.generate({ puma: master_pid, pid: Process.pid })
|
JSON.generate({puma: master_pid, pid: Process.pid})
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/token" do
|
get "/token" do
|
||||||
exp = Time.now.to_i + SECONDS_PER_MINUTE * 2
|
exp = Time.now.to_i + SECONDS_PER_MINUTE * 2
|
||||||
payload = { name: "anonymous", exp: exp, jti: Random.uuid }
|
payload = {name: "anonymous", exp: exp, jti: Random.uuid}
|
||||||
expires_at = Time.at(exp).to_datetime
|
expires_at = Time.at(exp).to_datetime
|
||||||
token = JWT.encode payload, JWT_SECRET, "HS256"
|
token = JWT.encode payload, JWT_SECRET, "HS256"
|
||||||
token
|
x = {token: token, expires_at: expires_at}
|
||||||
x = { :token => token, :expires_at => expires_at }
|
|
||||||
json x
|
json x
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -330,7 +329,7 @@ end
|
|||||||
|
|
||||||
get "/session" do
|
get "/session" do
|
||||||
j = session.to_hash
|
j = session.to_hash
|
||||||
j[:hostname] = ENV['HOSTNAME']
|
j[:hostname] = ENV["HOSTNAME"]
|
||||||
json j
|
json j
|
||||||
end
|
end
|
||||||
|
|
||||||
|
10
app_test.rb
10
app_test.rb
@ -1,8 +1,8 @@
|
|||||||
ENV['APP_ENV'] = 'test'
|
ENV["APP_ENV"] = "test"
|
||||||
|
|
||||||
require './app'
|
require "./app"
|
||||||
require 'test/unit'
|
require "test/unit"
|
||||||
require 'rack/test'
|
require "rack/test"
|
||||||
|
|
||||||
class ToyTest < Test::Unit::TestCase
|
class ToyTest < Test::Unit::TestCase
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
@ -12,7 +12,7 @@ class ToyTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_root
|
def test_root
|
||||||
get '/'
|
get "/"
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal "hello there!\n", last_response.body
|
assert_equal "hello there!\n", last_response.body
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require 'bundler/setup'
|
require "bundler/setup"
|
||||||
require 'sinatra'
|
require "sinatra"
|
||||||
|
|
||||||
require './app'
|
require "./app"
|
||||||
|
|
||||||
run Sinatra::Application
|
run Sinatra::Application
|
@ -1,3 +1,3 @@
|
|||||||
# workers 3
|
# workers 3
|
||||||
pidfile '/run/app/pid'
|
pidfile "/run/app/pid"
|
||||||
preload_app!
|
preload_app!
|
||||||
|
Loading…
Reference in New Issue
Block a user