eclinical-requester 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. api_requester/__init__.py +9 -0
  2. api_requester/core/admin/api/auth_api.py +34 -0
  3. api_requester/core/admin/api/user_on_board_application_api.py +31 -0
  4. api_requester/core/admin/service/auth_service.py +34 -0
  5. api_requester/core/admin/service/impl/system_env_service_impl.py +39 -0
  6. api_requester/core/admin/service/impl/user_on_board_application_service_impl.py +23 -0
  7. api_requester/core/admin/service/user_on_board_application_service.py +35 -0
  8. api_requester/core/call_api.py +64 -0
  9. api_requester/core/common/api/system_env_api.py +24 -0
  10. api_requester/core/common/service/system_env_service.py +27 -0
  11. api_requester/docs/application.yaml +46 -0
  12. api_requester/dto/admin/cross_user_user_on_board_dto.py +20 -0
  13. api_requester/dto/admin/jwt_authentication_request.py +20 -0
  14. api_requester/dto/admin/user_on_board_dto.py +29 -0
  15. api_requester/dto/base_dto.py +167 -0
  16. api_requester/dto/biz_base.py +31 -0
  17. api_requester/dto/user.py +39 -0
  18. api_requester/http/app_url.py +31 -0
  19. api_requester/http/authorize.py +156 -0
  20. api_requester/http/eclinical_requests.py +264 -0
  21. api_requester/http/exceptions.py +72 -0
  22. api_requester/http/gateway.py +105 -0
  23. api_requester/http/sample_headers.py +23 -0
  24. api_requester/http/token_manager.py +30 -0
  25. api_requester/utils/constant.py +108 -0
  26. api_requester/utils/json_utils.py +83 -0
  27. api_requester/utils/lib.py +456 -0
  28. api_requester/utils/log.py +91 -0
  29. api_requester/utils/path.py +21 -0
  30. api_requester/utils/placeholder_replacer.py +22 -0
  31. api_requester/utils/read_file.py +94 -0
  32. api_requester/utils/rsa.py +36 -0
  33. api_requester/utils/time_utils.py +27 -0
  34. eclinical_requester-1.0.0.dist-info/LICENSE +19 -0
  35. eclinical_requester-1.0.0.dist-info/METADATA +19 -0
  36. eclinical_requester-1.0.0.dist-info/RECORD +38 -0
  37. eclinical_requester-1.0.0.dist-info/WHEEL +5 -0
  38. eclinical_requester-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,91 @@
