Skip to content

Commit

Permalink
Merge pull request #3036 from bitzesty/env-var-changes
Browse files Browse the repository at this point in the history
chore: ENV var changes for new platform
  • Loading branch information
dreamfall authored Aug 14, 2024
2 parents 667ba52 + e4b268d commit e8a4342
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/healthcheck_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def check_cache
end

def check_redis
Redis.new(url: PaasResolver.redis_uri).ping
Redis.new(url: CredentialsResolver.redis_uri).ping
{ success: true }
rescue => e
{ success: false, message: e.message }
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ test:

production:
<<: *default
url: <%= PaasResolver.pgsql_uri %>
url: <%= CredentialsResolver.pgsql_uri %>
pool: <%= ENV['DB_POOL'] || ENV['MAX_THREADS'] || 5 %>
4 changes: 2 additions & 2 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
config.logger = Appsignal::Logger.new("sidekiq")
config.logger.formatter = Sidekiq::Logger::Formatters::WithoutTimestamp.new

config.redis = { url: PaasResolver.redis_uri }
config.redis = { url: CredentialsResolver.redis_uri }
end

Sidekiq.configure_client do |config|
config.redis = { url: PaasResolver.redis_uri }
config.redis = { url: CredentialsResolver.redis_uri }
end
27 changes: 27 additions & 0 deletions lib/credentials_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module CredentialsResolver
module_function

def redis_uri
ENV["REDIS_ENDPOINT"].presence || JSON.parse(ENV["VCAP_SERVICES"])["redis"][0]["credentials"]["uri"]
rescue
ENV["REDIS_URL"]
end

def pgsql_uri
if ENV["DATABASE_CREDENTIALS"].present?
parse_database_config(ENV["DATABASE_CREDENTIALS"])
else
# Fallback to the original logic
JSON.parse(ENV["VCAP_SERVICES"])["postgres"][0]["credentials"]["uri"]
end
rescue
ENV["DATABASE_URL"]
end

def parse_database_config(config_json)
config = JSON.parse(config_json)

# Construct the database URI
"#{config["engine"]}://#{config["username"]}:#{config["password"]}@#{config["host"]}:#{config["port"]}/#{config["dbname"]}"
end
end
17 changes: 0 additions & 17 deletions lib/paas_resolver.rb

This file was deleted.

0 comments on commit e8a4342

Please sign in to comment.