openshift/3scale_backend.conf
#!/usr/bin/env ruby
def parse_int_env(env_name)
env_var = ENV[env_name]
!env_var.nil? && !env_var.empty? ? env_var.to_i : nil
end
def parse_boolean_env(env_name)
value = ENV[env_name]
value == '1'.freeze || value&.downcase == 'true'.freeze
end
# Returns the request loggers as an array of symbols.
# For example: [:text, :json]
def parse_request_loggers
Array(ENV['CONFIG_REQUEST_LOGGERS']).flat_map do |s|
s.split(',').map(&:strip).reject(&:empty?).uniq.map(&:to_sym)
end
end
ThreeScale::Backend.configure do |config|
config.internal_api.user = "#{ENV['CONFIG_INTERNAL_API_USER']}"
config.internal_api.password = "#{ENV['CONFIG_INTERNAL_API_PASSWORD']}"
config.queues.master_name = "#{ENV['CONFIG_QUEUES_MASTER_NAME']}"
config.queues.username = "#{ENV['CONFIG_QUEUES_USERNAME']}"
config.queues.password = "#{ENV['CONFIG_QUEUES_PASSWORD']}"
config.queues.ssl = parse_boolean_env('CONFIG_QUEUES_SSL')
config.queues.ssl_params = {
ca_file: "#{ENV['CONFIG_QUEUES_CA_FILE']}",
cert: "#{ENV['CONFIG_QUEUES_CERT']}",
key: "#{ENV['CONFIG_QUEUES_PRIVATE_KEY']}"
}
config.queues.sentinels = "#{ENV['CONFIG_QUEUES_SENTINEL_HOSTS'] && !ENV['CONFIG_QUEUES_SENTINEL_HOSTS'].empty? ? ENV['CONFIG_QUEUES_SENTINEL_HOSTS'] : ENV['SENTINEL_HOSTS']}"
config.queues.sentinel_username = "#{ENV['CONFIG_QUEUES_SENTINEL_USERNAME']}"
config.queues.sentinel_password = "#{ENV['CONFIG_QUEUES_SENTINEL_PASSWORD']}"
config.queues.role = "#{ENV['CONFIG_QUEUES_SENTINEL_ROLE']}".to_sym
config.queues.connect_timeout = parse_int_env('CONFIG_QUEUES_CONNECT_TIMEOUT')
config.queues.read_timeout = parse_int_env('CONFIG_QUEUES_READ_TIMEOUT')
config.queues.write_timeout = parse_int_env('CONFIG_QUEUES_WRITE_TIMEOUT')
config.queues.max_connections = parse_int_env('CONFIG_QUEUES_MAX_CONNS')
config.redis.proxy = "#{ENV['CONFIG_REDIS_PROXY']}"
config.redis.username = "#{ENV['CONFIG_REDIS_USERNAME']}"
config.redis.password = "#{ENV['CONFIG_REDIS_PASSWORD']}"
config.redis.ssl = parse_boolean_env('CONFIG_REDIS_SSL')
config.redis.ssl_params = {
ca_file: "#{ENV['CONFIG_REDIS_CA_FILE']}",
cert: "#{ENV['CONFIG_REDIS_CERT']}",
key: "#{ENV['CONFIG_REDIS_PRIVATE_KEY']}"
}
config.redis.sentinels = "#{ENV['CONFIG_REDIS_SENTINEL_HOSTS']}"
config.redis.sentinel_username = "#{ENV['CONFIG_REDIS_SENTINEL_USERNAME']}"
config.redis.sentinel_password = "#{ENV['CONFIG_REDIS_SENTINEL_PASSWORD']}"
config.redis.role = "#{ENV['CONFIG_REDIS_SENTINEL_ROLE']}".to_sym
config.redis.connect_timeout = parse_int_env('CONFIG_REDIS_CONNECT_TIMEOUT')
config.redis.read_timeout = parse_int_env('CONFIG_REDIS_READ_TIMEOUT')
config.redis.write_timeout = parse_int_env('CONFIG_REDIS_WRITE_TIMEOUT')
config.redis.max_connections = parse_int_env('CONFIG_REDIS_MAX_CONNS')
config.redis.async = parse_boolean_env('CONFIG_REDIS_ASYNC')
config.notification_batch = "#{ENV['CONFIG_NOTIFICATION_BATCH']}"
config.log_path = "#{ENV['CONFIG_LOG_PATH']}"
config.master_service_id = "#{ENV['CONFIG_MASTER_SERVICE_ID']}"
config.master.metrics.transactions = "#{ENV['CONFIG_MASTER_METRICS_TRANSACTIONS']}"
config.master.metrics.transactions_authorize = "#{ENV['CONFIG_MASTER_METRICS_TRANSACTIONS_AUTHORIZE']}"
config.hoptoad.service = ENV['CONFIG_HOPTOAD_SERVICE'] ? "#{ENV['CONFIG_HOPTOAD_SERVICE']}" : nil
config.hoptoad.api_key = "#{ENV['CONFIG_HOPTOAD_API_KEY']}"
config.events_hook = "#{ENV['CONFIG_EVENTS_HOOK']}"
config.events_hook_shared_secret = "#{ENV['CONFIG_EVENTS_HOOK_SHARED_SECRET']}"
config.workers_log_file = "#{ENV['CONFIG_WORKERS_LOG_FILE']}"
config.request_loggers = parse_request_loggers
config.workers_logger_formatter = "#{ENV['CONFIG_WORKERS_LOGGER_FORMATTER']}".to_sym
config.worker_prometheus_metrics.enabled = parse_boolean_env('CONFIG_WORKER_PROMETHEUS_METRICS_ENABLED')
config.worker_prometheus_metrics.port = ENV['CONFIG_WORKER_PROMETHEUS_METRICS_PORT']
config.async_worker.max_concurrent_jobs = parse_int_env('CONFIG_ASYNC_WORKER_MAX_CONCURRENT_JOBS')
config.async_worker.max_pending_jobs = parse_int_env('CONFIG_ASYNC_WORKER_MAX_PENDING_JOBS')
config.async_worker.seconds_before_fetching_more = parse_int_env('CONFIG_ASYNC_WORKER_WAIT_SECONDS_FETCHING')
config.legacy_referrer_filters = parse_boolean_env('CONFIG_LEGACY_REFERRER_FILTERS')
config.opentelemetry.enabled = parse_boolean_env('CONFIG_OPENTELEMETRY_ENABLED')
end