(20250212) Started a new util to handle MikroTik config. in async mode through REST API.
This commit is contained in:
@@ -39,6 +39,7 @@ sys.path.append("..")
|
||||
import io
|
||||
|
||||
# The base model:
|
||||
from utils_v2.rest.controllers.auth import RESTAuth
|
||||
from utils_v2.rest.models.api_call import ApiResponse
|
||||
|
||||
# My utils:
|
||||
@@ -156,7 +157,8 @@ class AsyncREST:
|
||||
url: str,
|
||||
headers: dict = None,
|
||||
params: dict = None,
|
||||
auth: httpx.Auth = None
|
||||
auth: RESTAuth = None,
|
||||
request_id: str | int = None
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
@@ -165,6 +167,7 @@ class AsyncREST:
|
||||
:param headers: The headers to pass.
|
||||
:param params: The params to send in the query string itself.
|
||||
:param auth: Any authentication credentials that need to be sent.
|
||||
:param request_id: An id to give this request. Can be useful for debugging later.
|
||||
:return: A structured response that includes the raw response, the exception (if any), and so on.
|
||||
"""
|
||||
|
||||
@@ -172,7 +175,10 @@ class AsyncREST:
|
||||
api_response = ApiResponse(
|
||||
action = inspect.stack()[1].function,
|
||||
url = url,
|
||||
method = "GET"
|
||||
method = "GET",
|
||||
requestHeaders = headers,
|
||||
requestParams = params,
|
||||
requestId = request_id
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -182,7 +188,7 @@ class AsyncREST:
|
||||
url = url,
|
||||
headers = headers,
|
||||
params = params,
|
||||
auth = auth
|
||||
auth = auth.encode()
|
||||
)
|
||||
|
||||
# Note down the results:
|
||||
@@ -209,7 +215,8 @@ class AsyncREST:
|
||||
json: dict = None,
|
||||
data: dict = None,
|
||||
content: str | bytes = None,
|
||||
auth: httpx.Auth = None
|
||||
auth: RESTAuth = None,
|
||||
request_id: str | int = None
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
@@ -220,6 +227,7 @@ class AsyncREST:
|
||||
:param data: The params to send in the form-data in the body.
|
||||
:param content: The raw content to be sent in the body (typically as an octet-stream).
|
||||
:param auth: Any authentication credentials that need to be sent.
|
||||
:param request_id: An id to give this request. Can be useful for debugging later.
|
||||
:return: A structured response that includes the raw response, the exception (if any), and so on.
|
||||
"""
|
||||
|
||||
@@ -227,7 +235,12 @@ class AsyncREST:
|
||||
api_response = ApiResponse(
|
||||
action = inspect.stack()[1].function,
|
||||
url = url,
|
||||
method = "POST"
|
||||
method = "POST",
|
||||
requestHeaders = headers,
|
||||
requestJson = json,
|
||||
requestData = data,
|
||||
requestContent = content,
|
||||
requestId = request_id
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -239,7 +252,7 @@ class AsyncREST:
|
||||
json = json,
|
||||
data = data,
|
||||
content = content,
|
||||
auth = auth
|
||||
auth = auth.encode()
|
||||
)
|
||||
|
||||
# Note down the results:
|
||||
@@ -265,7 +278,8 @@ class AsyncREST:
|
||||
headers: dict = None,
|
||||
json: dict = None,
|
||||
data: dict = None,
|
||||
auth: httpx.Auth = None
|
||||
auth: RESTAuth = None,
|
||||
request_id: str | int = None
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
@@ -275,6 +289,7 @@ class AsyncREST:
|
||||
:param json: The params to send in the JSON body.
|
||||
:param data: The params to send in the form-data in the body.
|
||||
:param auth: Any authentication credentials that need to be sent.
|
||||
:param request_id: An id to give this request. Can be useful for debugging later.
|
||||
:return: A structured response that includes the raw response, the exception (if any), and so on.
|
||||
"""
|
||||
|
||||
@@ -282,7 +297,11 @@ class AsyncREST:
|
||||
api_response = ApiResponse(
|
||||
action = inspect.stack()[1].function,
|
||||
url = url,
|
||||
method = "PUT"
|
||||
method = "PUT",
|
||||
requestHeaders = headers,
|
||||
requestJson = json,
|
||||
requestData = data,
|
||||
requestId = request_id
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -293,7 +312,7 @@ class AsyncREST:
|
||||
headers = headers,
|
||||
json = json,
|
||||
data = data,
|
||||
auth = auth
|
||||
auth = auth.encode()
|
||||
)
|
||||
|
||||
# Note down the results:
|
||||
@@ -320,7 +339,8 @@ class AsyncREST:
|
||||
json: dict = None,
|
||||
data: dict = None,
|
||||
content: str | bytes = None,
|
||||
auth: httpx.Auth = None
|
||||
auth: RESTAuth = None,
|
||||
request_id: str | int = None
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
@@ -331,6 +351,7 @@ class AsyncREST:
|
||||
:param data: The params to send in the form-data in the body.
|
||||
:param content: The raw content to be sent in the body (typically as an octet-stream).
|
||||
:param auth: Any authentication credentials that need to be sent.
|
||||
:param request_id: An id to give this request. Can be useful for debugging later.
|
||||
:return: A structured response that includes the raw response, the exception (if any), and so on.
|
||||
"""
|
||||
|
||||
@@ -338,7 +359,11 @@ class AsyncREST:
|
||||
api_response = ApiResponse(
|
||||
action = inspect.stack()[1].function,
|
||||
url = url,
|
||||
method = "PATCH"
|
||||
method = "PATCH",
|
||||
requestHeaders = headers,
|
||||
requestJson = json,
|
||||
requestData = data,
|
||||
requestId = request_id
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -350,7 +375,7 @@ class AsyncREST:
|
||||
json = json,
|
||||
data = data,
|
||||
content = content,
|
||||
auth = auth
|
||||
auth = auth.encode()
|
||||
)
|
||||
|
||||
# Note down the results:
|
||||
@@ -374,7 +399,8 @@ class AsyncREST:
|
||||
self,
|
||||
url: str,
|
||||
headers: dict = None,
|
||||
auth: httpx.Auth = None
|
||||
auth: RESTAuth = None,
|
||||
request_id: str | int = None
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
@@ -382,6 +408,7 @@ class AsyncREST:
|
||||
:param url: The URL to call.
|
||||
:param headers: The headers to pass.
|
||||
:param auth: Any authentication credentials that need to be sent.
|
||||
:param request_id: An id to give this request. Can be useful for debugging later.
|
||||
:return: A structured response that includes the raw response, the exception (if any), and so on.
|
||||
"""
|
||||
|
||||
@@ -389,7 +416,9 @@ class AsyncREST:
|
||||
api_response = ApiResponse(
|
||||
action = inspect.stack()[1].function,
|
||||
url = url,
|
||||
method = "DELETE"
|
||||
method = "DELETE",
|
||||
requestHeaders = headers,
|
||||
requestId = request_id
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -398,7 +427,7 @@ class AsyncREST:
|
||||
response = await self._http_client.delete(
|
||||
url = url,
|
||||
headers = headers,
|
||||
auth = auth
|
||||
auth = auth.encode()
|
||||
)
|
||||
|
||||
# Note down the results:
|
||||
|
||||
Reference in New Issue
Block a user