|
| 1 | +from infisical_sdk.api_types import SymmetricEncryptionfrom infisical_sdk.api_types import KmsKeysOrderBy |
| 2 | + |
1 | 3 | # Infisical Python SDK |
2 | 4 |
|
3 | 5 | The Infisical SDK provides a convenient way to interact with the Infisical API. |
@@ -208,3 +210,147 @@ deleted_secret = client.secrets.delete_secret_by_name( |
208 | 210 |
|
209 | 211 | **Returns:** |
210 | 212 | - `BaseSecret`: The response after deleting the secret. |
| 213 | + |
| 214 | +### `kms` |
| 215 | + |
| 216 | +This sub-class handles KMS related operations: |
| 217 | + |
| 218 | +#### List KMS Keys |
| 219 | + |
| 220 | +```python |
| 221 | +kms_keys = client.kms.list_keys( |
| 222 | + project_id="<project-id>", |
| 223 | + offset=0, # Optional |
| 224 | + limit=100, # Optional |
| 225 | + order_by=KmsKeysOrderBy.NAME, # Optional |
| 226 | + order_direction=OrderDirection.ASC, # Optional |
| 227 | + search=None # Optional |
| 228 | +) |
| 229 | +``` |
| 230 | + |
| 231 | +**Parameters:** |
| 232 | +- `project_id` (str): The ID of your project. |
| 233 | +- `offset` (int, optional): The offset to paginate from. |
| 234 | +- `limit` (int, optional): The page size for paginating. |
| 235 | +- `order_by` (KmsKeysOrderBy, optional): The key property to order the list response by. |
| 236 | +- `order_direction` (OrderDirection, optional): The direction to order the list response in. |
| 237 | +- `search` (str, optional): The text value to filter key names by. |
| 238 | + |
| 239 | +**Returns:** |
| 240 | +- `ListKmsKeysResponse`: The response containing the list of KMS keys. |
| 241 | + |
| 242 | +#### Get KMS Key by ID |
| 243 | + |
| 244 | +```python |
| 245 | +kms_key = client.kms.get_key_by_id( |
| 246 | + key_id="<key-id>" |
| 247 | +) |
| 248 | +``` |
| 249 | + |
| 250 | +**Parameters:** |
| 251 | +- `key_id` (str): The ID of the key to retrieve. |
| 252 | + |
| 253 | +**Returns:** |
| 254 | +- `KmsKey`: The specified key. |
| 255 | + |
| 256 | +#### Get KMS Key by Name |
| 257 | + |
| 258 | +```python |
| 259 | +kms_key = client.kms.get_key_by_name( |
| 260 | + key_name="my-key", |
| 261 | + project_id="<project-id>" |
| 262 | +) |
| 263 | +``` |
| 264 | + |
| 265 | +**Parameters:** |
| 266 | +- `key_name` (str): The name of the key to retrieve. |
| 267 | +- `project_id` (str): The ID of your project. |
| 268 | + |
| 269 | +**Returns:** |
| 270 | +- `KmsKey`: The specified key. |
| 271 | + |
| 272 | +#### Create KMS Key |
| 273 | + |
| 274 | +```python |
| 275 | +kms_key = client.kms.create_key( |
| 276 | + name="my-key", |
| 277 | + project_id="<project-id>", |
| 278 | + encryption_algorithm=SymmetricEncryption.AES_GCM_256, |
| 279 | + description=None # Optional |
| 280 | +) |
| 281 | +``` |
| 282 | + |
| 283 | +**Parameters:** |
| 284 | +- `name` (str): The name of the key (must be slug-friendly). |
| 285 | +- `project_id` (str): The ID of your project. |
| 286 | +- `encryption_algorithm` (SymmetricEncryption): The encryption alogrithm this key should use. |
| 287 | +- `description` (str, optional): A description of your key. |
| 288 | + |
| 289 | +**Returns:** |
| 290 | +- `KmsKey`: The newly created key. |
| 291 | + |
| 292 | +#### Update KMS Key |
| 293 | + |
| 294 | +```python |
| 295 | +updated_key = client.kms.update_key( |
| 296 | + key_id="<key-id>", |
| 297 | + name="my-updated-key", # Optional |
| 298 | + description="Updated description", # Optional |
| 299 | + is_disabled=True # Optional |
| 300 | +) |
| 301 | +``` |
| 302 | + |
| 303 | +**Parameters:** |
| 304 | +- `key_id` (str): The ID of the key to be updated. |
| 305 | +- `name` (str, optional): The updated name of the key (must be slug-friendly). |
| 306 | +- `description` (str): The updated description of the key. |
| 307 | +- `is_disabled` (str): The flag to disable operations with this key. |
| 308 | + |
| 309 | +**Returns:** |
| 310 | +- `KmsKey`: The updated key. |
| 311 | + |
| 312 | +#### Delete KMS Key |
| 313 | + |
| 314 | +```python |
| 315 | +deleted_key = client.kms.delete_key( |
| 316 | + key_id="<key-id>" |
| 317 | +) |
| 318 | +``` |
| 319 | + |
| 320 | +**Parameters:** |
| 321 | +- `key_id` (str): The ID of the key to be deleted. |
| 322 | + |
| 323 | +**Returns:** |
| 324 | +- `KmsKey`: The deleted key. |
| 325 | + |
| 326 | +#### Encrypt Data with KMS Key |
| 327 | + |
| 328 | +```python |
| 329 | +encrypted_data = client.kms.encrypt_data( |
| 330 | + key_id="<key-id>", |
| 331 | + plaintext="TXkgc2VjcmV0IG1lc3NhZ2U=" # must be base64 encoded |
| 332 | +) |
| 333 | +``` |
| 334 | + |
| 335 | +**Parameters:** |
| 336 | +- `key_id` (str): The ID of the key to encrypt the data with. |
| 337 | +- `plaintext` (str): The plaintext data to encrypt (must be base64 encoded). |
| 338 | + |
| 339 | +**Returns:** |
| 340 | +- `str`: The encrypted ciphertext. |
| 341 | + |
| 342 | +#### Decrypte Data with KMS Key |
| 343 | + |
| 344 | +```python |
| 345 | +decrypted_data = client.kms.decrypt_data( |
| 346 | + key_id="<key-id>", |
| 347 | + ciphertext="Aq96Ry7sMH3k/ogaIB5MiSfH+LblQRBu69lcJe0GfIvI48ZvbWY+9JulyoQYdjAx" |
| 348 | +) |
| 349 | +``` |
| 350 | + |
| 351 | +**Parameters:** |
| 352 | +- `key_id` (str): The ID of the key to decrypt the data with. |
| 353 | +- `ciphertext` (str): The ciphertext returned from the encrypt operation. |
| 354 | + |
| 355 | +**Returns:** |
| 356 | +- `str`: The base64 encoded plaintext. |
0 commit comments