(20250210) Started working on MikroTik config automation.
This commit is contained in:
@@ -162,6 +162,7 @@ async def authorize_software_client(
|
||||
|
||||
# Start by assuming failure:
|
||||
success = False
|
||||
message = None
|
||||
|
||||
# ┏┳┓┓ ┏┓┏┓ ┏┓┏┏• ┏┓┳
|
||||
# ┃ ┣┓┏┓ ┃ ┣┫ ┃┃╋╋┓┏┏┓ ┣┫┃
|
||||
@@ -169,33 +170,61 @@ async def authorize_software_client(
|
||||
|
||||
if inbound_data.softwareClient == "theCaOfficeAi":
|
||||
|
||||
auth_token = CoreAuthTokenModel(
|
||||
serviceType = "software",
|
||||
client = inbound_data.softwareClient,
|
||||
authType = "auth",
|
||||
auth = inbound_data.auth.model_dump(),
|
||||
user = kwargs.get("session_info"),
|
||||
clientUserId = {},
|
||||
status = "active",
|
||||
syncFreq = 60
|
||||
pass
|
||||
|
||||
# auth_token = CoreAuthTokenModel(
|
||||
# serviceType = "software",
|
||||
# client = inbound_data.softwareClient,
|
||||
# authType = "auth",
|
||||
# auth = inbound_data.auth.model_dump(),
|
||||
# user = kwargs.get("session_info"),
|
||||
# clientUserId = {},
|
||||
# status = "active",
|
||||
# syncFreq = 60
|
||||
# )
|
||||
#
|
||||
# token_id = await current_app.core_auth_token_controller.get_token_id(
|
||||
# db_conn = current_app.sql_writer,
|
||||
# mongo_conn = current_app.data_mongo,
|
||||
# auth_token = auth_token,
|
||||
# token_notes = {},
|
||||
# session_token = inbound_headers["X-Session-Token"]
|
||||
# )
|
||||
#
|
||||
# success = await current_app.core_auth_token_controller.set_token(
|
||||
# db_conn = current_app.sql_writer,
|
||||
# mongo_conn = current_app.data_mongo,
|
||||
# token_id = token_id,
|
||||
# auth_token = auth_token,
|
||||
# token_notes = {},
|
||||
# session_token = inbound_headers["X-Session-Token"]
|
||||
# )
|
||||
|
||||
# ┏┓ ┳┳┓•┓ ┏┳┓•┓ ┏┓┏┓┏┓ ┏┓ ┓┏┓┏┓┏┓
|
||||
# ┣ ┏┓┏┓ ┃┃┃┓┃┏┏┓┏┓ ┃ ┓┃┏ ┃┃┃┃┃┃┏┓┣ ┃┃┫┃┫┃┫
|
||||
# ┻ ┗┛┛ ┛ ┗┗┛┗┛ ┗┛ ┻ ┗┛┗ ┣┛┣┛┣┛┗┛┗┛ ┻┗┛┗┛┗┛
|
||||
|
||||
elif inbound_data.softwareClient == "mikrotikPPPoE1000":
|
||||
|
||||
# Make the client controller test and save the auth:
|
||||
response = await current_app.mikrotik_pppoe_1000_controller.save_auth(
|
||||
sql_conn = current_app.sql_writer,
|
||||
mongo_data_conn = current_app.data_mongo,
|
||||
mikrotik_auth = inbound_data.auth
|
||||
)
|
||||
|
||||
token_id = await current_app.core_auth_token_controller.get_token_id(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
auth_token = auth_token,
|
||||
token_notes = {},
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
# Note down the results:
|
||||
success = response.success
|
||||
message = response.message
|
||||
|
||||
success = await current_app.core_auth_token_controller.set_token(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
token_id = token_id,
|
||||
auth_token = auth_token,
|
||||
token_notes = {},
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
# ┏┓ ┳┳┓•┓ ┏┳┓•┓ ┓┏ ┓┏┓┏┓┏┓
|
||||
# ┣ ┏┓┏┓ ┃┃┃┓┃┏┏┓┏┓ ┃ ┓┃┏ ┣┫┏┓╋┏┏┓┏┓╋ ┃┃┫┃┫┃┫
|
||||
# ┻ ┗┛┛ ┛ ┗┗┛┗┛ ┗┛ ┻ ┗┛┗ ┛┗┗┛┗┛┣┛┗┛┗ ┻┗┛┗┛┗┛
|
||||
# ┛
|
||||
|
||||
elif inbound_data.softwareClient == "mikrotikHotspot1000":
|
||||
|
||||
pass
|
||||
|
||||
# ┳┓
|
||||
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
||||
@@ -206,6 +235,7 @@ async def authorize_software_client(
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
message = message,
|
||||
data = {
|
||||
"client": inbound_data.softwareClient,
|
||||
"authorized": success
|
||||
|
||||
+18
@@ -97,6 +97,9 @@ from controllers_v2.finstitutions.trading.paper_trading import PaperTradingContr
|
||||
# ---
|
||||
from controllers_v2.finstitutions.payments.all_payments import AllPaymentsController
|
||||
from controllers_v2.finstitutions.payments.safaricom_mpesa_express import SafaricomMPesaExpressPaymentsController
|
||||
# ---
|
||||
from controllers_v2.software.mikrotik.all_mikrotik import AllMikroTikController
|
||||
from controllers_v2.software.mikrotik.mikrotik_pppoe_1000 import MikroTikPPPoE1000Controller
|
||||
|
||||
# To make REST API calls:
|
||||
import httpx
|
||||
@@ -557,6 +560,21 @@ async def app_startup(**kwargs):
|
||||
)
|
||||
current_app.printer("Finstitutions/Payments (C) ready.")
|
||||
|
||||
# Software / Mikrotik:
|
||||
current_app.mikrotik_controller = AllMikroTikController(
|
||||
cache = current_app.module_cache,
|
||||
http_client = current_app.http_client,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
debug = enable_debugging
|
||||
)
|
||||
current_app.mikrotik_pppoe_1000_controller = MikroTikPPPoE1000Controller(
|
||||
cache = current_app.module_cache,
|
||||
http_client = current_app.http_client,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
debug = enable_debugging
|
||||
)
|
||||
current_app.printer("Software/MikroTik (C) ready.")
|
||||
|
||||
# ┏┓ ┓ ┏┓┓•
|
||||
# ┃ ┏┓┏┓┏┓┏┓┏╋┏┓┏┓┏ ┏┓┏┓┏┫ ┃ ┃┓┏┓┏┓╋┏
|
||||
# ┗┛┗┛┛┗┛┗┗ ┗┗┗┛┛ ┛ ┗┻┛┗┗┻ ┗┛┗┗┗ ┛┗┗┛
|
||||
|
||||
Reference in New Issue
Block a user