Base¶
Infisical Base Resource.
InfisicalResourceRequest
¶
Bases: BaseModel
Base model for Infisical resource requests.
Attributes:
| Name | Type | Description |
|---|---|---|
workspace_id |
str
|
The ID of the workspace. |
environment |
str
|
The environment name. |
Source code in src/infisical/resources/base.py
InfisicalAPI
¶
Base class for Infisical API resources.
This class provides common functionality for all Infisical resources, such as formatting URLs, raising resource errors, and verifying required parameters. It is not meant to be used directly, but rather as a base class for the specific resource classes.
To implement a new resource, inherit from this class and implement the required methods.
The base_uri attribute should be set to the base URI of the resource. The resource-specific methods
should be named according to the names designated in https://infisical.com/docs/api-reference/overview/introduction.
For example, the Retrieve GET request would have a method named retrieve. In the list below, we just use
placeholder names for the functions, but the real functions should use the actual names from the API documentation.
The function signature should be defined as follows, which is dependent on the type of HTTP request:
- GET:
def get_method(self, arg1, arg2, **params: Unpack[QueryParams]) -> BaseModel - POST:
def post_method(self, request_model: RequestModel) -> BaseModel - PUT:
def put_method(self, request_model: RequestModel) -> BaseModel - PATCH:
def patch_method(self, request_model: RequestModel) -> BaseModel - DELETE:
def delete_method(self, request_model: RequestModel) -> BaseModel
The QueryParams should be a TypedDict that defines the query parameters for the specific API URI, the
RequestModel should be a Pydantic BaseModel that defines the request body for the specific API URI which is
generated by the model_dump method, and the return type should be a Pydantic BaseModel that defines the
response body for the specific API URI.
Note
In the GET signature above, arg1 and arg2 represent path parameters within the URL, while params are
the optional query parameters. If any of the query parameters are required, they should be added to the
required_params list in the verify_required_params call inside the function.
Typical method implementation
def list_my_resources(self, name: str, **params: Unpack[ResourceQueryParams]) -> ResourceList:
# Only log INFO once per request to avoid clutter
self.logger.info("Listing resources with params %s", params)
# Verify that the required parameters are present, typically the workspaceId and environment
self.verify_required_params(required_params=["workspaceId", "environment"], params=params)
# Format the URL with the resource name and parameters
url = self._format_url(f"/{name}")
# Create the request with the formatted URL and parameters
request = self.client.create_request(
method="get", url=url, params=params,
)
# Return `handle_request` from the client with the request and expected response model(s)
return self.client.handle_request(request=request, expected_responses={"resources": ResourceList})
Source code in src/infisical/resources/base.py
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 | |
__init__
¶
Initialize the resource with the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
SyncOrAsyncClient
|
An initialized InfisicalClient or InfisicalAsyncClient. |
required |
Source code in src/infisical/resources/base.py
raise_resource_error
¶
raise_resource_error(message: str) -> None
Raise an error for the resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The error message to raise. |
required |
Raises:
| Type | Description |
|---|---|
InfisicalResourceError
|
Uses your provided |
Source code in src/infisical/resources/base.py
verify_required_params
¶
Verify that the required parameters are present.
The required_params list should contain the names of the parameters from the method's
**params: Unpack[QueryParams] argument. The params dictionary should contain all the optional
query parameters passed to the method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required_params
|
list[str]
|
List of required parameters. |
required |
params
|
dict
|
Dictionary of parameters to verify. |
required |
Raises:
| Type | Description |
|---|---|
InfisicalResourceError
|
If any required parameters are missing. |