From 2e68f303f8c7a576991dae1d9f1b08fb1cd91cb6 Mon Sep 17 00:00:00 2001 From: Ameya Vaichalkar <57044378+ameyagv@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:59:49 -0400 Subject: [PATCH] Fix/bugs (#119) * Update json_web_token.rb Convert keys to PEM format and save to the file * Update setup.sh Removing existing server PID file --- lib/json_web_token.rb | 7 +++++-- setup.sh | 14 ++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/json_web_token.rb b/lib/json_web_token.rb index cca8051fb..356ec4719 100644 --- a/lib/json_web_token.rb +++ b/lib/json_web_token.rb @@ -5,14 +5,17 @@ class JsonWebToken RSA_KEYS_FILE = 'rsa_keys.yml'.freeze if File.exist?(RSA_KEYS_FILE) - rsa_keys = YAML.load_file(RSA_KEYS_FILE) + rsa_keys = YAML.load_file(RSA_KEYS_FILE, permitted_classes: [OpenSSL::PKey::RSA, String]) RSA_PRIVATE_KEY = OpenSSL::PKey::RSA.new(rsa_keys['private_key']) RSA_PUBLIC_KEY = OpenSSL::PKey::RSA.new(rsa_keys['public_key']) else rsa_key = OpenSSL::PKey::RSA.generate(2048) RSA_PRIVATE_KEY = rsa_key RSA_PUBLIC_KEY = rsa_key.public_key - File.write(RSA_KEYS_FILE, { 'private_key' => RSA_PRIVATE_KEY, 'public_key' => RSA_PUBLIC_KEY }.to_yaml) + File.write(RSA_KEYS_FILE, { + 'private_key' => RSA_PRIVATE_KEY.to_pem, + 'public_key' => RSA_PUBLIC_KEY.to_pem + }.to_yaml) end def self.encode(payload, exp = 24.hours.from_now) diff --git a/setup.sh b/setup.sh index 65e1a484c..c10d11f6f 100755 --- a/setup.sh +++ b/setup.sh @@ -7,18 +7,20 @@ do done echo "=== Running commands in the 'app' terminal ===" -echo "Step 1: Bundling dependencies..." +echo "Step 1: Removing existing server PID file if any..." +rm -f /app/tmp/pids/server.pid + +echo "Step 2: Bundling dependencies..." bundle install -echo "Step 2: Creating the database..." +echo "Step 3: Creating the database..." rake db:create -echo "Step 3: Running database migrations..." +echo "Step 4: Running database migrations..." rake db:migrate -echo "Step 4: Seeding the database..." +echo "Step 5: Seeding the database..." rake db:seed -echo "Step 5: Starting the Rails server..." +echo "Step 6: Starting the Rails server..." rails s -p 3002 -b '0.0.0.0' -