Fix lint errors
All checks were successful
Gitea Actions Demo / lint (push) Successful in 1m19s
Gitea Actions Demo / test (push) Successful in 1m22s
Gitea Actions Demo / release-image (push) Successful in 1m0s

This commit is contained in:
Ryan Cavicchioni 2024-07-07 16:26:38 -05:00
parent dba544db71
commit 9fab7393f7
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
5 changed files with 23 additions and 24 deletions

View File

@ -1,7 +1,7 @@
source "https://rubygems.org"
gem "sinatra"
gem 'sinatra-contrib'
gem "sinatra-contrib"
gem "puma"
gem "rackup"
@ -11,7 +11,7 @@ gem "nanoid"
gem "ulid"
gem "uuid7"
gem 'jwt'
gem "jwt"
group :development do
gem "ruby-lsp"

23
app.rb
View File

@ -15,7 +15,7 @@ require "jwt"
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
PID_FILE_PATH = "/run/app/pid".freeze
@ -35,7 +35,7 @@ DURATION_PARTS = [
[SECONDS_PER_DAY, "day", "d"],
[SECONDS_PER_HOUR, "hour", "h"],
[SECONDS_PER_MINUTE, "minute", "m"],
[1, "second", "s"],
[1, "second", "s"]
].freeze
JWT_SECRET = SecureRandom.bytes(64).freeze
@ -44,8 +44,8 @@ module Sinatra
module RequestHeadersHelper
def req_headers
hash = request.env.select { |k, _| k.start_with? "HTTP_" }
.collect { |k, v| [k.gsub(/^HTTP_/, "").gsub(/_/, "-").downcase, v] }
.sort
.collect { |k, v| [k.gsub(/^HTTP_/, "").tr("_", "-").downcase, v] }
.sort
h = Rack::Headers.new
h.merge hash
end
@ -90,7 +90,7 @@ module UpDown
def to_json(*_args)
return unless enabled?
JSON.generate({ "status" => "ok" })
JSON.generate({"status" => "ok"})
end
end
@ -203,7 +203,7 @@ end
before do
# 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
get "/" do
@ -249,7 +249,7 @@ end
get "/livez/uptime" do
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
end
@ -304,16 +304,15 @@ post "/halt" do
end
get "/pid" do
JSON.generate({ puma: master_pid, pid: Process.pid })
JSON.generate({puma: master_pid, pid: Process.pid})
end
get "/token" do
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
token = JWT.encode payload, JWT_SECRET, "HS256"
token
x = { :token => token, :expires_at => expires_at }
x = {token: token, expires_at: expires_at}
json x
end
@ -330,7 +329,7 @@ end
get "/session" do
j = session.to_hash
j[:hostname] = ENV['HOSTNAME']
j[:hostname] = ENV["HOSTNAME"]
json j
end

View File

@ -1,8 +1,8 @@
ENV['APP_ENV'] = 'test'
ENV["APP_ENV"] = "test"
require './app'
require 'test/unit'
require 'rack/test'
require "./app"
require "test/unit"
require "rack/test"
class ToyTest < Test::Unit::TestCase
include Rack::Test::Methods
@ -12,7 +12,7 @@ class ToyTest < Test::Unit::TestCase
end
def test_root
get '/'
get "/"
assert last_response.ok?
assert_equal "hello there!\n", last_response.body
end

View File

@ -1,6 +1,6 @@
require 'bundler/setup'
require 'sinatra'
require "bundler/setup"
require "sinatra"
require './app'
require "./app"
run Sinatra::Application
run Sinatra::Application

View File

@ -1,3 +1,3 @@
# workers 3
pidfile '/run/app/pid'
pidfile "/run/app/pid"
preload_app!