Skip to content

Commit

Permalink
Fix/bugs (expertiza#119)
Browse files Browse the repository at this point in the history
* Update json_web_token.rb

Convert keys to PEM format and save to the file

* Update setup.sh

Removing existing server PID file
  • Loading branch information
ameyagv authored Oct 7, 2024
1 parent c060103 commit 2e68f30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/json_web_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 2e68f30

Please sign in to comment.