crud-mysql 0.1.7__tar.gz → 0.1.8__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crud-mysql
3
- Version: 0.1.7
3
+ Version: 0.1.8
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:
@@ -55,6 +55,9 @@ to protect endpoints by verifying tokens - add protected_methods to that object
55
55
 
56
56
  here when using "GET" to get a car we will need to add a token.
57
57
 
58
+ important: also add to app.py the line:
59
+ set_jwt_protection(app)
60
+
58
61
  in order for this to work a few things need to be set:
59
62
  an environment varriable JWT_ALGORITHM should be set.
60
63
  the options are:
@@ -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
@@ -0,0 +1,35 @@
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
+ import os
6
+
7
+ def protect():
8
+ def decorator(fn):
9
+ @wraps(fn)
10
+ def wrapper(*args, **kwargs):
11
+ method = request.method
12
+ object_type = request.base_url.split("/")[-1]
13
+ crud = CrudObject(object_type).get_crud()[object_type]
14
+ if "protected_methods" in crud and method in crud["protected_methods"]:
15
+ return jwt_required()(fn)(*args, **kwargs)
16
+ else:
17
+ return fn(*args, **kwargs)
18
+ return wrapper
19
+ return decorator
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.8
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:
@@ -5,7 +5,7 @@ with open('README.md', encoding='utf-8') as f:
5
5
 
6
6
  setup(
7
7
  name='crud-mysql',
8
- version='0.1.7',
8
+ version='0.1.8',
9
9
  packages=find_packages(),
10
10
  install_requires=['mysql-connector-python', 'mysql-database', 'flask', 'flask_jwt_extended', 'cryptography', 'PyJWT'],
11
11
  author='hanna',
@@ -1,19 +0,0 @@
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
-
File without changes
File without changes