crud-mysql 0.1.7__py3-none-any.whl → 0.1.9__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/__init__.py CHANGED
@@ -1,2 +1,3 @@
1
1
  from .endpoints import crud, create_object, get_object, delete_object, update_object
2
- from .crud_object import CrudObject
2
+ from .crud_object import CrudObject
3
+ from .protect import set_jwt_protection
crud_mysql/endpoints.py CHANGED
@@ -35,7 +35,7 @@ def get_object(object_type):
35
35
  except Exception as e:
36
36
  return jsonify(f"Invalid path: /{object_type}"), 404
37
37
 
38
-
38
+ @protect()
39
39
  @crud.route("/<object_type>", methods=["POST"])
40
40
  def create_object(object_type):
41
41
  try:
@@ -53,7 +53,8 @@ def create_object(object_type):
53
53
  return jsonify({"objectId": object_id}), 201
54
54
  else:
55
55
  return jsonify("error occured while creating object"), 500
56
-
56
+
57
+ @protect()
57
58
  @crud.route("/<object_type>", methods=["PUT"])
58
59
  def update_object(object_type):
59
60
  try:
@@ -70,6 +71,7 @@ def update_object(object_type):
70
71
  crud_object.update_object(object_id, object_info)
71
72
  return jsonify(f"Successfully updated {object_type} with id: {object_id}"), 200
72
73
 
74
+ @protect()
73
75
  @crud.route("/<object_type>", methods=["DELETE"])
74
76
  def delete_object(object_type):
75
77
  try:
crud_mysql/protect.py CHANGED
@@ -2,6 +2,7 @@ from flask_jwt_extended import JWTManager, jwt_required, get_jwt
2
2
  from flask import request
3
3
  from functools import wraps
4
4
  from crud_mysql.crud_object import CrudObject
5
+ import os
5
6
 
6
7
  def protect():
7
8
  def decorator(fn):
@@ -17,3 +18,18 @@ def protect():
17
18
  return wrapper
18
19
  return decorator
19
20
 
21
+ def set_jwt_protection(app):
22
+ with open("crud.json", "r") as f:
23
+ crud_file = f.read()
24
+ if "protected_methods" in crud_file:
25
+ algo = os.environ.get("JWT_ALGORITHM", "HS256")
26
+ app.config['JWT_ALGORITHM'] = algo
27
+ if algo == "RS256":
28
+ SECRET_KEYS_PATH = os.environ.get("SECRET_KEYS_PATH", ".")
29
+ with open(f'{SECRET_KEYS_PATH}/public.pem', 'r') as f:
30
+ app.config['JWT_PUBLIC_KEY'] = f.read()
31
+ elif algo == "HS256":
32
+ if "SECRET_KEY" not in os.environ:
33
+ raise Exception("missing secret key for verifying tokens")
34
+ app.config['SECRET_KEY'] = os.environ.get("SECRET_KEY")
35
+ jwt = JWTManager(app)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crud-mysql
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: crud defiend by json
5
5
  Home-page: https://github.com/Ms-Shoshany/crud-mysql
6
6
  Author: hanna
@@ -85,6 +85,9 @@ to protect endpoints by verifying tokens - add protected_methods to that object
85
85
 
86
86
  here when using "GET" to get a car we will need to add a token.
87
87
 
88
+ important: also add to app.py the line:
89
+ set_jwt_protection(app)
90
+
88
91
  in order for this to work a few things need to be set:
89
92
  an environment varriable JWT_ALGORITHM should be set.
90
93
  the options are:
@@ -0,0 +1,10 @@
1
+ crud_mysql/__init__.py,sha256=P5UdgwNmgtHtEDs6p10-faMgHnVAeFdSVhrgi7xMBZY,162
2
+ crud_mysql/crud_object.py,sha256=HrxuioscVIvGreaEh3XSPPbBQjruAimyUhmIFR97WGE,2578
3
+ crud_mysql/endpoints.py,sha256=tPN-2ewn7ecr146CZgHqCQyjhz1gMoyG9twqYuoX9e8,2929
4
+ crud_mysql/protect.py,sha256=-u9BjlhUK2BDnlyDiC_WjQzkT1E_r4iOQysPD4pRSsw,1422
5
+ crud_mysql/vars.py,sha256=Dx629hEZPt6uMWddftBqYzAR0D2VNlJo4NhiabBl0C8,243
6
+ crud_mysql-0.1.9.dist-info/licenses/LICENCE,sha256=6GSnt7dVNYlTiGLt8PqV1r8k0W7d83LX6GI-PQzPpsk,15
7
+ crud_mysql-0.1.9.dist-info/METADATA,sha256=5WUwRIfm3y_nQGRmvS8sHaGgRQ20OyaiYUqYvzXx7rE,2816
8
+ crud_mysql-0.1.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ crud_mysql-0.1.9.dist-info/top_level.txt,sha256=KstBJpM9sK-Yg_NhtwQMh4UVFa9GAxKabKDwTWXWmFA,11
10
+ crud_mysql-0.1.9.dist-info/RECORD,,
@@ -1,10 +0,0 @@
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,,