Skip to content

Commit

Permalink
Upgrade Flask and simplify code to bypass static endpoint (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sathiyaraj-sridhar authored Nov 30, 2023
1 parent ee0fbe8 commit 252c7a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Import community modules.
import os
import json

# Get App configuration.
Expand All @@ -15,6 +16,8 @@ def redis_conf():
conf = file.read()
conf = json.loads(conf)
file.close()
if 'STATIC_ENDPOINT' in os.environ:
conf['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
return conf

app_conf = app_conf()
Expand Down
23 changes: 1 addition & 22 deletions init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Import community modules.
import os
# Import community modules.
import sys
import json
from elasticapm.contrib.flask import ElasticAPM
Expand Down Expand Up @@ -43,8 +42,6 @@ def home():
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
vars['accounts'] = redis.engine.hgetall(redis_conf['key_prefix']['account'])
for key,value in vars['accounts'].items():
vars['accounts'][key] = json.loads(value)
Expand All @@ -55,8 +52,6 @@ def account_create():
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
return render_template('account/create.html',vars=vars)
elif request.method=='POST':
Expand All @@ -79,8 +74,6 @@ def account_update(id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],id))
vars['account']['id'] = id
Expand All @@ -100,8 +93,6 @@ def account_view(id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],id))
vars['account']['id'] = id
return render_template('account/view.html',vars=vars)
Expand All @@ -111,8 +102,6 @@ def contact_view(act_id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
vars['contacts'] = redis.engine.hgetall(redis_conf['key_prefix']['contact']+':'+str(act_id))
Expand All @@ -125,8 +114,6 @@ def contact_create(act_id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
Expand All @@ -150,8 +137,6 @@ def contact_update(act_id,id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
Expand All @@ -172,8 +157,6 @@ def lead_view(act_id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
vars['leads'] = redis.engine.hgetall(redis_conf['key_prefix']['lead']+':'+str(act_id))
Expand All @@ -186,8 +169,6 @@ def lead_create(act_id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
Expand All @@ -211,8 +192,6 @@ def lead_update(act_id,id):
vars = {}
vars['environment'] = app_conf['environment']
vars['cdn'] = app_conf['cdn']
if os.environ['STATIC_ENDPOINT']:
vars['cdn']['static']['endpoint'] = os.environ['STATIC_ENDPOINT']
if request.method=='GET':
vars['account'] = json.loads(redis.engine.hget(redis_conf['key_prefix']['account'],act_id))
vars['account']['id'] = act_id
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
flask==0.12.4
MarkupSafe==2.1.3
Jinja2==3.1.2
flask==2.2.5
redis==2.10.6
elastic-apm[flask]==3.0.5
pytest==4.6.5

0 comments on commit 252c7a9

Please sign in to comment.