Browse Source

API Update

master
venkataakhil 2 years ago
parent
commit
77229fbe64
  1. 12
      smart_service/apis/addon_api.py
  2. 24
      smart_service/apis/app_user_login.py
  3. 7
      smart_service/apis/master_api.py
  4. 10
      smart_service/apis/publish_api.py
  5. 4
      smart_service/apis/transaction_api.py
  6. 8
      smart_service/apis/update_validation.py

12
smart_service/apis/addon_api.py

@ -6,11 +6,11 @@ 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 rate_limit
from smart_service.apis.master_api import custom_rate_limit
@frappe.whitelist()
def addon(args=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
# if args == None:
@ -78,7 +78,7 @@ def addon(args=None):
@frappe.whitelist()
def bookmark(args=None, request=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
@ -141,7 +141,7 @@ def bookmark(args=None, request=None):
@frappe.whitelist()
def feedback(args=None, request=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val=input_validation(args=args,request=request)
@ -226,7 +226,7 @@ def feedback(args=None, request=None):
@frappe.whitelist()
def model_hit(args=None, request=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val=input_validation(args=args,request=request)
@ -272,7 +272,7 @@ def model_hit(args=None, request=None):
@frappe.whitelist()
def model_usage(args=None, request=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val=input_validation(args=args,request=request)

24
smart_service/apis/app_user_login.py

@ -10,7 +10,7 @@ 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 rate_limit
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
@ -30,7 +30,7 @@ def app_user_validation_test():
@frappe.whitelist(allow_guest=True)
def app_user_validation(usr=None, pwd=None):
# rate_res = rate_limit(limit=5, seconds=15)
# rate_res = custom_custom_rate_limit(limit=5, seconds=15)
# if rate_res != 1:
# return rate_res
val = input_validation(usr=usr, pwd=pwd)
@ -177,7 +177,7 @@ def app_user_validation(usr=None, pwd=None):
@frappe.whitelist(allow_guest=True)
def grant_user_access(userdata=None, iid=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(userdata=userdata, iid=iid)
@ -399,7 +399,7 @@ def grant_user_access(userdata=None, iid=None):
@frappe.whitelist(allow_guest=True)
def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(usr=usr, pwd=pwd, iid=iid, device_data=device_data)
@ -540,7 +540,7 @@ def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None):
def new_grant_user_access(userdata=None, iid=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
try:
@ -751,7 +751,7 @@ def new_grant_user_access(userdata=None, iid=None):
@frappe.whitelist(allow_guest=1)
def generate_keys(user_name):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
@ -769,7 +769,7 @@ def generate_keys(user_name):
@frappe.whitelist()
def login_generate_token(doc=None, method=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
new_tok = generate_keys('cms@guidedsmartservice.com')
@ -798,7 +798,7 @@ def xml_to_dict(node):
@frappe.whitelist(allow_guest=True)
def generate_user_token(user_email):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
access_token = generate_access_token(user_email)
@ -810,7 +810,7 @@ def generate_user_token(user_email):
@frappe.whitelist(allow_guest=True)
def generate_access_token(user_email):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
frappe.set_user("Administrator")
@ -839,7 +839,7 @@ def generate_refresh_token():
@frappe.whitelist(allow_guest=1, methods=['POST'])
def refresh_token(refresh_token):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
if refresh_token:
@ -871,7 +871,7 @@ def refresh_token(refresh_token):
@frappe.whitelist(allow_guest=1, methods=['POST'])
def invalidate_token(refresh_token):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
if refresh_token:
@ -964,7 +964,7 @@ def get_encryption_key():
@frappe.whitelist(allow_guest=1)
def deactivate_tokens():
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
frappe.set_user("Administrator")

7
smart_service/apis/master_api.py

@ -1,7 +1,6 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
# from frappe.rate_limiter import rate_limit
import frappe
from frappe.model.document import Document
@ -14,13 +13,13 @@ current_db_name = frappe.conf.get("db_name")
@frappe.whitelist(allow_guest=True)
def masters1():
rate_res = rate_limit(limit=5, seconds=10)
rate_res = custom_rate_limit(limit=5, seconds=10)
if rate_res != 1:
return rate_res
return 1
def rate_limit(limit, seconds):
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
@ -40,7 +39,7 @@ def rate_limit(limit, seconds):
@frappe.whitelist()
def masters(args=None, LSD=None):
rate = rate_limit(limit=5, seconds=5)
rate = custom_rate_limit(limit=5, seconds=5)
if rate != 1:
return rate

10
smart_service/apis/publish_api.py

@ -7,7 +7,7 @@ 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 rate_limit
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -39,7 +39,7 @@ def get_parent_map(input_list, parameter):
@frappe.whitelist(allow_guest=True)
def api_procedure(args, publish_type, vehicle, language, version):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(args=args, publish_type=publish_type,
@ -233,7 +233,7 @@ def print(sts):
@frappe.whitelist(allow_guest=True)
def new_publish(args, publish_type, vehicle, language, version):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(args=args, publish_type=publish_type,
@ -315,7 +315,7 @@ def new_publish(args, publish_type, vehicle, language, version):
@frappe.whitelist(allow_guest=True)
def new_update(vehicle_list=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(vehicle_list=vehicle_list)
@ -363,7 +363,7 @@ def new_update(vehicle_list=None):
@frappe.whitelist(allow_guest=True)
def merge_json_files(old_json_path, new_json_path, out_file_path):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(old_json_path=old_json_path,

4
smart_service/apis/transaction_api.py

@ -4,7 +4,7 @@ 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 rate_limit
from smart_service.apis.master_api import custom_rate_limit
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -14,7 +14,7 @@ base_url = os.path.expanduser(
@frappe.whitelist()
def get_technical_manual(args=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
# if args == None:

8
smart_service/apis/update_validation.py

@ -5,7 +5,7 @@ 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 rate_limit
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(
@ -31,7 +31,7 @@ def get_parent_map(input_list, parameter):
@frappe.whitelist()
def check_all_vehicle_updates(vehicle_list=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
# if vehicle_list == None:
@ -112,7 +112,7 @@ def check_all_vehicle_updates(vehicle_list=None):
@frappe.whitelist()
def check_vehicle_update(vehicle_list=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
# if vehicle_list == None:
@ -787,7 +787,7 @@ def get_publish_ver(vehicle, l_id):
@frappe.whitelist()
def update_completed(FileName=None):
rate_res = rate_limit(limit=5, seconds=15)
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(FileName=FileName)

Loading…
Cancel
Save