square-authentication 5.1.5__tar.gz → 5.2.0__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.
Files changed (24) hide show
  1. {square_authentication-5.1.5 → square_authentication-5.2.0}/PKG-INFO +15 -1
  2. {square_authentication-5.1.5 → square_authentication-5.2.0}/README.md +12 -0
  3. {square_authentication-5.1.5 → square_authentication-5.2.0}/setup.py +3 -1
  4. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/configuration.py +26 -0
  5. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/data/config.ini +7 -1
  6. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/main.py +2 -1
  7. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/messages.py +2 -0
  8. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/routes/core.py +1 -10
  9. square_authentication-5.2.0/square_authentication/routes/profile.py +134 -0
  10. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication.egg-info/PKG-INFO +15 -1
  11. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication.egg-info/SOURCES.txt +1 -0
  12. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication.egg-info/requires.txt +2 -0
  13. {square_authentication-5.1.5 → square_authentication-5.2.0}/setup.cfg +0 -0
  14. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/__init__.py +0 -0
  15. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/pydantic_models/__init__.py +0 -0
  16. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/pydantic_models/core.py +0 -0
  17. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/routes/__init__.py +0 -0
  18. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/routes/utility.py +0 -0
  19. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/utils/__init__.py +0 -0
  20. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/utils/encryption.py +0 -0
  21. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication/utils/token.py +0 -0
  22. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication.egg-info/dependency_links.txt +0 -0
  23. {square_authentication-5.1.5 → square_authentication-5.2.0}/square_authentication.egg-info/top_level.txt +0 -0
  24. {square_authentication-5.1.5 → square_authentication-5.2.0}/tests/test_1.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: square_authentication
3
- Version: 5.1.5
3
+ Version: 5.2.0
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: uvicorn>=0.24.0.post1
15
15
  Requires-Dist: fastapi>=0.104.1
16
+ Requires-Dist: python-multipart>=0.0.6
16
17
  Requires-Dist: pydantic>=2.5.3
17
18
  Requires-Dist: bcrypt>=4.1.2
18
19
  Requires-Dist: pyjwt>=2.8.0
@@ -22,6 +23,7 @@ Requires-Dist: square_commons>=1.0.0
22
23
  Requires-Dist: square_logger>=2.0.0
23
24
  Requires-Dist: square_database_helper>=2.0.0
24
25
  Requires-Dist: square_database_structure>=2.3.1
26
+ Requires-Dist: square_file_store_helper>=2.1.0
25
27
  Requires-Dist: pytest>=8.0.0
26
28
  Requires-Dist: httpx>=0.27.2
27
29
  Dynamic: author
@@ -51,6 +53,18 @@ pip install square_authentication
51
53
 
52
54
  ## changelog
53
55
 
56
+ ### v5.2.0
57
+
58
+ - add temp folder to .gitignore.
59
+ - add square_file_store_helper as a dependency.
60
+ - config
61
+ - add config section for file store helper.
62
+ - initialise file store helper and database helper in config.py
63
+ - add profile router
64
+ - profile
65
+ - add update_profile_photo/v0
66
+ - update messages.
67
+
54
68
  ### v5.1.5
55
69
 
56
70
  - bump square_logger to >=2.0.0.
@@ -16,6 +16,18 @@ pip install square_authentication
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v5.2.0
20
+
21
+ - add temp folder to .gitignore.
22
+ - add square_file_store_helper as a dependency.
23
+ - config
24
+ - add config section for file store helper.
25
+ - initialise file store helper and database helper in config.py
26
+ - add profile router
27
+ - profile
28
+ - add update_profile_photo/v0
29
+ - update messages.
30
+
19
31
  ### v5.1.5
20
32
 
21
33
  - bump square_logger to >=2.0.0.
@@ -4,7 +4,7 @@ package_name = "square_authentication"
4
4
 
