[cherry-pick]allow redis password safe special characters on release-2.8.0 (#18587)

allow redis password safe special characters

Signed-off-by: yminer <yminer@vmware.com>

string and None type conversion
This commit is contained in:
MinerYang 2023-04-24 09:52:33 +08:00 committed by GitHub
parent 3c5cb274ec
commit 405f975eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import logging
import os
import yaml
from urllib.parse import urlencode
from urllib.parse import urlencode, quote
from g import versions_file_path, host_root_dir, DEFAULT_UID, INTERNAL_NO_PROXY_DN
from models import InternalTLS, Metric, Trace, PurgeUpload, Cache
from utils.misc import generate_random_string, owner_can_read, other_can_read
@ -385,7 +385,7 @@ def get_redis_url(db, redis=None):
kwargs['scheme'] = kwargs.get('sentinel_master_set', None) and 'redis+sentinel' or 'redis'
kwargs['db_part'] = db and ("/%s" % db) or ""
kwargs['sentinel_part'] = kwargs.get('sentinel_master_set', None) and ("/" + kwargs['sentinel_master_set']) or ''
kwargs['password_part'] = kwargs.get('password', None) and (':%s@' % kwargs['password']) or ''
kwargs['password_part'] = quote(str(kwargs.get('password', None)), safe='') and (':%s@' % quote(str(kwargs['password']), safe='')) or ''
kwargs['username_part'] = kwargs.get('username', None) or ''
return "{scheme}://{username_part}{password_part}{host}{sentinel_part}{db_part}".format(**kwargs) + get_redis_url_param(kwargs)

View File

@ -2,7 +2,7 @@ import copy
import os
import subprocess
from g import config_dir, templates_dir, DEFAULT_GID, DEFAULT_UID, data_dir
from urllib.parse import urlsplit
from urllib.parse import urlsplit, unquote
from utils.jinja import render_jinja
from utils.misc import prepare_dir
@ -46,14 +46,14 @@ def parse_redis(redis_url):
if not u.scheme or u.scheme == 'redis':
return {
'redis_host': u.netloc.split('@')[-1],
'redis_password': u.password or '',
'redis_password': '' if u.password is None else unquote(u.password),
'redis_db_index_reg': u.path and int(u.path[1:]) or 0,
}
elif u.scheme == 'redis+sentinel':
return {
'sentinel_master_set': u.path.split('/')[1],
'redis_host': u.netloc.split('@')[-1],
'redis_password': u.password or '',
'redis_password': '' if u.password is None else unquote(u.password),
'redis_db_index_reg': len(u.path.split('/')) == 3 and int(u.path.split('/')[2]) or 0,
}
else: