Don't expose the envvar values through `rqinfo -h`.

main
Vincent Driessen 11 years ago
parent e77b3e8a21
commit 3667e37ed3

@ -1,32 +1,29 @@
import os
import importlib import importlib
import redis import os
from functools import partial
from warnings import warn from warnings import warn
import redis
from first import first
from rq import use_connection from rq import use_connection
def add_standard_arguments(parser): def add_standard_arguments(parser):
parser.add_argument('--config', '-c', default=None, parser.add_argument('--config', '-c', default=None,
help='Module containing RQ settings.') help='Module containing RQ settings.')
parser.add_argument('--url', '-u', parser.add_argument('--url', '-u', default=None,
default=os.environ.get('RQ_REDIS_URL'),
help='URL describing Redis connection details. ' help='URL describing Redis connection details. '
'Overrides other connection arguments if ' 'Overrides other connection arguments if supplied.')
'supplied.') parser.add_argument('--host', '-H', default=None,
parser.add_argument('--host', '-H',
default=os.environ.get('RQ_REDIS_HOST', 'localhost'),
help='The Redis hostname (default: localhost)') help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', parser.add_argument('--port', '-p', default=None,
default=int(os.environ.get('RQ_REDIS_PORT', 6379)),
help='The Redis portnumber (default: 6379)') help='The Redis portnumber (default: 6379)')
parser.add_argument('--db', '-d', type=int, parser.add_argument('--db', '-d', type=int, default=None,
default=int(os.environ.get('RQ_REDIS_DB', 0)),
help='The Redis database (default: 0)') help='The Redis database (default: 0)')
parser.add_argument('--password', '-a', parser.add_argument('--password', '-a', default=None,
default=os.environ.get('RQ_REDIS_PASSWORD'),
help='The Redis password (default: None)') help='The Redis password (default: None)')
parser.add_argument('--socket', '-s', parser.add_argument('--socket', '-s', default=None,
default=os.environ.get('RQ_REDIS_SOCKET'),
help='The Redis Unix socket') help='The Redis Unix socket')
@ -40,31 +37,20 @@ def read_config_file(module):
def setup_default_arguments(args, settings): def setup_default_arguments(args, settings):
""" Sets up args from settings or defaults """ """ Sets up args from settings or defaults """
if args.url is None: args.url = first([args.url, settings.get('REDIS_URL'), os.environ.get('RQ_REDIS_URL')])
args.url = settings.get('REDIS_URL')
if (args.host or args.port or args.socket or args.db or args.password): if (args.host or args.port or args.socket or args.db or args.password):
warn('Host, port, db, password options for Redis will not be ' warn('Host, port, db, password options for Redis will not be '
'supported in future versions of RQ. ' 'supported in future versions of RQ. '
'Please use `REDIS_URL` or `--url` instead.', DeprecationWarning) 'Please use `REDIS_URL` or `--url` instead.', DeprecationWarning)
if args.host is None: strict_first = partial(first, key=lambda obj: obj is not None)
args.host = settings.get('REDIS_HOST', 'localhost')
if args.port is None:
args.port = int(settings.get('REDIS_PORT', 6379))
else:
args.port = int(args.port)
socket = settings.get('REDIS_SOCKET', False)
if args.socket is None and socket:
args.socket = socket
if args.db is None:
args.db = settings.get('REDIS_DB', 0)
if args.password is None: args.host = strict_first([args.host, settings.get('REDIS_HOST'), os.environ.get('RQ_REDIS_HOST'), 'localhost'])
args.password = settings.get('REDIS_PASSWORD', None) args.port = int(strict_first([args.port, settings.get('REDIS_PORT'), os.environ.get('RQ_REDIS_PORT'), 6379]))
args.socket = strict_first([args.socket, settings.get('REDIS_SOCKET'), os.environ.get('RQ_REDIS_SOCKET'), False])
args.db = strict_first([args.db, settings.get('REDIS_DB'), os.environ.get('RQ_REDIS_DB'), 0])
args.password = strict_first([args.password, settings.get('REDIS_PASSWORD'), os.environ.get('RQ_REDIS_PASSWORD')])
def setup_redis(args): def setup_redis(args):

@ -17,7 +17,7 @@ def get_version():
def get_dependencies(): def get_dependencies():
deps = ['redis >= 2.4.13'] deps = ['redis >= 2.4.13', 'first >= 2.0']
if sys.version_info < (2, 7) or \ if sys.version_info < (2, 7) or \
(sys.version_info >= (3, 0) and sys.version_info < (3, 1)): (sys.version_info >= (3, 0) and sys.version_info < (3, 1)):
deps += ['importlib'] deps += ['importlib']

Loading…
Cancel
Save