5
5
  setup(
6
6
  name=package_name,
7
- version="5.1.5",
7
+ version="5.2.0",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -12,6 +12,7 @@ setup(
12
12
  install_requires=[
13
13
  "uvicorn>=0.24.0.post1",
14
14
  "fastapi>=0.104.1",
15
+ "python-multipart>=0.0.6",
15
16
  "pydantic>=2.5.3",
16
17
  "bcrypt>=4.1.2",
17
18
  "pyjwt>=2.8.0",
@@ -21,6 +22,7 @@ setup(
21
22
  "square_logger>=2.0.0",
22
23
  "square_database_helper>=2.0.0",
23
24
  "square_database_structure>=2.3.1",
25
+ "square_file_store_helper>=2.1.0",
24
26
  "pytest>=8.0.0",
25
27
  "httpx>=0.27.2",
26
28
  ],
@@ -2,6 +2,8 @@ import os
2
2
  import sys
3
3
 
4
4
  from square_commons import ConfigReader
5
+ from square_database_helper import SquareDatabaseHelper
6
+ from square_file_store_helper import SquareFileStoreHelper
5
7
  from square_logger.main import SquareLogger
6
8
 
7
9
  try:
@@ -67,6 +69,20 @@ try:
67
69
  ldict_configuration["SQUARE_DATABASE_HELPER"]["SQUARE_DATABASE_PORT"]
68
70
  )
69
71
  # ===========================================
72
+
73
+ # ===========================================
74
+ # square_file_store_helper
75
+
76
+ config_str_square_file_store_protocol = ldict_configuration[
77
+ "SQUARE_FILE_STORE_HELPER"
78
+ ]["SQUARE_FILE_STORE_PROTOCOL"]
79
+ config_str_square_file_store_ip = ldict_configuration["SQUARE_FILE_STORE_HELPER"][
80
+ "SQUARE_FILE_STORE_IP"
81
+ ]
82
+ config_int_square_file_store_port = int(
83
+ ldict_configuration["SQUARE_FILE_STORE_HELPER"]["SQUARE_FILE_STORE_PORT"]
84
+ )
85
+ # ===========================================
70
86
  # Initialize logger
71
87
  global_object_square_logger = SquareLogger(
72
88
  pstr_log_file_name=config_str_log_file_name,
@@ -74,6 +90,16 @@ try:
74
90
  pstr_log_path=config_str_log_path,
75
91
  pint_log_backup_count=config_int_log_backup_count,
76
92
  )
93
+ global_object_square_database_helper = SquareDatabaseHelper(
94
+ param_str_square_database_ip=config_str_square_database_ip,
95
+ param_int_square_database_port=config_int_square_database_port,
96
+ param_str_square_database_protocol=config_str_square_database_protocol,
97
+ )
98
+ global_object_square_file_store_helper = SquareFileStoreHelper(
99
+ param_str_square_file_store_protocol=config_str_square_file_store_protocol,
100
+ param_str_square_file_store_ip=config_str_square_file_store_ip,
101
+ param_int_square_file_store_port=config_int_square_file_store_port,
102
+ )
77
103
  except Exception as e:
78
104
  print(
79
105
  "\033[91mMissing or incorrect config.ini file.\n"
@@ -39,4 +39,10 @@ LOG_BACKUP_COUNT = 3
39
39
 
40
40
  SQUARE_DATABASE_PROTOCOL = http
41
41
  SQUARE_DATABASE_IP = localhost
42
- SQUARE_DATABASE_PORT = 10010
42
+ SQUARE_DATABASE_PORT = 10010
43
+
44
+ [SQUARE_FILE_STORE_HELPER]
45
+
46
+ SQUARE_FILE_STORE_PROTOCOL = http
47
+ SQUARE_FILE_STORE_IP = localhost
48
+ SQUARE_FILE_STORE_PORT = 10100
@@ -14,7 +14,7 @@ from square_authentication.configuration import (
14
14
  config_str_ssl_key_file_path,
15
15
  config_str_ssl_crt_file_path,
16
16
  )
17
- from square_authentication.routes import core, utility
17
+ from square_authentication.routes import core, utility, profile
18
18
 
19
19
  app = FastAPI()
20
20
 
@@ -28,6 +28,7 @@ app.add_middleware(
28
28
 
29
29
  app.include_router(core.router)
30
30
  app.include_router(utility.router)
31
+ app.include_router(profile.router)
31
32
 
32
33
 
33
34
  @app.get("/")
@@ -14,4 +14,6 @@ messages = {
14
14
  "GENERIC_DELETE_SUCCESSFUL": "your records have been deleted successfully.",
15
15
  "GENERIC_400": "the request is invalid or cannot be processed.",
16
16
  "GENERIC_500": "an internal server error occurred. please try again later.",
17
+ "INVALID_FILE_FORMAT": "the file format is not supported. please upload a valid file.",
18
+ "FILE_SIZE_EXCEEDS_LIMIT": "the file size exceeds the limit. please upload a smaller file.",
17
19
  }
@@ -8,7 +8,6 @@ from fastapi.params import Query
8
8
  from fastapi.responses import JSONResponse
9
9
  from requests import HTTPError
10
10
  from square_commons import get_api_output_in_standard_format
11
- from square_database_helper.main import SquareDatabaseHelper
12
11
  from square_database_helper.pydantic_models import FilterConditionsV0, FiltersV0
13
12
  from square_database_structure.square import global_string_database_name
14
13
  from square_database_structure.square.authentication import global_string_schema_name
@@ -27,12 +26,10 @@ from square_database_structure.square.public.tables import App
27
26
  from square_authentication.configuration import (
28
27
  config_int_access_token_valid_minutes,
29
28
  config_int_refresh_token_valid_minutes,
30
- config_int_square_database_port,
31
29
  config_str_secret_key_for_access_token,
32
30
  config_str_secret_key_for_refresh_token,
33
- config_str_square_database_ip,
34
- config_str_square_database_protocol,
35
31
  global_object_square_logger,
32
+ global_object_square_database_helper,
36
33
  )
37
34
  from square_authentication.messages import messages
38
35
  from square_authentication.pydantic_models.core import (
@@ -49,12 +46,6 @@ router = APIRouter(
49
46
  tags=["core"],
50
47
  )
51
48
 
52
- global_object_square_database_helper = SquareDatabaseHelper(
53
- param_str_square_database_ip=config_str_square_database_ip,
54
- param_int_square_database_port=config_int_square_database_port,
55
- param_str_square_database_protocol=config_str_square_database_protocol,
56
- )
57
-
58
49
 
59
50
  @router.post("/register_username/v0")
60
51
  @global_object_square_logger.auto_logger()
@@ -0,0 +1,134 @@
1
+ import os
2
+ from typing import Annotated
3
+
4
+ from fastapi import APIRouter, HTTPException, status, Header, UploadFile
5
+ from fastapi.responses import JSONResponse
6
+ from square_commons import get_api_output_in_standard_format
7
+ from square_database_helper import FiltersV0
8
+ from square_database_helper.pydantic_models import FilterConditionsV0
9
+ from square_database_structure.square import global_string_database_name
10
+ from square_database_structure.square.authentication import global_string_schema_name
11
+ from square_database_structure.square.authentication.tables import UserProfile
12
+
13
+ from square_authentication.configuration import (
14
+ global_object_square_logger,
15
+ config_str_secret_key_for_access_token,
16
+ global_object_square_file_store_helper,
17
+ global_object_square_database_helper,
18
+ )
19
+ from square_authentication.messages import messages
20
+ from square_authentication.utils.token import get_jwt_payload
21
+
22
+ router = APIRouter(
23
+ tags=["profile"],
24
+ )
25
+
26
+
27
+ @router.patch("/update_profile_photo/v0")
28
+ @global_object_square_logger.auto_logger()
29
+ async def update_profile_photo_v0(
30
+ access_token: Annotated[str, Header()],
31
+ profile_photo: UploadFile,
32
+ ):
33
+
34
+ try:
35
+ """
36
+ validation
37
+ """
38
+ # validate access token
39
+ try:
40
+ local_dict_access_token_payload = get_jwt_payload(
41
+ access_token, config_str_secret_key_for_access_token
42
+ )
43
+ except Exception as error:
44
+ output_content = get_api_output_in_standard_format(
45
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
46
+ )
47
+ raise HTTPException(
48
+ status_code=status.HTTP_400_BAD_REQUEST,
49
+ detail=output_content,
50
+ )
51
+ user_id = local_dict_access_token_payload["user_id"]
52
+
53
+ # validate file format
54
+ if not profile_photo.filename.endswith((".jpg", ".jpeg", ".png")):
55
+ output_content = get_api_output_in_standard_format(
56
+ message=messages["INVALID_FILE_FORMAT"]
57
+ )
58
+ raise HTTPException(
59
+ status_code=status.HTTP_400_BAD_REQUEST,
60
+ detail=output_content,
61
+ )
62
+
63
+ # validate file size
64
+ file_size_limit_in_mib = 5
65
+ if profile_photo.size > (file_size_limit_in_mib * 1024 * 1024):
66
+ output_content = get_api_output_in_standard_format(
67
+ message=messages["FILE_SIZE_EXCEEDS_LIMIT"]
68
+ )
69
+ raise HTTPException(
70
+ status_code=status.HTTP_400_BAD_REQUEST,
71
+ detail=output_content,
72
+ )
73
+ """
74
+ main process
75
+ """
76
+ # uploading to square file store
77
+ destination_path = f"temp/{user_id}/profile_photo/{profile_photo.filename}"
78
+ os.makedirs(os.path.dirname(destination_path), exist_ok=True)
79
+ with open(destination_path, "wb") as out_file:
80
+ content = await profile_photo.read()
81
+ out_file.write(content)
82
+
83
+ file_upload_response = (
84
+ global_object_square_file_store_helper.upload_file_using_file_path_v0(
85
+ file_path=destination_path,
86
+ system_relative_path="global/users/profile_photos",
87
+ )
88
+ )
89
+ os.remove(destination_path)
90
+
91
+ # adding file storage token to user profile
92
+ profile_update_response = global_object_square_database_helper.edit_rows_v0(
93
+ data={
94
+ UserProfile.user_profile_photo_storage_token.name: file_upload_response[
95
+ "data"
96
+ ]["main"]
97
+ },
98
+ filters=FiltersV0(
99
+ {UserProfile.user_id.name: FilterConditionsV0(eq=user_id)}
100
+ ),
101
+ database_name=global_string_database_name,
102
+ schema_name=global_string_schema_name,
103
+ table_name=UserProfile.__tablename__,
104
+ apply_filters=True,
105
+ )
106
+
107
+ """
108
+ return value
109
+ """
110
+ output_content = get_api_output_in_standard_format(
111
+ data=profile_update_response["data"],
112
+ message=messages["GENERIC_UPDATE_SUCCESSFUL"],
113
+ )
114
+ return JSONResponse(
115
+ status_code=status.HTTP_200_OK,
116
+ content=output_content,
117
+ )
118
+ except HTTPException as http_exception:
119
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
120
+ return JSONResponse(
121
+ status_code=http_exception.status_code, content=http_exception.detail
122
+ )
123
+ except Exception as e:
124
+ """
125
+ rollback logic
126
+ """
127
+ global_object_square_logger.logger.error(e, exc_info=True)
128
+ output_content = get_api_output_in_standard_format(
129
+ message=messages["GENERIC_500"],
130
+ log=str(e),
131
+ )
132
+ return JSONResponse(
133
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
134
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: square_authentication
3
- Version: 5.1.5
3
+ Version: 5.2.0
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: uvicorn>=0.24.0.post1
15
15
  Requires-Dist: fastapi>=0.104.1
16
+ Requires-Dist: python-multipart>=0.0.6
16
17
  Requires-Dist: pydantic>=2.5.3
17
18
  Requires-Dist: bcrypt>=4.1.2
18
19
  Requires-Dist: pyjwt>=2.8.0
@@ -22,6 +23,7 @@ Requires-Dist: square_commons>=1.0.0
22
23
  Requires-Dist: square_logger>=2.0.0
23
24
  Requires-Dist: square_database_helper>=2.0.0
24
25
  Requires-Dist: square_database_structure>=2.3.1
26
+ Requires-Dist: square_file_store_helper>=2.1.0
25
27
  Requires-Dist: pytest>=8.0.0
26
28
  Requires-Dist: httpx>=0.27.2
27
29
  Dynamic: author
@@ -51,6 +53,18 @@ pip install square_authentication
51
53
 
52
54
  ## changelog
53
55
 
56
+ ### v5.2.0
57
+
58
+ - add temp folder to .gitignore.
59
+ - add square_file_store_helper as a dependency.
60
+ - config
61
+ - add config section for file store helper.
62
+ - initialise file store helper and database helper in config.py
63
+ - add profile router
64
+ - profile
65
+ - add update_profile_photo/v0
66
+ - update messages.
67
+
54
68
  ### v5.1.5
55
69
 
56
70
  - bump square_logger to >=2.0.0.
@@ -14,6 +14,7 @@ square_authentication/pydantic_models/__init__.py
14
14
  square_authentication/pydantic_models/core.py
15
15
  square_authentication/routes/__init__.py
16
16
  square_authentication/routes/core.py
17
+ square_authentication/routes/profile.py
17
18
  square_authentication/routes/utility.py
18
19
  square_authentication/utils/__init__.py
19
20
  square_authentication/utils/encryption.py
@@ -1,5 +1,6 @@
1
1
  uvicorn>=0.24.0.post1
2
2
  fastapi>=0.104.1
3
+ python-multipart>=0.0.6
3
4
  pydantic>=2.5.3
4
5
  bcrypt>=4.1.2
5
6
  pyjwt>=2.8.0
@@ -9,5 +10,6 @@ square_commons>=1.0.0
9
10
  square_logger>=2.0.0
10
11
  square_database_helper>=2.0.0
11
12
  square_database_structure>=2.3.1
13
+ square_file_store_helper>=2.1.0
12
14
  pytest>=8.0.0
13
15
  httpx>=0.27.2