Base¶
Infisical Base Client Module.
BaseClient
¶
Base Client for Infisical HTTPX clients.
This is the base class for InfisicalClient and InfisicalAsyncClient that handles the common functionality between the two clients, such as creating requests, handling responses, and managing the credentials.
Warning
DO NOT use this class directly.
Source code in src/infisical/clients/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
__init__
¶
__init__(**kwargs: Unpack[InfisicalClientParams]) -> None
Initialize with any optional parameter.
Source code in src/infisical/clients/base.py
__get_headers__
¶
Generate the headers for the request.
The headers will include the Authorization header with the bearer token and the Content-Type header if
the method is not a GET request. The Authorization header will be set to the token from the credentials
acquired from the InfisicalCredentialProviderChain. We call
get_token() every time to ensure we get a valid token, as there is refresh logic in the credential object
to handle token expiration.
Tip
Token refreshing only happens if the credentials acquired are Universal Auth credentials (Client ID and Secret). If the credentials are not Universal Auth credentials, the token cannot be refreshed and expiration will raise an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
HttpxMethod
|
The HTTP method for the request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: The headers for the request. |
Source code in src/infisical/clients/base.py
create_request
abstractmethod
¶
create_request(
method: Literal["get", "post", "put", "delete", "patch"],
url: str,
params: dict | None = None,
body: dict | None = None,
) -> Callable | Coroutine
Abstract method to create a request for the resource.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method should be implemented in the subclass. |
Source code in src/infisical/clients/base.py
__handle_response__
¶
__handle_response__(
response: Response, expected_responses: dict[str, BaseModel] | None = None
) -> BaseModel | Any
Handle the response from the request.
The response object will raise an exception if the status code is not 2xx. If the status code is 4xx or 5xx,
it will raise an InfisicalHTTPError stacked with the httpx.HTTPStatusError.
We will parse error response JSON to provide more context about the error.
If the status code is 2xx, it will validate the response JSON against the expected responses, which is a dict
of response JSON keys to their corresponding models. If the key is an empty string, it will validate the
entire response JSON against the model. If none of the keys are found in the response JSON, it will raise a
ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The response object from the request. |
required |
expected_responses
|
dict[str, BaseModel]
|
A dict of response JSON keys to their corresponding models. |
None
|
Raises:
| Type | Description |
|---|---|
InfisicalHTTPError
|
If the status code is not 2xx. |
ValueError
|
If none of the keys are found in the response JSON. |
Returns:
| Type | Description |
|---|---|
BaseModel
|
The validated response model. |
Any
|
The raw response JSON if no expected responses are provided. |