Skip to content

Commit 37704eb

Browse files
Enhance public key update task with local URL handling and add usage instructions
1 parent 27e585c commit 37704eb

File tree

1 file changed

+13
-62
lines changed

1 file changed

+13
-62
lines changed

react_on_rails_pro/rakelib/public_key_management.rake

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace :react_on_rails_pro do
2121
# Determine the API URL based on the source
2222
api_url = case source
2323
when "local", "localhost"
24+
# Use the default local URL created by the Cloudflare Wrangler tool when the worker is run locally
2425
"http://localhost:8788/api/public-key"
2526
when "production", "prod"
2627
"https://www.shakacode.com/api/public-key"
@@ -55,6 +56,8 @@ namespace :react_on_rails_pro do
5556
exit 1
5657
end
5758

59+
# TODO: Add a prepublish check to ensure this key matches the latest public key from the API.
60+
# This should be implemented after publishing the API endpoint on the ShakaCode website.
5861
# Update Ruby public key file
5962
ruby_file_path = File.join(File.dirname(__FILE__), "..", "lib", "react_on_rails_pro", "license_public_key.rb")
6063
ruby_content = <<~RUBY.strip_heredoc
@@ -67,6 +70,11 @@ namespace :react_on_rails_pro do
6770
# and is never committed to the repository
6871
# Last updated: #{Time.now.utc.strftime("%Y-%m-%d %H:%M:%S UTC")}
6972
# Source: #{api_url}
73+
#
74+
# You can update this public key by running the rake task:
75+
# react_on_rails_pro:update_public_key
76+
# This task fetches the latest key from the API endpoint:
77+
# http://shakacode.com/api/public-key
7078
KEY = OpenSSL::PKey::RSA.new(<<~PEM.strip.strip_heredoc)
7179
#{public_key.strip}
7280
PEM
@@ -85,6 +93,11 @@ namespace :react_on_rails_pro do
8593
// and is never committed to the repository
8694
// Last updated: #{Time.now.utc.strftime("%Y-%m-%d %H:%M:%S UTC")}
8795
// Source: #{api_url}
96+
//
97+
// You can update this public key by running the rake task:
98+
// react_on_rails_pro:update_public_key
99+
// This task fetches the latest key from the API endpoint:
100+
// http://shakacode.com/api/public-key
88101
export const PUBLIC_KEY = `#{public_key.strip}`;
89102
TYPESCRIPT
90103

@@ -110,68 +123,6 @@ namespace :react_on_rails_pro do
110123
end
111124
end
112125

113-
desc "Verify the current public key configuration"
114-
task :verify_public_key do
115-
puts "Verifying public key configuration..."
116-
117-
begin
118-
# Load and check Ruby public key
119-
require "openssl"
120-
121-
# Need to define OpenSSL before loading the public key
122-
require_relative "../lib/react_on_rails_pro/license_public_key"
123-
ruby_key = ReactOnRailsPro::LicensePublicKey::KEY
124-
puts "✅ Ruby public key loaded successfully"
125-
puts " Key size: #{ruby_key.n.num_bits} bits"
126-
127-
# Check Node public key file exists
128-
node_file_path = File.join(File.dirname(__FILE__), "..", "packages", "node-renderer", "src", "shared", "licensePublicKey.ts")
129-
if File.exist?(node_file_path)
130-
node_content = File.read(node_file_path)
131-
if node_content.include?("BEGIN PUBLIC KEY")
132-
puts "✅ Node public key file exists and contains a public key"
133-
else
134-
puts "⚠️ Node public key file exists but may not contain a valid key"
135-
end
136-
else
137-
puts "❌ Node public key file not found: #{node_file_path}"
138-
end
139-
140-
# Try to validate with current license if one exists (simplified check without Rails)
141-
license_file = File.join(File.dirname(__FILE__), "..", "spec", "dummy", "config", "react_on_rails_pro_license.key")
142-
if ENV["REACT_ON_RAILS_PRO_LICENSE"] || File.exist?(license_file)
143-
puts "\n✅ License configuration detected"
144-
puts " ENV variable set" if ENV["REACT_ON_RAILS_PRO_LICENSE"]
145-
puts " Config file exists: #{license_file}" if File.exist?(license_file)
146-
147-
# Basic JWT validation test
148-
require "jwt"
149-
license = ENV["REACT_ON_RAILS_PRO_LICENSE"] || File.read(license_file).strip
150-
151-
begin
152-
payload, _header = JWT.decode(license, ruby_key, true, { algorithm: "RS256" })
153-
puts " ✅ License signature valid"
154-
puts " License email: #{payload['sub']}" if payload['sub']
155-
puts " Organization: #{payload['organization']}" if payload['organization']
156-
rescue JWT::ExpiredSignature
157-
puts " ⚠️ License expired"
158-
rescue JWT::DecodeError => e
159-
puts " ⚠️ License validation failed: #{e.message}"
160-
end
161-
else
162-
puts "\n⚠️ No license configured"
163-
puts " Set REACT_ON_RAILS_PRO_LICENSE env variable or create config/react_on_rails_pro_license.key"
164-
end
165-
rescue LoadError => e
166-
puts "❌ Failed to load required module: #{e.message}"
167-
puts " You may need to run 'bundle install' first"
168-
exit 1
169-
rescue StandardError => e
170-
puts "❌ Error during verification: #{e.message}"
171-
exit 1
172-
end
173-
end
174-
175126
desc "Show usage examples for updating the public key"
176127
task :public_key_help do
177128
puts <<~HELP

0 commit comments

Comments
 (0)