crud-mysql 0.1.6__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.6
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
@@ -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
@@ -62,3 +65,39 @@ 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
+ important: also add to app.py the line:
89
+ set_jwt_protection(app)
90
+
91
+ in order for this to work a few things need to be set:
92
+ an environment varriable JWT_ALGORITHM should be set.
93
+ the options are:
94
+ - RS256
95
+ - HS256
96
+ if none are set it will default to HS256.
97
+
98
+ if the algorithim being used is HS256 then a variable needs to be set for SECRET_KEY.
99
+ this has to be the same SECRET_KEY that was used for creating the jwt.
100
+
101
+ if the algorithim being used is RS256. a variable needs to be set for SECRET_KEYS_PATH.
102
+ and at that path there needs to be a public.pem
103
+ it has to be the same cert that was used to create the jwt.
@@ -0,0 +1,73 @@
1
+ main.py / app.py - example
2
+
3
+ from flask import Flask
4
+ from flask_cors import CORS
5
+ from crud_mysql import crud
6
+
7
+ app = Flask(__name__)
8
+
9
+ app.register_blueprint(crud)
10
+
11
+ if __name__ == "__main__":
12
+ app.run(host="0.0.0.0", debug=True)
13
+
14
+ cred.json - example
15
+
16
+ {
17
+ "user": {
18
+ "allowd_methods": ["GET", "POST", "DELETE", "PUT"],
19
+ "fetch_all": "true",
20
+ "schema": {
21
+ "name": "VARCHAR(100)",
22
+ "email": "VARCHAR(100)",
23
+ "encrypted_password": "VARCHAR(100)",
24
+ "account_id": "INT",
25
+ "is_active": "INT"
26
+ }
27
+ },
28
+ "account": {
29
+ "allowd_methods": ["GET", "POST", "DELETE"],
30
+ "fetch_all": "false",
31
+ "schema": {
32
+ "name": "VARCHAR(100)",
33
+ "subscription_type": "VARCHAR(100)",
34
+ "root_user": "INT"
35
+ }
36
+ }
37
+ }
38
+
39
+ using tokens:
40
+
41
+ to protect endpoints by verifying tokens - add protected_methods to that object for example:
42
+
43
+ {
44
+ "car": {
45
+ "allowd_methods": ["GET", "POST", "DELETE", "PUT"],
46
+ "protected_methods": ["GET"],
47
+ "fetch_all": "true",
48
+ "schema": {
49
+ "owner": "VARCHAR(100)",
50
+ "color": "VARCHAR(100)",
51
+ "licence_plate": "INT"
52
+ }
53
+ }
54
+ }
55
+
56
+ here when using "GET" to get a car we will need to add a token.
57
+
58
+ important: also add to app.py the line:
59
+ set_jwt_protection(app)
60
+
61
+ in order for this to work a few things need to be set:
62
+ an environment varriable JWT_ALGORITHM should be set.
63
+ the options are:
64
+ - RS256
65
+ - HS256
66
+ if none are set it will default to HS256.
67
+
68
+ if the algorithim being used is HS256 then a variable needs to be set for SECRET_KEY.
69
+ this has to be the same SECRET_KEY that was used for creating the jwt.
70
+
71
+ if the algorithim being used is RS256. a variable needs to be set for SECRET_KEYS_PATH.
72
+ and at that path there needs to be a public.pem
73
+ it has to be the same cert that was used to create the jwt.
@@ -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
@@ -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)
@@ -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.6
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
@@ -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
@@ -62,3 +65,39 @@ 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
+ important: also add to app.py the line:
89
+ set_jwt_protection(app)
90
+
91
+ in order for this to work a few things need to be set:
92
+ an environment varriable JWT_ALGORITHM should be set.
93
+ the options are:
94
+ - RS256
95
+ - HS256
96
+ if none are set it will default to HS256.
97
+
98
+ if the algorithim being used is HS256 then a variable needs to be set for SECRET_KEY.
99
+ this has to be the same SECRET_KEY that was used for creating the jwt.
100
+
101
+ if the algorithim being used is RS256. a variable needs to be set for SECRET_KEYS_PATH.
102
+ and at that path there needs to be a public.pem
103
+ it has to be the same cert that was used to create the jwt.
@@ -4,6 +4,7 @@ setup.py
4
4
  crud_mysql/__init__.py
5
5
  crud_mysql/crud_object.py
6
6
  crud_mysql/endpoints.py
7
+ crud_mysql/protect.py
7
8
  crud_mysql/vars.py
8
9
  crud_mysql.egg-info/PKG-INFO
9
10
  crud_mysql.egg-info/SOURCES.txt
@@ -1,3 +1,6 @@
1
1
  mysql-connector-python
2
2
  mysql-database
3
3
  flask
4
+ flask_jwt_extended
5
+ cryptography
6
+ PyJWT
@@ -5,9 +5,9 @@ with open('README.md', encoding='utf-8') as f:
5
5
 
6
6
  setup(
7
7
  name='crud-mysql',
8
- version='0.1.6',
8
+ version='0.1.8',
9
9
  packages=find_packages(),
10
- install_requires=['mysql-connector-python', 'mysql-database', 'flask'],
10
+ install_requires=['mysql-connector-python', 'mysql-database', 'flask', 'flask_jwt_extended', 'cryptography', 'PyJWT'],
11
11
  author='hanna',
12
12
  author_email='channashosh@gmail.com',
13
13
  description='crud defiend by json',
@@ -1,37 +0,0 @@
1
- main.py / app.py - example
2
-
3
- from flask import Flask
4
- from flask_cors import CORS
5
- from crud_mysql import crud
6
-
7
- app = Flask(__name__)
8
-
9
- app.register_blueprint(crud)
10
-
11
- if __name__ == "__main__":
12
- app.run(host="0.0.0.0", debug=True)
13
-
14
- cred.json - example
15
-
16
- {
17
- "user": {
18
- "allowd_methods": ["GET", "POST", "DELETE", "PUT"],
19
- "fetch_all": "true",
20
- "schema": {
21
- "name": "VARCHAR(100)",
22
- "email": "VARCHAR(100)",
23
- "encrypted_password": "VARCHAR(100)",
24
- "account_id": "INT",
25
- "is_active": "INT"
26
- }
27
- },
28
- "account": {
29
- "allowd_methods": ["GET", "POST", "DELETE"],
30
- "fetch_all": "false",
31
- "schema": {
32
- "name": "VARCHAR(100)",
33
- "subscription_type": "VARCHAR(100)",
34
- "root_user": "INT"
35
- }
36
- }
37
- }
File without changes
File without changes