1
+ # !/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @Author: xiaodong.li
5
+ @Time: 3/18/2024 4:59 PM
6
+ @Description: Description
7
+ @File: log.py
8
+ """
9
+ import logging
10
+ import os
11
+ import re
12
+ import time
13
+
14
+ from api_requester.utils.path import root
15
+ from api_requester.utils.time_utils import now_yyyy_mm_dd
16
+
17
+
18
+ class Logger:
19
+ """
20
+ define log
21
+ """
22
+
23
+ def __init__(self, path=None, c_level=logging.INFO, f_level=logging.DEBUG):
24
+ if path is None:
25
+ path = os.path.join(root(), "logs", f"{now_yyyy_mm_dd(time.time())}.log")
26
+ self.path = path
27
+ self.sh = None
28
+ self.fh = None
29
+ # create log file in case of no file
30
+ if not os.path.exists(path):
31
+ path_dir = os.path.dirname(path)
32
+ if not os.path.exists(path_dir):
33
+ os.makedirs(path_dir)
34
+ file = open(path, "w", encoding="utf-8")
35
+ file.close()
36
+ # create logger
37
+ self.logger = logging.getLogger(path)
38
+ self.logger.setLevel(logging.DEBUG)
39
+ # in case of creating multi-logger object
40
+ if not self.logger.handlers:
41
+ # set log format
42
+ fmt = logging.Formatter("[%(asctime)s.%(msecs)03d] [thread:%(thread)d] [threadName:%(threadName)s] "
43
+ "[%(levelname)s %(message)s]", datefmt=r"%Y-%m-%d %H:%M:%S")
44
+ # %(filename)s [line:%(lineno)d]
45
+ # set CMD log
46
+ self.sh = logging.StreamHandler()
47
+ self.sh.setFormatter(fmt)
48
+ self.sh.setLevel(c_level)
49
+ # set log in file
50
+ self.fh = logging.FileHandler(path, encoding="utf-8")
51
+ self.fh.setFormatter(fmt)
52
+ self.fh.setLevel(f_level)
53
+ self.logger.addHandler(self.sh)
54
+ self.logger.addHandler(self.fh)
55
+
56
+ def __del__(self):
57
+ try:
58
+ if self.sh is not None:
59
+ self.logger.removeHandler(self.sh)
60
+ if self.fh is not None:
61
+ self.logger.removeHandler(self.fh)
62
+ finally:
63
+ pass
64
+
65
+ def debug(self, message):
66
+ self.logger.debug(self._msg(message))
67
+
68
+ def info(self, message):
69
+ self.logger.info(self._msg(message))
70
+
71
+ def warn(self, message):
72
+ self.logger.warning(self._msg(message))
73
+
74
+ def error(self, message):
75
+ self.logger.error(self._msg(message))
76
+
77
+ def cri(self, message):
78
+ self.logger.critical(self._msg(message))
79
+
80
+ @staticmethod
81
+ def _msg(message):
82
+ try:
83
+ if "SQL>>>" in message:
84
+ b = re.compile(r"\s{2,}")
85
+ message = b.sub(" ", message)
86
+ return message
87
+ elif re.search(r"\n\n", message):
88
+ message = re.sub(r"\n\n", r"\n", message)
89
+ return message
90
+ finally:
91
+ return message
@@ -0,0 +1,21 @@
1
+ # !/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @Author: xiaodong.li
5
+ @Time: 12/23/2020 2:32 PM
6
+ @Description: Description
7
+ @File: path.py
8
+ """
9
+ import os
10
+
11
+
12
+ def root():
13
+ return os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
14
+
15
+
16
+ def project_path():
17
+ return os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
18
+
19
+
20
+ def docs_path():
21
+ return os.path.join(project_path(), "docs")
@@ -0,0 +1,22 @@
1
+ # !/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @Author: xiaodong.li
5
+ @Time: 12/30/2024 3:55 PM
6
+ @Description: Description
7
+ @File: placeholder_replacer.py
8
+ """
9
+ import re
10
+
11
+
12
+ class PlaceholderReplacer:
13
+ def __init__(self, replacements=None):
14
+ self.replacements = replacements or dict()
15
+
16
+ def add_replacement(self, placeholder, value):
17
+ self.replacements[placeholder] = value
18
+
19
+ def replace(self, text):
20
+ for placeholder, value in self.replacements.items():
21
+ text = re.sub(rf"\{{\s*{re.escape(placeholder)}\s*\}}", str(value), text)
22
+ return text
@@ -0,0 +1,94 @@
1
+ # !/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @Author: xiaodong.li
5
+ @Time: 3/18/2024 4:59 PM
6
+ @Description: Description
7
+ @File: read_file.py
8
+ """
9
+ import json
10
+ import os
11
+
12
+ import yaml
13
+ from lxml import etree
14
+
15
+ from api_requester.utils.log import Logger
16
+
17
+
18
+ class JSONConnector:
19
+ def __init__(self, filepath):
20
+ self.data = dict()
21
+ with open(filepath, mode='r', encoding='utf-8') as f:
22
+ self.data = json.load(f)
23
+
24
+ @property
25
+ def parsed_data(self):
26
+ return self.data
27
+
28
+
29
+ class XMLConnector:
30
+ def __init__(self, filepath):
31
+ self.root = etree.parse(filepath).getroot()
32
+
33
+ @property
34
+ def parsed_root(self):
35
+ return self.root
36
+
37
+
38
+ class MyYamlLoader(yaml.FullLoader):
39
+
40
+ def __init__(self, stream, filepath=None):
41
+ self.filepath = filepath and filepath or None
42
+ super(MyYamlLoader, self).__init__(stream)
43
+
44
+
45
+ class YAMLConnector:
46
+ def __init__(self, filepath):
47
+ self.data = None
48
+ with open(filepath, mode='r', encoding='utf-8') as f:
49
+ self.data = yaml.load(f.read(), Loader=lambda s: MyYamlLoader(s, filepath))
50
+
51
+ @property
52
+ def parsed_data(self):
53
+ return self.data
54
+
55
+
56
+ class SQLConnector:
57
+ def __init__(self, filepath):
58
+ self.data = dict()
59
+ with open(filepath, mode='r', encoding='utf-8') as f:
60
+ self.data = f.read()
61
+
62
+ @property
63
+ def parsed_data(self):
64
+ return self.data
65
+
66
+
67
+ def connection_factory(filepath):
68
+ if filepath.endswith('json'):
69
+ connector = JSONConnector
70
+ elif filepath.endswith('xml'):
71
+ connector = XMLConnector
72
+ elif filepath.endswith('yaml'):
73
+ connector = YAMLConnector
74
+ elif filepath.endswith('sql'):
75
+ connector = SQLConnector
76
+ else:
77
+ raise ValueError(f'Cannot connect to {filepath}.')
78
+ return connector(filepath)
79
+
80
+
81
+ def connect_to(filepath, ignore_error=False):
82
+ if not os.path.exists(filepath):
83
+ if ignore_error is False:
84
+ raise Exception("No such file.")
85
+ else:
86
+ return None
87
+ try:
88
+ return connection_factory(filepath)
89
+ except ValueError as ve:
90
+ Logger().error(ve)
91
+ if ignore_error is False:
92
+ raise Exception(ve)
93
+ else:
94
+ return None
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @author: xiaodong.li
5
+ @time: 11/10/2020 3:19 PM
6
+ @desc:
7
+ """
8
+ import base64
9
+ import time
10
+
11
+ from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
12
+ from Crypto.PublicKey import RSA
13
+
14
+
15
+ def encrypt(string):
16
+ public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTYnHdPs3A6JDZanoNumpZqoTam3B4yMiR" \
17
+ "blbaSmxGs8tW5AUEGfdevRZJn3zg/g0KETIptFXJ7oFbhYdmeo5Q8XEQnrXU1Q9GKyVZBpfJ" \
18
+ "ujGD7y3MaMYw29TwUdAuWDm0aWAqiwlqR2B9IWPkVBysIp2BypwfMrpe5IutObo3jQIDAQAB "
19
+ public_key = "-----BEGIN PUBLIC KEY-----\n" + public_key + "\n-----END PUBLIC KEY-----"
20
+ rsa_key = RSA.importKey(public_key)
21
+ cipher = Cipher_pkcs1_v1_5.new(rsa_key)
22
+ cipher_text = base64.b64encode(cipher.encrypt(string.encode()))
23
+ return cipher_text.decode()
24
+
25
+
26
+ def encrypt_password(pwd):
27
+ timestamp = int(time.time() * 1000)
28
+ # timestamp = date_to_timestamp("2021-07-15")
29
+ pwd_obj = dict(password=pwd, time=timestamp)
30
+ return encrypt(repr(pwd_obj).replace("'", "\""))
31
+
32
+
33
+ def date_to_timestamp(date):
34
+ frmt = "%Y-%m-%d"
35
+ time_array = time.strptime(date, frmt)
36
+ return int(time.mktime(time_array)) * 1000
@@ -0,0 +1,27 @@
1
+ # !/usr/bin/python3
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ @Author: xiaodong.li
5
+ @Time: 3/18/2024 4:59 PM
6
+ @Description: Description
7
+ @File: time_utils.py
8
+ """
9
+
10
+ import datetime
11
+ import time
12
+
13
+
14
+ def now(timestamp):
15
+ return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
16
+
17
+
18
+ def now_yyyy_mm_dd(timestamp):
19
+ return time.strftime("%Y-%m-%d", time.localtime(timestamp))
20
+
21
+
22
+ def now_utc(timestamp):
23
+ return datetime.datetime.utcfromtimestamp(timestamp)
24
+
25
+
26
+ def now_for_file(timestamp):
27
+ return time.strftime("%Y-%m-%d %H-%M-%S", time.localtime(timestamp))
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: eclinical_requester
3
+ Version: 1.0.0
4
+ Summary: edetek api requester
5
+ Home-page: http://example.com
6
+ Author: xiaodong.li
7
+ Author-email:
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: lxml>=5.3.0
12
+ Requires-Dist: requests>=2.32.3
13
+ Requires-Dist: PyYAML>=6.0.2
14
+ Requires-Dist: requests-toolbelt>=1.0.0
15
+ Requires-Dist: python-dateutil>=2.9.0.post0
16
+ Requires-Dist: numpy>=2.0.2
17
+ Requires-Dist: pycryptodome>=3.21.0
18
+
19
+ api_requester
@@ -0,0 +1,38 @@
1
+ api_requester/__init__.py,sha256=anVrvJawL8_RBA4b9shlqA_MC_YrPmQl1R8mzd4wVvk,175
2
+ api_requester/core/call_api.py,sha256=g0RIwDOamDeenehHHJRHZKl-iOoR9k-XTjPFIPZ8eHI,2274
3
+ api_requester/core/admin/api/auth_api.py,sha256=dKKOuEnXIKgzhUfaNfSzNm24LREUcvPZ28xxTZisY6w,861
4
+ api_requester/core/admin/api/user_on_board_application_api.py,sha256=gb7w8NYWsXgnWOla9JMyAyb5gVz3NmLiEb9H7ZlkyQs,897
5
+ api_requester/core/admin/service/auth_service.py,sha256=RiXY5fgZd63KKKNqkDmqvjl9iVVvIs1PhadJt6Fxbis,1057
6
+ api_requester/core/admin/service/user_on_board_application_service.py,sha256=qxevIpe26wXtGdBFqPsEdj7nir8MOQ3wAZsO_jxccF0,1353
7
+ api_requester/core/admin/service/impl/system_env_service_impl.py,sha256=zoR1HZm6tSoaJFe_bNe2cDLV_GfhZrf2qevKt2UmTQc,1519
8
+ api_requester/core/admin/service/impl/user_on_board_application_service_impl.py,sha256=2vNFD3dFZDI5ssvrSgzg2AT-yA3nlty_eCRWRd_5-nc,694
9
+ api_requester/core/common/api/system_env_api.py,sha256=Ogrc2vSpbjQBUIr_cUfz-TLX4DD_9eg_PabX433VQuA,634
10
+ api_requester/core/common/service/system_env_service.py,sha256=SIKQCG2tIf1s4dUsSiFvOMAgai6JQ-xRP5HJ8MKF3Ts,787
11
+ api_requester/docs/application.yaml,sha256=5R27yfD5QNfiPE1_UYnCJgBHqgL_j821PTtqRmjl4hI,1095
12
+ api_requester/dto/base_dto.py,sha256=nyBGidUblKE6MSK-yvcVSlYDyqPbIEdXiTOvymcFZp0,6904
13
+ api_requester/dto/biz_base.py,sha256=4lzf6FoXCNBr0OlxbFryf-7v16wfP3Hv6c7WUh-DgNs,874
14
+ api_requester/dto/user.py,sha256=X9CWYdRWNBKtQQtJN5ZyxR2l3USC1-JD9XE_8mOQ3WM,1280
15
+ api_requester/dto/admin/cross_user_user_on_board_dto.py,sha256=VSsihBthlfJORhhVeumDQxuF0lUj5vsLUcF3131Wi1s,489
16
+ api_requester/dto/admin/jwt_authentication_request.py,sha256=Wo9xTzpVIUJjkr4nYdnXsB7Q2nu3oFpy36K2aUUSy90,472
17
+ api_requester/dto/admin/user_on_board_dto.py,sha256=zsCKgnEttnsCkFlXKfuzkXWbvIhfiWv3jEj8jY6GRbQ,692
18
+ api_requester/http/app_url.py,sha256=jTGwxPcu_yts4WZbE9wDl6HqGOB48BdEIGw4Otmo1F0,939
19
+ api_requester/http/authorize.py,sha256=HIjVGYUACtpW1_vKyUGfs5LHJr0s6mDpBl-D6PXEAYk,7498
20
+ api_requester/http/eclinical_requests.py,sha256=6TATJAt6DjX9N7GZ0RSxEjL-T_-tqLULuBAYrI5eNwA,9496
21
+ api_requester/http/exceptions.py,sha256=BG0eSOkYT50Qib_PpjSrNWkcv9p9gBanOvXOWrP7Jz8,2685
22
+ api_requester/http/gateway.py,sha256=Ntnj-3OtyKLoGpkcCczMWQ0-0XrS5J_qkEcc9jB5AUk,3676
23
+ api_requester/http/sample_headers.py,sha256=Tz-_gLUx1jBzXd8niTZGgF1MDl6HTZHiVbriIUOqt78,544
24
+ api_requester/http/token_manager.py,sha256=sQO4zd3smA0XfmEndBwXs-8rRCmjkEU48S8jWxxXevA,919
25
+ api_requester/utils/constant.py,sha256=l1qhn0TkRhX6YAgJUEpiymtTmi1rSmzJVKdPVpayROs,2422
26
+ api_requester/utils/json_utils.py,sha256=0fTXGESYxuiHv4ezx_iIrmXv2qwb3Ozd1qRIXenToOQ,2614
27
+ api_requester/utils/lib.py,sha256=wOXU4hB1tFPHT2X96zmVUfEb7hulowDVO8BN5kV9OpA,14429
28
+ api_requester/utils/log.py,sha256=McGW0GE_8mt6GlYHT1B9cW_xGVXV3e1mkez_QJe6DkE,2885
29
+ api_requester/utils/path.py,sha256=65N-cWfKylYMaP3R4_Ajzx1TlQnAD-_8RY7Dm6Ps4vQ,451
30
+ api_requester/utils/placeholder_replacer.py,sha256=umNGeA1KCQ6Ewzsv1xEehLmHtKkgvSrfBf6mwvn7EdM,606
31
+ api_requester/utils/read_file.py,sha256=QRE2hZaPaCo7tyY0fW7c6PLXSmc7Zp1HA-SsN_B-2gs,2325
32
+ api_requester/utils/rsa.py,sha256=dr2m3a2M_LYu1Us97EEiMcjZAkpn1yWKIOjyYYubZeg,1202
33
+ api_requester/utils/time_utils.py,sha256=u1hHO0POBhdXaTQ7VGY_2YjaYxwlrWXGb5phP8iLfOY,579
34
+ eclinical_requester-1.0.0.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
35
+ eclinical_requester-1.0.0.dist-info/METADATA,sha256=qRr2VmPWHfgUq8SbwybR4-jDodZWksErlqelt0aKGPM,540
36
+ eclinical_requester-1.0.0.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
37
+ eclinical_requester-1.0.0.dist-info/top_level.txt,sha256=nM6wDThrKcbLCcBGrTBPPtstqV97VyITV-YiKLoUG0U,14
38
+ eclinical_requester-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.7.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ api_requester