crud-mysql 0.1.5__py3-none-any.whl → 0.1.7__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.
crud_mysql/crud_object.py CHANGED
@@ -27,9 +27,9 @@ class CrudObject:
27
27
  raise Exception(f"cant find {self.object_type} with id: {object_id}")
28
28
  return object
29
29
 
30
- def get_objects(self, filter, include_columns=[], exclude_columns=[]):
30
+ def get_objects(self, filter, include_columns=[], exclude_columns=[], conditions={}):
31
31
 
32
- object = self.db.get_filtered_list_of_objects(self.object_type, filter, include_columns, exclude_columns, as_dict=True)
32
+ object = self.db.get_filtered_list_of_objects(self.object_type, filter, include_columns, exclude_columns, conditions, as_dict=True)
33
33
  return object
34
34
 
35
35
  def create_object(self, object):
crud_mysql/endpoints.py CHANGED
@@ -1,10 +1,14 @@
1
1
  from flask import Blueprint
2
2
  from flask import request, jsonify
3
3
  from .crud_object import CrudObject
4
+ from .protect import protect
5
+
4
6
 
5
7
  crud = Blueprint('crud', __name__, template_folder='templates')
6
8
 
9
+
7
10
  @crud.route("/<object_type>", methods=["GET"])
11
+ @protect()
8
12
  def get_object(object_type):
9
13
  try:
10
14
  crud_object = CrudObject(object_type)
crud_mysql/protect.py ADDED
@@ -0,0 +1,19 @@
1
+ from flask_jwt_extended import JWTManager, jwt_required, get_jwt
2
+ from flask import request
3
+ from functools import wraps
4
+ from crud_mysql.crud_object import CrudObject
5
+
6
+ def protect():
7
+ def decorator(fn):
8
+ @wraps(fn)
9
+ def wrapper(*args, **kwargs):
10
+ method = request.method
11
+ object_type = request.base_url.split("/")[-1]
12
+ crud = CrudObject(object_type).get_crud()[object_type]
13
+ if "protected_methods" in crud and method in crud["protected_methods"]:
14
+ return jwt_required()(fn)(*args, **kwargs)
15
+ else:
16
+ return fn(*args, **kwargs)
17
+ return wrapper
18
+ return decorator
19
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crud-mysql
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: crud defiend by json
5
5
  Home-page: https://github.com/Ms-Shoshany/crud-mysql
6
6
  Author: hanna
@@ -14,6 +14,9 @@ License-File: LICENCE
14
14
  Requires-Dist: mysql-connector-python
15
15
  Requires-Dist: mysql-database
16
16
  Requires-Dist: flask
17
+ Requires-Dist: flask_jwt_extended
18
+ Requires-Dist: cryptography
19
+ Requires-Dist: PyJWT
17
20
  Dynamic: author
18
21
  Dynamic: author-email
19
22
  Dynamic: classifier
@@ -29,7 +32,7 @@ main.py / app.py - example
29
32
 
30
33
  from flask import Flask
31
34
  from flask_cors import CORS
32
- from crud-mysql import crud
35
+ from crud_mysql import crud
33
36
 
34
37
  app = Flask(__name__)
35
38
 
@@ -62,3 +65,36 @@ cred.json - example
62
65
  }
63
66
  }
64
67
  }
68
+
69
+ using tokens:
70
+
71
+ to protect endpoints by verifying tokens - add protected_methods to that object for example:
72
+
73
+ {
74
+ "car": {
75
+ "allowd_methods": ["GET", "POST", "DELETE", "PUT"],
76
+ "protected_methods": ["GET"],
77
+ "fetch_all": "true",
78
+ "schema": {
79
+ "owner": "VARCHAR(100)",
80
+ "color": "VARCHAR(100)",
81
+ "licence_plate": "INT"
82
+ }
83
+ }
84
+ }
85
+
86
+ here when using "GET" to get a car we will need to add a token.
87
+
88
+ in order for this to work a few things need to be set:
89
+ an environment varriable JWT_ALGORITHM should be set.
90
+ the options are:
91
+ - RS256
92
+ - HS256
93
+ if none are set it will default to HS256.
94
+
95
+ if the algorithim being used is HS256 then a variable needs to be set for SECRET_KEY.
96
+ this has to be the same SECRET_KEY that was used for creating the jwt.
97
+
98
+ if the algorithim being used is RS256. a variable needs to be set for SECRET_KEYS_PATH.
99
+ and at that path there needs to be a public.pem
100
+ it has to be the same cert that was used to create the jwt.
@@ -0,0 +1,10 @@
1
+ crud_mysql/__init__.py,sha256=0Dpvaha4FlC2WseTJsTNBZuGtVY-FPUrQEr5koovDAc,121
2
+ crud_mysql/crud_object.py,sha256=HrxuioscVIvGreaEh3XSPPbBQjruAimyUhmIFR97WGE,2578
3
+ crud_mysql/endpoints.py,sha256=J0wXB_REu7qd3DH1PTl7HZDEAYK7ZSWe3QxmKbn2yNI,2897
4
+ crud_mysql/protect.py,sha256=9phgBnHdWEItx_TDs10A4HoF7ljXGEzQroXLrEMucI8,690
5
+ crud_mysql/vars.py,sha256=Dx629hEZPt6uMWddftBqYzAR0D2VNlJo4NhiabBl0C8,243
6
+ crud_mysql-0.1.7.dist-info/licenses/LICENCE,sha256=6GSnt7dVNYlTiGLt8PqV1r8k0W7d83LX6GI-PQzPpsk,15
7
+ crud_mysql-0.1.7.dist-info/METADATA,sha256=DzzX80RpCb90xzo-Dt2xXfmtd0fcP8ksc1ATn5FRkJU,2746
8
+ crud_mysql-0.1.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ crud_mysql-0.1.7.dist-info/top_level.txt,sha256=KstBJpM9sK-Yg_NhtwQMh4UVFa9GAxKabKDwTWXWmFA,11
10
+ crud_mysql-0.1.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,9 +0,0 @@
1
- crud_mysql/__init__.py,sha256=0Dpvaha4FlC2WseTJsTNBZuGtVY-FPUrQEr5koovDAc,121
2
- crud_mysql/crud_object.py,sha256=6_nsij1OTCKwOXn94KeWoKynnXNwMiyfts1UI2AGv_s,2551
3
- crud_mysql/endpoints.py,sha256=2ynG30Tc1DzKnMUPGb9flzhdiMluBYXTbUBv4K_2t9g,2851
4
- crud_mysql/vars.py,sha256=Dx629hEZPt6uMWddftBqYzAR0D2VNlJo4NhiabBl0C8,243
5
- crud_mysql-0.1.5.dist-info/licenses/LICENCE,sha256=6GSnt7dVNYlTiGLt8PqV1r8k0W7d83LX6GI-PQzPpsk,15
6
- crud_mysql-0.1.5.dist-info/METADATA,sha256=9mYxBEpLiAtqK8sCgkB5Z3W5xk54IoU0Uc1z1tH7xhM,1622
7
- crud_mysql-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- crud_mysql-0.1.5.dist-info/top_level.txt,sha256=KstBJpM9sK-Yg_NhtwQMh4UVFa9GAxKabKDwTWXWmFA,11
9
- crud_mysql-0.1.5.dist-info/RECORD,,