square_administration 4.0.0__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.
- square_administration/__init__.py +0 -0
- square_administration/configuration.py +120 -0
- square_administration/data/config.sample.ini +56 -0
- square_administration/data/config.testing.sample.ini +57 -0
- square_administration/main.py +58 -0
- square_administration/messages.py +16 -0
- square_administration/pydantic_models/__init__.py +0 -0
- square_administration/pydantic_models/authentication.py +36 -0
- square_administration/pydantic_models/core.py +12 -0
- square_administration/routes/__init__.py +0 -0
- square_administration/routes/authentication.py +212 -0
- square_administration/routes/core.py +39 -0
- square_administration/utils/__init__.py +0 -0
- square_administration/utils/common.py +36 -0
- square_administration/utils/routes/__init__.py +0 -0
- square_administration/utils/routes/authentication.py +725 -0
- square_administration/utils/routes/core.py +143 -0
- square_administration-4.0.0.dist-info/METADATA +74 -0
- square_administration-4.0.0.dist-info/RECORD +20 -0
- square_administration-4.0.0.dist-info/WHEEL +4 -0
|
File without changes
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from square_authentication_helper import SquareAuthenticationHelper
|
|
5
|
+
from square_commons import ConfigReader
|
|
6
|
+
from square_database_helper import SquareDatabaseHelper
|
|
7
|
+
from square_logger.main import SquareLogger
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
config_file_path = os.path.join(
|
|
11
|
+
os.path.dirname(os.path.abspath(__file__)), "data", "config.ini"
|
|
12
|
+
)
|
|
13
|
+
config_sample_file_path = os.path.join(
|
|
14
|
+
os.path.dirname(os.path.abspath(__file__)), "data", "config.sample.ini"
|
|
15
|
+
)
|
|
16
|
+
ldict_configuration = ConfigReader(
|
|
17
|
+
config_file_path, config_sample_file_path
|
|
18
|
+
).read_configuration()
|
|
19
|
+
# get all vars and typecast
|
|
20
|
+
# ===========================================
|
|
21
|
+
# general
|
|
22
|
+
config_str_module_name = ldict_configuration["GENERAL"]["MODULE_NAME"]
|
|
23
|
+
config_str_app_name = ldict_configuration["GENERAL"]["APP_NAME"]
|
|
24
|
+
# ===========================================
|
|
25
|
+
|
|
26
|
+
# ===========================================
|
|
27
|
+
# environment
|
|
28
|
+
config_str_host_ip = ldict_configuration["ENVIRONMENT"]["HOST_IP"]
|
|
29
|
+
config_int_host_port = int(ldict_configuration["ENVIRONMENT"]["HOST_PORT"])
|
|
30
|
+
config_list_allow_origins = eval(
|
|
31
|
+
ldict_configuration["ENVIRONMENT"]["ALLOW_ORIGINS"]
|
|
32
|
+
)
|
|
33
|
+
config_str_log_file_name = ldict_configuration["ENVIRONMENT"]["LOG_FILE_NAME"]
|
|
34
|
+
config_str_admin_password_hash = ldict_configuration["ENVIRONMENT"][
|
|
35
|
+
"ADMIN_PASSWORD_HASH"
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
config_str_ssl_crt_file_path = ldict_configuration["ENVIRONMENT"][
|
|
39
|
+
"SSL_CRT_FILE_PATH"
|
|
40
|
+
]
|
|
41
|
+
config_str_ssl_key_file_path = ldict_configuration["ENVIRONMENT"][
|
|
42
|
+
"SSL_KEY_FILE_PATH"
|
|
43
|
+
]
|
|
44
|
+
config_str_cookie_domain = ldict_configuration["ENVIRONMENT"]["COOKIE_DOMAIN"]
|
|
45
|
+
config_str_db_ip = ldict_configuration["ENVIRONMENT"]["DB_IP"]
|
|
46
|
+
config_int_db_port = int(ldict_configuration["ENVIRONMENT"]["DB_PORT"])
|
|
47
|
+
config_str_db_username = ldict_configuration["ENVIRONMENT"]["DB_USERNAME"]
|
|
48
|
+
config_str_db_password = ldict_configuration["ENVIRONMENT"]["DB_PASSWORD"]
|
|
49
|
+
# ===========================================
|
|
50
|
+
|
|
51
|
+
# ===========================================
|
|
52
|
+
# square_logger
|
|
53
|
+
config_int_log_level = int(ldict_configuration["SQUARE_LOGGER"]["LOG_LEVEL"])
|
|
54
|
+
config_str_log_path = ldict_configuration["SQUARE_LOGGER"]["LOG_PATH"]
|
|
55
|
+
config_int_log_backup_count = int(
|
|
56
|
+
ldict_configuration["SQUARE_LOGGER"]["LOG_BACKUP_COUNT"]
|
|
57
|
+
)
|
|
58
|
+
config_formatter_choice = ldict_configuration["SQUARE_LOGGER"]["FORMATTER_CHOICE"]
|
|
59
|
+
if config_formatter_choice not in ("human_readable", "json"):
|
|
60
|
+
raise ValueError(f"Invalid formatter choice: {config_formatter_choice}")
|
|
61
|
+
config_bool_enable_redaction = eval(
|
|
62
|
+
ldict_configuration["SQUARE_LOGGER"]["ENABLE_REDACTION"]
|
|
63
|
+
)
|
|
64
|
+
# ===========================================
|
|
65
|
+
|
|
66
|
+
# ===========================================
|
|
67
|
+
# square_database_helper
|
|
68
|
+
|
|
69
|
+
config_str_square_database_protocol = ldict_configuration["SQUARE_DATABASE_HELPER"][
|
|
70
|
+
"SQUARE_DATABASE_PROTOCOL"
|
|
71
|
+
]
|
|
72
|
+
config_str_square_database_ip = ldict_configuration["SQUARE_DATABASE_HELPER"][
|
|
73
|
+
"SQUARE_DATABASE_IP"
|
|
74
|
+
]
|
|
75
|
+
config_int_square_database_port = int(
|
|
76
|
+
ldict_configuration["SQUARE_DATABASE_HELPER"]["SQUARE_DATABASE_PORT"]
|
|
77
|
+
)
|
|
78
|
+
# ===========================================
|
|
79
|
+
# ===========================================
|
|
80
|
+
# square_authentication_helper
|
|
81
|
+
|
|
82
|
+
config_str_square_authentication_protocol = ldict_configuration[
|
|
83
|
+
"SQUARE_AUTHENTICATION_HELPER"
|
|
84
|
+
]["SQUARE_AUTHENTICATION_PROTOCOL"]
|
|
85
|
+
config_str_square_authentication_ip = ldict_configuration[
|
|
86
|
+
"SQUARE_AUTHENTICATION_HELPER"
|
|
87
|
+
]["SQUARE_AUTHENTICATION_IP"]
|
|
88
|
+
config_int_square_authentication_port = int(
|
|
89
|
+
ldict_configuration["SQUARE_AUTHENTICATION_HELPER"][
|
|
90
|
+
"SQUARE_AUTHENTICATION_PORT"
|
|
91
|
+
]
|
|
92
|
+
)
|
|
93
|
+
# ===========================================
|
|
94
|
+
# Initialize logger
|
|
95
|
+
global_object_square_logger = SquareLogger(
|
|
96
|
+
log_file_name=config_str_log_file_name,
|
|
97
|
+
log_level=config_int_log_level,
|
|
98
|
+
log_path=config_str_log_path,
|
|
99
|
+
log_backup_count=config_int_log_backup_count,
|
|
100
|
+
formatter_choice=config_formatter_choice,
|
|
101
|
+
enable_redaction=config_bool_enable_redaction,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
global_object_square_database_helper = SquareDatabaseHelper(
|
|
105
|
+
param_str_square_database_ip=config_str_square_database_ip,
|
|
106
|
+
param_int_square_database_port=config_int_square_database_port,
|
|
107
|
+
param_str_square_database_protocol=config_str_square_database_protocol,
|
|
108
|
+
)
|
|
109
|
+
global_object_square_authentication_helper = SquareAuthenticationHelper(
|
|
110
|
+
param_str_square_authentication_protocol=config_str_square_authentication_protocol,
|
|
111
|
+
param_str_square_authentication_ip=config_str_square_authentication_ip,
|
|
112
|
+
param_int_square_authentication_port=config_int_square_authentication_port,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
except Exception as e:
|
|
116
|
+
print(
|
|
117
|
+
"\033[91mMissing or incorrect config.ini file.\n"
|
|
118
|
+
"Error details: " + str(e) + "\033[0m"
|
|
119
|
+
)
|
|
120
|
+
sys.exit()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[GENERAL]
|
|
2
|
+
MODULE_NAME = square_administration
|
|
3
|
+
APP_NAME = square_admin
|
|
4
|
+
|
|
5
|
+
[ENVIRONMENT]
|
|
6
|
+
HOST_IP = 0.0.0.0
|
|
7
|
+
HOST_PORT = 10111
|
|
8
|
+
ALLOW_ORIGINS = ["http://localhost:10111"]
|
|
9
|
+
|
|
10
|
+
LOG_FILE_NAME = square_administration
|
|
11
|
+
|
|
12
|
+
ADMIN_PASSWORD_HASH = $2b$12$tDw4ZR0guiF5s5oVve5PcuELhlWO.lUH.OChPoeWVn95ac7QJlndq
|
|
13
|
+
|
|
14
|
+
# absolute path (mandatory only for http)
|
|
15
|
+
SSL_CRT_FILE_PATH = ssl.crt
|
|
16
|
+
SSL_KEY_FILE_PATH = ssl.key
|
|
17
|
+
|
|
18
|
+
COOKIE_DOMAIN = localhost
|
|
19
|
+
|
|
20
|
+
DB_IP = localhost
|
|
21
|
+
DB_PORT = 10001
|
|
22
|
+
DB_USERNAME = postgres
|
|
23
|
+
DB_PASSWORD = dummy
|
|
24
|
+
|
|
25
|
+
[SQUARE_LOGGER]
|
|
26
|
+
|
|
27
|
+
# | Log Level | Value |
|
|
28
|
+
# | --------- | ----- |
|
|
29
|
+
# | CRITICAL | 50 |
|
|
30
|
+
# | ERROR | 40 |
|
|
31
|
+
# | WARNING | 30 |
|
|
32
|
+
# | INFO | 20 |
|
|
33
|
+
# | DEBUG | 10 |
|
|
34
|
+
# | NOTSET | 0 |
|
|
35
|
+
|
|
36
|
+
LOG_LEVEL = 20
|
|
37
|
+
# absolute or relative path
|
|
38
|
+
LOG_PATH = logs
|
|
39
|
+
# number of backup log files to keep during rotation
|
|
40
|
+
# if backupCount is zero, rollover never occurs.
|
|
41
|
+
LOG_BACKUP_COUNT = 3
|
|
42
|
+
# json or human_readable
|
|
43
|
+
FORMATTER_CHOICE = json
|
|
44
|
+
ENABLE_REDACTION = True
|
|
45
|
+
|
|
46
|
+
[SQUARE_DATABASE_HELPER]
|
|
47
|
+
|
|
48
|
+
SQUARE_DATABASE_PROTOCOL = http
|
|
49
|
+
SQUARE_DATABASE_IP = localhost
|
|
50
|
+
SQUARE_DATABASE_PORT = 10010
|
|
51
|
+
|
|
52
|
+
[SQUARE_AUTHENTICATION_HELPER]
|
|
53
|
+
|
|
54
|
+
SQUARE_AUTHENTICATION_PROTOCOL = http
|
|
55
|
+
SQUARE_AUTHENTICATION_IP = localhost
|
|
56
|
+
SQUARE_AUTHENTICATION_PORT = 10011
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[GENERAL]
|
|
2
|
+
MODULE_NAME = square_administration
|
|
3
|
+
APP_NAME = square_admin
|
|
4
|
+
|
|
5
|
+
[ENVIRONMENT]
|
|
6
|
+
HOST_IP = 0.0.0.0
|
|
7
|
+
HOST_PORT = 10111
|
|
8
|
+
ALLOW_ORIGINS = ["http://localhost:10111"]
|
|
9
|
+
|
|
10
|
+
LOG_FILE_NAME = square_administration
|
|
11
|
+
|
|
12
|
+
ADMIN_PASSWORD_HASH = $2b$12$tDw4ZR0guiF5s5oVve5PcuELhlWO.lUH.OChPoeWVn95ac7QJlndq
|
|
13
|
+
|
|
14
|
+
# absolute path (mandatory only for http)
|
|
15
|
+
SSL_CRT_FILE_PATH = ssl.crt
|
|
16
|
+
SSL_KEY_FILE_PATH = ssl.key
|
|
17
|
+
|
|
18
|
+
COOKIE_DOMAIN = localhost
|
|
19
|
+
|
|
20
|
+
DB_IP = raspi.thepmsquare.com
|
|
21
|
+
DB_PORT = 15432
|
|
22
|
+
DB_USERNAME = postgres
|
|
23
|
+
DB_PASSWORD = testing_password
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[SQUARE_LOGGER]
|
|
27
|
+
|
|
28
|
+
# | Log Level | Value |
|
|
29
|
+
# | --------- | ----- |
|
|
30
|
+
# | CRITICAL | 50 |
|
|
31
|
+
# | ERROR | 40 |
|
|
32
|
+
# | WARNING | 30 |
|
|
33
|
+
# | INFO | 20 |
|
|
34
|
+
# | DEBUG | 10 |
|
|
35
|
+
# | NOTSET | 0 |
|
|
36
|
+
|
|
37
|
+
LOG_LEVEL = 20
|
|
38
|
+
# absolute or relative path
|
|
39
|
+
LOG_PATH = logs
|
|
40
|
+
# number of backup log files to keep during rotation
|
|
41
|
+
# if backupCount is zero, rollover never occurs.
|
|
42
|
+
LOG_BACKUP_COUNT = 3
|
|
43
|
+
# json or human_readable
|
|
44
|
+
FORMATTER_CHOICE = json
|
|
45
|
+
ENABLE_REDACTION = True
|
|
46
|
+
|
|
47
|
+
[SQUARE_DATABASE_HELPER]
|
|
48
|
+
|
|
49
|
+
SQUARE_DATABASE_PROTOCOL = http
|
|
50
|
+
SQUARE_DATABASE_IP = raspi.thepmsquare.com
|
|
51
|
+
SQUARE_DATABASE_PORT = 20010
|
|
52
|
+
|
|
53
|
+
[SQUARE_AUTHENTICATION_HELPER]
|
|
54
|
+
|
|
55
|
+
SQUARE_AUTHENTICATION_PROTOCOL = http
|
|
56
|
+
SQUARE_AUTHENTICATION_IP = raspi.thepmsquare.com
|
|
57
|
+
SQUARE_AUTHENTICATION_PORT = 20011
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from fastapi import FastAPI, status
|
|
2
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
3
|
+
from fastapi.responses import JSONResponse
|
|
4
|
+
from square_commons import get_api_output_in_standard_format
|
|
5
|
+
from uvicorn import run
|
|
6
|
+
|
|
7
|
+
from square_administration.configuration import (
|
|
8
|
+
config_int_host_port,
|
|
9
|
+
config_str_host_ip,
|
|
10
|
+
global_object_square_logger,
|
|
11
|
+
config_str_module_name,
|
|
12
|
+
config_str_ssl_key_file_path,
|
|
13
|
+
config_str_ssl_crt_file_path,
|
|
14
|
+
config_list_allow_origins,
|
|
15
|
+
)
|
|
16
|
+
from square_administration.routes import core, authentication
|
|
17
|
+
from square_administration.utils.common import is_https
|
|
18
|
+
|
|
19
|
+
app = FastAPI()
|
|
20
|
+
|
|
21
|
+
app.add_middleware(
|
|
22
|
+
CORSMiddleware,
|
|
23
|
+
allow_credentials=True,
|
|
24
|
+
allow_origins=config_list_allow_origins,
|
|
25
|
+
allow_methods=["*"],
|
|
26
|
+
allow_headers=["*"],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
app.include_router(core.router)
|
|
30
|
+
app.include_router(authentication.router)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@app.get("/")
|
|
34
|
+
@global_object_square_logger.auto_logger()
|
|
35
|
+
async def root():
|
|
36
|
+
output_content = get_api_output_in_standard_format(log=config_str_module_name)
|
|
37
|
+
return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
try:
|
|
42
|
+
if is_https():
|
|
43
|
+
run(
|
|
44
|
+
app,
|
|
45
|
+
host=config_str_host_ip,
|
|
46
|
+
port=config_int_host_port,
|
|
47
|
+
ssl_certfile=config_str_ssl_crt_file_path,
|
|
48
|
+
ssl_keyfile=config_str_ssl_key_file_path,
|
|
49
|
+
)
|
|
50
|
+
else:
|
|
51
|
+
run(
|
|
52
|
+
app,
|
|
53
|
+
host=config_str_host_ip,
|
|
54
|
+
port=config_int_host_port,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
except Exception as exc:
|
|
58
|
+
global_object_square_logger.logger.critical(exc, exc_info=True)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
messages = {
|
|
2
|
+
"REGISTRATION_SUCCESSFUL": "registration was successful. welcome aboard!",
|
|
3
|
+
"LOGIN_SUCCESSFUL": "you have logged in successfully.",
|
|
4
|
+
"LOGOUT_SUCCESSFUL": "you have logged out successfully.",
|
|
5
|
+
"INCORRECT_USERNAME": "the username you entered does not exist.",
|
|
6
|
+
"INCORRECT_PASSWORD": "the password you entered is incorrect. please try again.",
|
|
7
|
+
"GENERIC_CREATION_SUCCESSFUL": "records created successfully.",
|
|
8
|
+
"GENERIC_READ_SUCCESSFUL": "data retrieved successfully.",
|
|
9
|
+
"GENERIC_UPDATE_SUCCESSFUL": "your information has been updated successfully.",
|
|
10
|
+
"GENERIC_DELETE_SUCCESSFUL": "your records have been deleted successfully.",
|
|
11
|
+
"GENERIC_400": "the request is invalid or cannot be processed.",
|
|
12
|
+
"GENERIC_500": "an internal server error occurred. please try again later.",
|
|
13
|
+
"INCORRECT_ACCESS_TOKEN": "the access token provided is invalid or expired.",
|
|
14
|
+
"INCORRECT_REFRESH_TOKEN": "the refresh token provided is invalid or expired.",
|
|
15
|
+
"REFRESH_TOKEN_NOT_FOUND": "refresh token not found. please login again.",
|
|
16
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RegisterUsernameV0(BaseModel):
|
|
5
|
+
username: str
|
|
6
|
+
password: str
|
|
7
|
+
admin_password: str
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LoginUsernameV0(BaseModel):
|
|
11
|
+
username: str
|
|
12
|
+
password: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RemoveAppForSelfV0(BaseModel):
|
|
16
|
+
password: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ResetPasswordAndLoginUsingBackupCodeV0(BaseModel):
|
|
20
|
+
backup_code: str
|
|
21
|
+
username: str
|
|
22
|
+
new_password: str
|
|
23
|
+
logout_other_sessions: bool = False
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ResetPasswordAndLoginUsingResetEmailCodeV0(BaseModel):
|
|
27
|
+
reset_email_code: str
|
|
28
|
+
username: str
|
|
29
|
+
new_password: str
|
|
30
|
+
logout_other_sessions: bool = False
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class UpdatePasswordV0(BaseModel):
|
|
34
|
+
old_password: str
|
|
35
|
+
new_password: str
|
|
36
|
+
logout_other_sessions: bool = False
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
from square_database_structure.square.greeting.tables import Greeting
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GetAllGreetingsV0(BaseModel):
|
|
8
|
+
order_by: List[str] = Field(
|
|
9
|
+
default_factory=lambda: [f"-{Greeting.greeting_datetime.name}"]
|
|
10
|
+
)
|
|
11
|
+
limit: Optional[int] = None
|
|
12
|
+
offset: int = 0
|
|
File without changes
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, status, HTTPException, Header, Request
|
|
4
|
+
from fastapi.responses import JSONResponse
|
|
5
|
+
from square_commons import get_api_output_in_standard_format
|
|
6
|
+
|
|
7
|
+
from square_administration.configuration import (
|
|
8
|
+
global_object_square_logger,
|
|
9
|
+
)
|
|
10
|
+
from square_administration.messages import messages
|
|
11
|
+
from square_administration.pydantic_models.authentication import (
|
|
12
|
+
RegisterUsernameV0,
|
|
13
|
+
LoginUsernameV0,
|
|
14
|
+
RemoveAppForSelfV0,
|
|
15
|
+
ResetPasswordAndLoginUsingBackupCodeV0,
|
|
16
|
+
ResetPasswordAndLoginUsingResetEmailCodeV0,
|
|
17
|
+
UpdatePasswordV0,
|
|
18
|
+
)
|
|
19
|
+
from square_administration.utils.routes.authentication import (
|
|
20
|
+
util_register_username_v0,
|
|
21
|
+
util_login_username_v0,
|
|
22
|
+
util_remove_app_for_self_v0,
|
|
23
|
+
util_logout_v0,
|
|
24
|
+
util_generate_access_token_v0,
|
|
25
|
+
util_reset_password_and_login_using_backup_code_v0,
|
|
26
|
+
util_reset_password_and_login_using_reset_email_code_v0,
|
|
27
|
+
util_update_password_v0,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
router = APIRouter(
|
|
31
|
+
tags=["authentication"],
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@router.post("/register_username/v0")
|
|
36
|
+
@global_object_square_logger.auto_logger()
|
|
37
|
+
async def register_username_v0(
|
|
38
|
+
body: RegisterUsernameV0,
|
|
39
|
+
):
|
|
40
|
+
try:
|
|
41
|
+
return util_register_username_v0(
|
|
42
|
+
body=body,
|
|
43
|
+
)
|
|
44
|
+
except HTTPException as he:
|
|
45
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
46
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
47
|
+
except Exception as e:
|
|
48
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
49
|
+
output_content = get_api_output_in_standard_format(
|
|
50
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
51
|
+
)
|
|
52
|
+
return JSONResponse(
|
|
53
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@router.post("/login_username/v0")
|
|
58
|
+
@global_object_square_logger.auto_logger()
|
|
59
|
+
async def login_username_v0(
|
|
60
|
+
body: LoginUsernameV0,
|
|
61
|
+
):
|
|
62
|
+
try:
|
|
63
|
+
return util_login_username_v0(
|
|
64
|
+
body=body,
|
|
65
|
+
)
|
|
66
|
+
except HTTPException as he:
|
|
67
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
68
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
69
|
+
except Exception as e:
|
|
70
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
71
|
+
output_content = get_api_output_in_standard_format(
|
|
72
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
73
|
+
)
|
|
74
|
+
return JSONResponse(
|
|
75
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@router.patch("/remove_app_for_self/v0")
|
|
80
|
+
@global_object_square_logger.auto_logger()
|
|
81
|
+
async def remove_app_for_self_v0(
|
|
82
|
+
access_token: Annotated[str, Header()],
|
|
83
|
+
body: RemoveAppForSelfV0,
|
|
84
|
+
):
|
|
85
|
+
try:
|
|
86
|
+
return util_remove_app_for_self_v0(
|
|
87
|
+
body=body,
|
|
88
|
+
access_token=access_token,
|
|
89
|
+
)
|
|
90
|
+
except HTTPException as he:
|
|
91
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
92
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
95
|
+
output_content = get_api_output_in_standard_format(
|
|
96
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
97
|
+
)
|
|
98
|
+
return JSONResponse(
|
|
99
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@router.delete("/logout/v0")
|
|
104
|
+
@global_object_square_logger.auto_logger()
|
|
105
|
+
async def logout_v0(request: Request):
|
|
106
|
+
try:
|
|
107
|
+
return util_logout_v0(
|
|
108
|
+
request=request,
|
|
109
|
+
)
|
|
110
|
+
except HTTPException as he:
|
|
111
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
112
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
115
|
+
output_content = get_api_output_in_standard_format(
|
|
116
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
117
|
+
)
|
|
118
|
+
return JSONResponse(
|
|
119
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@router.get("/generate_access_token/v0")
|
|
124
|
+
@global_object_square_logger.auto_logger()
|
|
125
|
+
async def generate_access_token_v0(
|
|
126
|
+
request: Request,
|
|
127
|
+
):
|
|
128
|
+
try:
|
|
129
|
+
return util_generate_access_token_v0(
|
|
130
|
+
request=request,
|
|
131
|
+
)
|
|
132
|
+
except HTTPException as he:
|
|
133
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
134
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
135
|
+
except Exception as e:
|
|
136
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
137
|
+
output_content = get_api_output_in_standard_format(
|
|
138
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
139
|
+
)
|
|
140
|
+
return JSONResponse(
|
|
141
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@router.post("/reset_password_and_login_using_backup_code/v0")
|
|
146
|
+
@global_object_square_logger.auto_logger()
|
|
147
|
+
async def reset_password_and_login_using_backup_code_v0(
|
|
148
|
+
body: ResetPasswordAndLoginUsingBackupCodeV0,
|
|
149
|
+
):
|
|
150
|
+
try:
|
|
151
|
+
return util_reset_password_and_login_using_backup_code_v0(
|
|
152
|
+
body=body,
|
|
153
|
+
)
|
|
154
|
+
except HTTPException as he:
|
|
155
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
156
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
157
|
+
except Exception as e:
|
|
158
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
159
|
+
output_content = get_api_output_in_standard_format(
|
|
160
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
161
|
+
)
|
|
162
|
+
return JSONResponse(
|
|
163
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@router.post("/reset_password_and_login_using_reset_email_code/v0")
|
|
168
|
+
@global_object_square_logger.auto_logger()
|
|
169
|
+
async def reset_password_and_login_using_reset_email_code_v0(
|
|
170
|
+
body: ResetPasswordAndLoginUsingResetEmailCodeV0,
|
|
171
|
+
):
|
|
172
|
+
try:
|
|
173
|
+
return util_reset_password_and_login_using_reset_email_code_v0(
|
|
174
|
+
body=body,
|
|
175
|
+
)
|
|
176
|
+
except HTTPException as he:
|
|
177
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
178
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
179
|
+
except Exception as e:
|
|
180
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
181
|
+
output_content = get_api_output_in_standard_format(
|
|
182
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
183
|
+
)
|
|
184
|
+
return JSONResponse(
|
|
185
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@router.patch("/update_password/v0")
|
|
190
|
+
@global_object_square_logger.auto_logger()
|
|
191
|
+
async def update_password_v0(
|
|
192
|
+
request: Request,
|
|
193
|
+
body: UpdatePasswordV0,
|
|
194
|
+
access_token: Annotated[str, Header()],
|
|
195
|
+
):
|
|
196
|
+
try:
|
|
197
|
+
return util_update_password_v0(
|
|
198
|
+
request=request,
|
|
199
|
+
body=body,
|
|
200
|
+
access_token=access_token,
|
|
201
|
+
)
|
|
202
|
+
except HTTPException as he:
|
|
203
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
204
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
205
|
+
except Exception as e:
|
|
206
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
207
|
+
output_content = get_api_output_in_standard_format(
|
|
208
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
209
|
+
)
|
|
210
|
+
return JSONResponse(
|
|
211
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
212
|
+
)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Header, status, HTTPException
|
|
4
|
+
from fastapi.responses import JSONResponse
|
|
5
|
+
from square_commons import get_api_output_in_standard_format
|
|
6
|
+
|
|
7
|
+
from square_administration.configuration import (
|
|
8
|
+
global_object_square_logger,
|
|
9
|
+
)
|
|
10
|
+
from square_administration.messages import messages
|
|
11
|
+
from square_administration.pydantic_models.core import GetAllGreetingsV0
|
|
12
|
+
from square_administration.utils.routes.core import util_get_all_greetings_v0
|
|
13
|
+
|
|
14
|
+
router = APIRouter(
|
|
15
|
+
tags=["core"],
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@router.post("/get_all_greetings/v0")
|
|
20
|
+
@global_object_square_logger.auto_logger()
|
|
21
|
+
async def get_all_greetings_v0(
|
|
22
|
+
access_token: Annotated[str, Header()], body: GetAllGreetingsV0
|
|
23
|
+
):
|
|
24
|
+
try:
|
|
25
|
+
return util_get_all_greetings_v0(
|
|
26
|
+
access_token=access_token,
|
|
27
|
+
body=body,
|
|
28
|
+
)
|
|
29
|
+
except HTTPException as he:
|
|
30
|
+
global_object_square_logger.logger.error(he, exc_info=True)
|
|
31
|
+
return JSONResponse(status_code=he.status_code, content=he.detail)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
|
34
|
+
output_content = get_api_output_in_standard_format(
|
|
35
|
+
message=messages["GENERIC_500"], log=str(e)
|
|
36
|
+
)
|
|
37
|
+
return JSONResponse(
|
|
38
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
|
39
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from square_database_helper import FiltersV0
|
|
4
|
+
from square_database_helper.pydantic_models import FilterConditionsV0
|
|
5
|
+
from square_database_structure.square import global_string_database_name
|
|
6
|
+
from square_database_structure.square.public import global_string_schema_name
|
|
7
|
+
from square_database_structure.square.public.tables import App
|
|
8
|
+
|
|
9
|
+
from square_administration.configuration import (
|
|
10
|
+
config_str_ssl_key_file_path,
|
|
11
|
+
config_str_ssl_crt_file_path,
|
|
12
|
+
global_object_square_logger,
|
|
13
|
+
global_object_square_database_helper,
|
|
14
|
+
config_str_app_name,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@global_object_square_logger.auto_logger()
|
|
19
|
+
def is_https() -> bool:
|
|
20
|
+
return os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
|
|
21
|
+
config_str_ssl_crt_file_path
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# get app id
|
|
26
|
+
global_int_app_id = global_object_square_database_helper.get_rows_v0(
|
|
27
|
+
database_name=global_string_database_name,
|
|
28
|
+
schema_name=global_string_schema_name,
|
|
29
|
+
table_name=App.__tablename__,
|
|
30
|
+
filters=FiltersV0(
|
|
31
|
+
root={
|
|
32
|
+
App.app_name.name: FilterConditionsV0(eq=config_str_app_name),
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
columns=[App.app_id.name],
|
|
36
|
+
)["data"]["main"][0][App.app_id.name]
|
|
File without changes
|