Skip to content

Commit 19c5476

Browse files
authored
Allow redis-webcli to run with newer Python (#21)
Re-implement some method and use different buildpack for PCF.
1 parent 2496372 commit 19c5476

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

app.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import threading
23
import time
34
import subprocess
@@ -11,14 +12,28 @@
1112
from flask import Flask, render_template, request, jsonify, abort
1213
from flask import current_app as capp
1314
from flask_redis_sentinel import SentinelExtension
15+
import flask_redis_sentinel
1416
from flask_bootstrap import Bootstrap
1517
from config import configure, should_read_from_file_system, get_username_and_password_from_file_system
1618
import redis_sentinel_url
1719
import redis
1820

21+
22+
class MyOverride(object):
23+
@classmethod
24+
def _my_config_from_variables(cls, config, the_class):
25+
args = inspect.getfullargspec(the_class.__init__).args
26+
args.remove('self')
27+
args.remove('host')
28+
args.remove('port')
29+
args.remove('db')
30+
return {arg: config[arg.upper()] for arg in args if arg.upper() in config}
31+
32+
flask_redis_sentinel.RedisSentinel._config_from_variables = MyOverride._my_config_from_variables
1933
redis_sentinel = SentinelExtension()
2034
sentinel = redis_sentinel.sentinel
2135

36+
2237
app = Flask(__name__)
2338

2439
configure(app)
@@ -94,9 +109,6 @@ def execute():
94109
response = 'Exception: %s' % str(err)
95110
app.logger.exception("execute err")
96111

97-
if isinstance(response, bytes):
98-
response = response.decode("utf-8")
99-
100112
return jsonify({
101113
'response': response,
102114
'success': success
@@ -127,15 +139,16 @@ def get_conn_through_sentinel():
127139
connection_args = {
128140
"host": master_ip,
129141
"port": master_port,
130-
"password": app.config['REDIS_PASSWORD']
142+
"password": app.config['REDIS_PASSWORD'],
143+
"decode_responses" : True
131144
}
132145
redis_username = app.config['REDIS_USERNAME']
133146
if redis_username:
134147
# if no user name is sent, Redis will use the default username.
135148
connection_args['username'] = redis_username
136149

137150
if app.config['SSL_ENABLED']:
138-
ssl_cert_reqs = None if app.config['SKIP_HOSTNAME_VALIDATION'] else 'required'
151+
ssl_cert_reqs = "none" if app.config['SKIP_HOSTNAME_VALIDATION'] else 'required'
139152
connection_args['ssl'] = True
140153
connection_args['ssl_cert_reqs'] = ssl_cert_reqs
141154

manifest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ applications:
55
disk_quota: 256MB
66
random-route: true
77
buildpacks:
8-
- https://github.com/cloudfoundry/python-buildpack.git#v1.7.6
9-
command: python2 -m flask run -p $PORT -h 0.0.0.0
8+
- https://github.com/cloudfoundry/python-buildpack.git#v1.8.15
9+
command: python -m flask run -p $PORT -h 0.0.0.0
1010
env:
1111
FLASK_APP: app.py
1212
APP_SETTINGS: settings.cfg

runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.8.18

0 commit comments

Comments
 (0)