Browse Source

Circular import fix

master
venkataakhil 2 years ago
parent
commit
85aaf32ad1
  1. 18
      smart_service/apis/addon_api.py
  2. 17
      smart_service/apis/app_user_login.py
  3. 18
      smart_service/apis/publish_api.py
  4. 18
      smart_service/apis/transaction_api.py
  5. 19
      smart_service/apis/update_validation.py

18
smart_service/apis/addon_api.py

@ -6,8 +6,24 @@ import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
current_db_name = frappe.conf.get("db_name")
from smart_service.apis.master_api import custom_rate_limit
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
@frappe.whitelist()
def addon(args=None):
rate_res = custom_rate_limit(limit=5, seconds=15)

17
smart_service/apis/app_user_login.py

@ -10,10 +10,25 @@ from cryptography.fernet import Fernet, InvalidToken
from frappe.utils import cstr, encode
from datetime import datetime
from datetime import timedelta
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
# Temporary Login
@frappe.whitelist(allow_guest=True)

18
smart_service/apis/publish_api.py

@ -7,7 +7,6 @@ import frappe.utils
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -19,9 +18,22 @@ global_path = base_url + '/files/json_files/global/'
full_update_path = base_url + '/files/json_files/full_update/'
class Publish(Document):
pass
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
def get_parent_map(input_list, parameter):
parentChildMap = {}

18
smart_service/apis/transaction_api.py

@ -4,7 +4,6 @@ import json
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -12,6 +11,23 @@ base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
@frappe.whitelist()
def get_technical_manual(args=None):
rate_res = custom_rate_limit(limit=5, seconds=15)

19
smart_service/apis/update_validation.py

@ -5,13 +5,30 @@ import os
from frappe.utils import cstr
import time
from smart_service.apis.app_user_login import input_validation
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
def get_parent_map(input_list, parameter):
parentChildMap = {}
for b in input_list:

Loading…
Cancel
Save