vc-utils 0.0.3__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.
linkage/__init__.py ADDED
@@ -0,0 +1,38 @@
1
+ import os
2
+ import requests
3
+ from datetime import datetime
4
+ import asyncio
5
+ import json
6
+ import logging
7
+
8
+
9
+ dir_path = os.path.dirname(os.path.realpath(__file__))
10
+ conf_file = os.path.join(dir_path, "../conf/default.json")
11
+ with open(conf_file, "r") as f:
12
+ config = json.load(f)
13
+
14
+ login_address = os.getenv("VU_LINKAGE_LOGIN_SERVICE", config.get("linkage", {}).get("VU_LINKAGE_LOGIN_SERVICE"))
15
+ user_address = os.getenv("VU_LINKAGE_USER_SERVICE", config.get("linkage", {}).get("VU_LINKAGE_USER_SERVICE"))
16
+
17
+ async def login(username: str, password: str):
18
+ # return (email, is_admin)
19
+ if login_address and user_address:
20
+ r = requests.post(login_address, data={'username': username, 'password': password})
21
+ if r.status_code < 400:
22
+ data = r.json()
23
+ headers = {
24
+ "Authorization": "Bearer " + data["access_token"]
25
+ }
26
+ response = requests.get(user_address, headers=headers)
27
+ try:
28
+ response.raise_for_status()
29
+ data = response.json()
30
+ data["email"] = data["email"].strip().lower()
31
+ if "performanceManager" in data["claims"]:
32
+ return {'email': data['email'], 'is_admin': True}
33
+ return {'email': data['email'], 'is_admin': False}
34
+ except requests.exceptions.HTTPError as exc:
35
+ logging.warning("Login failed", exc)
36
+
37
+ raise Exception("Login failed")
38
+
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: vc-utils
3
+ Version: 0.0.3
4
+ Summary: Vulcan Coalition utililities
5
+ Home-page: https://github.com/vulcan-coalition/vulcan-utils
6
+ Author: Chatavut Viriyasuthee
7
+ Author-email: chatavut@lab.ai
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: shortuuid
14
+ Requires-Dist: dotenv
15
+ Requires-Dist: requests
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # vulcan-utils
27
+
28
+ Vulcan python utility
29
+
30
+ ## Features
31
+
32
+ ### Linkage APIs
33
+
34
+ - Linkage API for various services
35
+
36
+ ### Collab APIs
37
+
38
+ - Collab API for various services
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install vulcan-utils
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ from vulcan_utils import example_function
50
+ ```
@@ -0,0 +1,5 @@
1
+ linkage/__init__.py,sha256=nyYEzb0bhnOuQNh0c_NubVF7uhIk3VVi7mTH50BDehQ,1443
2
+ vc_utils-0.0.3.dist-info/METADATA,sha256=tQ7BFKYLHor6wmRlu6zfKkrRVRRnF8euY76rOGs9cFo,983
3
+ vc_utils-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
+ vc_utils-0.0.3.dist-info/top_level.txt,sha256=vXflLPg1H4brKpbpr0blubIkAQJ5LAqf3SBZTWfJmHI,8
5
+ vc_utils-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ linkage