a1c1853ca5
git-subtree-dir: utils_v2 git-subtree-split: 88e444ac57ca6c090736645616d8a8a2d2af367b
149 lines
5.4 KiB
Python
149 lines
5.4 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Khushal P Soonderji
|
|
|
|
DATE:
|
|
|
|
Wednesday, 12th Feb., 2025.
|
|
|
|
OBJECTIVE:
|
|
|
|
To provide authentication abstraction for using with the Async REST class.
|
|
The idea is that if an input library changes, the rest of the code shouldn't change.
|
|
|
|
REFERENCES:
|
|
|
|
N/A
|
|
|
|
DOWNLOADS:
|
|
|
|
N/A
|
|
|
|
"""
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** IMPORT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# To make sibling directories accessible for imports:
|
|
import sys
|
|
sys.path.append(".")
|
|
sys.path.append("..")
|
|
|
|
# System-level activities:
|
|
import io
|
|
|
|
# The base model:
|
|
from utils_v2.rest.models.api_call import ApiResponse
|
|
|
|
# My utils:
|
|
from utils_v2.date_time import date_time
|
|
|
|
# To make API calls:
|
|
import httpx
|
|
|
|
# To work with date and time:
|
|
import datetime
|
|
|
|
# For working with datatypes:
|
|
from typing import Literal, List
|
|
|
|
# For creating abstract classes:
|
|
from abc import ABC, abstractmethod
|
|
|
|
# For debugging:
|
|
from icecream import IceCreamDebugger
|
|
import inspect
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** CLASSES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
class RESTAuth(ABC):
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
@staticmethod
|
|
def encode(self) -> httpx.Auth:
|
|
|
|
"""
|
|
Use this method to give the desired output. For example, in Basic Auth, you convert the input username and
|
|
password to a Base64 string. If you are using, say, the HTTPX library, you would want to return its class from
|
|
this method.
|
|
:return: Whatever object is needed by the library you are using inside 'AsyncREST'.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
class BasicAuth(RESTAuth):
|
|
|
|
def __init__(
|
|
self,
|
|
username: str,
|
|
password: str
|
|
):
|
|
|
|
super().__init__()
|
|
self._username = username
|
|
self._password = password
|
|
|
|
def encode(self) -> httpx.BasicAuth:
|
|
return httpx.BasicAuth(self._username, self._password)
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|