From d2d168cd57d9a65ecf771f9e7da5ce50819b1de0 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Fri, 25 Nov 2022 21:31:39 -0600 Subject: [PATCH] fix REDIS_URL unix socket path parsing for relative paths --- .env.development | 3 ++- .env.test | 2 +- lib/mastodon/redis_config.rb | 19 ++++++++++++++++++- streaming/index.js | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.env.development b/.env.development index 1a11e918ef..0629bf94ce 100644 --- a/.env.development +++ b/.env.development @@ -1,6 +1,7 @@ LOCAL_DOMAIN=localhost +ALTERNATE_DOMAINS=mastodon.internal DB_HOST=$(pwd)/data/postgres DB_USER=mastodon DB_NAME=mastodon_dev -REDIS_URL=redis://$(pwd)/data/redis/redis-dev.sock +REDIS_URL=unix://./data/redis/redis-dev.sock diff --git a/.env.test b/.env.test index e3706868ca..1cfc25119a 100644 --- a/.env.test +++ b/.env.test @@ -7,4 +7,4 @@ LOCAL_HTTPS=true DB_HOST=$(pwd)/data/postgres DB_USER=mastodon DB_NAME=mastodon_dev -REDIS_URL=redis://$(pwd)/data/redis/redis-test.sock +REDIS_URL=unix://./data/redis/redis-dev.sock diff --git a/lib/mastodon/redis_config.rb b/lib/mastodon/redis_config.rb index 98dc4788d1..4220d832d4 100644 --- a/lib/mastodon/redis_config.rb +++ b/lib/mastodon/redis_config.rb @@ -1,10 +1,27 @@ # frozen_string_literal: true +require 'pathname' + def setup_redis_env_url(prefix = nil, defaults = true) prefix = prefix.to_s.upcase + '_' unless prefix.nil? prefix = '' if prefix.nil? - return if ENV[prefix + 'REDIS_URL'].present? + if ENV["#{prefix}REDIS_URL"].present? + conn = +ENV["#{prefix}REDIS_URL"].sub(/redis:\/\//i, '') + + unix = !!conn.sub!(/^unix:\/\//i, '') + unix |= conn.sub!(/^(\.\/)+/, '') + unix |= conn.start_with?('/') + + ENV["#{prefix}REDIS_URL"] = begin + pn = Pathname.new(conn) + pn = Pathname.getwd / pn if pn.relative? + + "unix://#{pn}" + end if unix + + return + end password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults } host = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults } diff --git a/streaming/index.js b/streaming/index.js index cecb53ed5b..b09e7e6b6d 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -18,7 +18,7 @@ const env = process.env.NODE_ENV || 'development'; const alwaysRequireAuth = process.env.LIMITED_FEDERATION_MODE === 'true' || process.env.WHITELIST_MODE === 'true' || process.env.AUTHORIZED_FETCH === 'true'; dotenv.config({ - path: env === 'production' ? '.env.production' : '.env', + path: env === 'production' || env === 'development' ? `.env.${env}` : '.env', }); log.level = process.env.LOG_LEVEL || 'verbose';