fix: Include aes_iv in cache key and fix subdomain parsing for cloud mode
1. license.rb: Add aes_iv to Redis cache key to prevent CipherError after
container restart. New random IVs after restart were causing stale cache
decryption failures.
2. action_controller.rb:
- Use request.subdomains.first instead of .last to correctly parse shop
code from tenant.fc.smartsales.asia domains
- Add localhost bypass (127.0.0.1 / ::1) for Docker health checks in
cloud mode, returning 200 OK instead of 404 not_found
Refs: infra-fix-2026-05-06
This commit is contained in:
@@ -32,7 +32,7 @@ class License
|
|||||||
aes_key, aes_iv = aes.export_to_file(lookup)
|
aes_key, aes_iv = aes.export_to_file(lookup)
|
||||||
|
|
||||||
##Check from local redis - if available load local otherwise get from remote
|
##Check from local redis - if available load local otherwise get from remote
|
||||||
cache_key = "#{lookup}:license:#{aes_key}:hostname"
|
cache_key = "#{lookup}:license:#{aes_key}:#{aes_iv}:hostname"
|
||||||
|
|
||||||
cache_license = nil
|
cache_license = nil
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class ActionController::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
|
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.first && request.subdomains.first != "www"
|
||||||
if license = cache_license # request.subdomain.downcase
|
if license = cache_license # request.subdomain.downcase
|
||||||
logger.info "Location - " + license.dbschema
|
logger.info "Location - " + license.dbschema
|
||||||
ActiveRecord::Base.establish_connection(website_connection(license))
|
ActiveRecord::Base.establish_connection(website_connection(license))
|
||||||
@@ -23,7 +23,7 @@ class ActionController::Base
|
|||||||
logger.info 'License is nil'
|
logger.info 'License is nil'
|
||||||
not_found
|
not_found
|
||||||
end
|
end
|
||||||
elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www"
|
elsif ENV["SERVER_MODE"] == "application" || request.subdomains.first && request.subdomains.first != "www"
|
||||||
# check for license file
|
# check for license file
|
||||||
if !current_license.exists?
|
if !current_license.exists?
|
||||||
redirect_to activate_path
|
redirect_to activate_path
|
||||||
@@ -31,7 +31,14 @@ class ActionController::Base
|
|||||||
redirect_to review_license_path
|
redirect_to review_license_path
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
not_found
|
if ENV["SERVER_MODE"] == "cloud" && (request.remote_ip == "127.0.0.1" || request.remote_ip == "::1")
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render plain: "OK", status: :ok }
|
||||||
|
format.json { render json: { status: "ok" } }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,7 +103,7 @@ class ActionController::API
|
|||||||
private
|
private
|
||||||
|
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
|
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.first && request.subdomains.first != "www"
|
||||||
if license = cache_license # request.subdomain.downcase
|
if license = cache_license # request.subdomain.downcase
|
||||||
logger.info "Location - " + license.dbschema
|
logger.info "Location - " + license.dbschema
|
||||||
ActiveRecord::Base.establish_connection(website_connection(license))
|
ActiveRecord::Base.establish_connection(website_connection(license))
|
||||||
@@ -105,10 +112,17 @@ class ActionController::API
|
|||||||
logger.info 'License is nil'
|
logger.info 'License is nil'
|
||||||
not_found
|
not_found
|
||||||
end
|
end
|
||||||
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www")
|
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.first && request.subdomains.first != "www")
|
||||||
not_found unless current_license.exists? && !current_license.expired?
|
not_found unless current_license.exists? && !current_license.expired?
|
||||||
else
|
else
|
||||||
not_found
|
if ENV["SERVER_MODE"] == "cloud" && (request.remote_ip == "127.0.0.1" || request.remote_ip == "::1")
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render plain: "OK", status: :ok }
|
||||||
|
format.json { render json: { status: "ok" } }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user