Add basic auth for rpc server
Browse files- src/libs/rpc_client.py +22 -2
src/libs/rpc_client.py
CHANGED
|
@@ -7,9 +7,29 @@ load_dotenv()
|
|
| 7 |
|
| 8 |
rpc_server_url = os.getenv('CHATXBT_RPC_SERVER_URL')
|
| 9 |
|
| 10 |
-
async def rpc_call(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
headers = {
|
| 12 |
'Content-Type': 'application/json',
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
payload = {
|
|
@@ -26,4 +46,4 @@ async def rpc_call(method_name, params: Optional[Union[dict, list]] = {}, url: s
|
|
| 26 |
return response.json()
|
| 27 |
except httpx.RequestError as e:
|
| 28 |
print(f"Error making RPC call: {e}")
|
| 29 |
-
return None
|
|
|
|
| 7 |
|
| 8 |
rpc_server_url = os.getenv('CHATXBT_RPC_SERVER_URL')
|
| 9 |
|
| 10 |
+
async def rpc_call(
|
| 11 |
+
method_name: str, # The name of the RPC method to be called
|
| 12 |
+
params: Optional[Union[dict, list]] = None, # Optional parameters for the RPC method
|
| 13 |
+
url: str = rpc_server_url # The URL of the RPC server
|
| 14 |
+
) -> dict: # Returns the JSON response from the RPC server
|
| 15 |
+
"""
|
| 16 |
+
This function makes an RPC call to the specified URL with the given method name and parameters.
|
| 17 |
+
|
| 18 |
+
Args:
|
| 19 |
+
method_name (str): The name of the RPC method to be called.
|
| 20 |
+
params (Optional[Union[dict, list]], optional): Optional parameters for the RPC method. Defaults to None.
|
| 21 |
+
url (str, optional): The URL of the RPC server. Defaults to rpc_server_url.
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
dict: The JSON response from the RPC server.
|
| 25 |
+
|
| 26 |
+
Raises:
|
| 27 |
+
httpx.RequestError: If an error occurs while making the RPC call.
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
headers = {
|
| 31 |
'Content-Type': 'application/json',
|
| 32 |
+
"Authorization": os.getenv('CHATXBT_RPC_SERVER_BASIC_AUTH_CREDENTIALS')
|
| 33 |
}
|
| 34 |
|
| 35 |
payload = {
|
|
|
|
| 46 |
return response.json()
|
| 47 |
except httpx.RequestError as e:
|
| 48 |
print(f"Error making RPC call: {e}")
|
| 49 |
+
return None
|