Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/

#Ipython Notebook
.ipynb_checkpoints

# IDEs
.idea
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,147 @@ deleted_secret = client.secrets.delete_secret_by_name(

**Returns:**
- `BaseSecret`: The response after deleting the secret.

### `kms`

This sub-class handles KMS related operations:

#### List KMS Keys

```python
kms_keys = client.kms.list_keys(
project_id="<project-id>",
offset=0, # Optional
limit=100, # Optional
order_by=KmsKeysOrderBy.NAME, # Optional
order_direction=OrderDirection.ASC, # Optional
search=None # Optional
)
```

**Parameters:**
- `project_id` (str): The ID of your project.
- `offset` (int, optional): The offset to paginate from.
- `limit` (int, optional): The page size for paginating.
- `order_by` (KmsKeysOrderBy, optional): The key property to order the list response by.
- `order_direction` (OrderDirection, optional): The direction to order the list response in.
- `search` (str, optional): The text value to filter key names by.

**Returns:**
- `ListKmsKeysResponse`: The response containing the list of KMS keys.

#### Get KMS Key by ID

```python
kms_key = client.kms.get_key_by_id(
key_id="<key-id>"
)
```

**Parameters:**
- `key_id` (str): The ID of the key to retrieve.

**Returns:**
- `KmsKey`: The specified key.

#### Get KMS Key by Name

```python
kms_key = client.kms.get_key_by_name(
key_name="my-key",
project_id="<project-id>"
)
```

**Parameters:**
- `key_name` (str): The name of the key to retrieve.
- `project_id` (str): The ID of your project.

**Returns:**
- `KmsKey`: The specified key.

#### Create KMS Key

```python
kms_key = client.kms.create_key(
name="my-key",
project_id="<project-id>",
encryption_algorithm=SymmetricEncryption.AES_GCM_256,
description=None # Optional
)
```

**Parameters:**
- `name` (str): The name of the key (must be slug-friendly).
- `project_id` (str): The ID of your project.
- `encryption_algorithm` (SymmetricEncryption): The encryption alogrithm this key should use.
- `description` (str, optional): A description of your key.

**Returns:**
- `KmsKey`: The newly created key.

#### Update KMS Key

```python
updated_key = client.kms.update_key(
key_id="<key-id>",
name="my-updated-key", # Optional
description="Updated description", # Optional
is_disabled=True # Optional
)
```

**Parameters:**
- `key_id` (str): The ID of the key to be updated.
- `name` (str, optional): The updated name of the key (must be slug-friendly).
- `description` (str): The updated description of the key.
- `is_disabled` (str): The flag to disable operations with this key.

**Returns:**
- `KmsKey`: The updated key.

#### Delete KMS Key

```python
deleted_key = client.kms.delete_key(
key_id="<key-id>"
)
```

**Parameters:**
- `key_id` (str): The ID of the key to be deleted.

**Returns:**
- `KmsKey`: The deleted key.

#### Encrypt Data with KMS Key

```python
encrypted_data = client.kms.encrypt_data(
key_id="<key-id>",
base64EncodedPlaintext="TXkgc2VjcmV0IG1lc3NhZ2U=" # must be base64 encoded
)
```

**Parameters:**
- `key_id` (str): The ID of the key to encrypt the data with.
- `base64EncodedPlaintext` (str): The plaintext data to encrypt (must be base64 encoded).

**Returns:**
- `str`: The encrypted ciphertext.

#### Decrypte Data with KMS Key

```python
decrypted_data = client.kms.decrypt_data(
key_id="<key-id>",
ciphertext="Aq96Ry7sMH3k/ogaIB5MiSfH+LblQRBu69lcJe0GfIvI48ZvbWY+9JulyoQYdjAx"
)
```

**Parameters:**
- `key_id` (str): The ID of the key to decrypt the data with.
- `ciphertext` (str): The ciphertext returned from the encrypt operation.

**Returns:**
- `str`: The base64 encoded plaintext.
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

sdkInstance = InfisicalSDKClient(host="https://app.infisical.com")

sdkInstance.auth.universalAuth.login("<>", "<>")
sdkInstance.auth.universal_auth.login("<>", "<>")

# new_secret = sdkInstance.secrets.create_secret_by_name(
# secret_name="NEW_SECRET",
Expand Down
70 changes: 69 additions & 1 deletion infisical_sdk/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SingleSecretResponse(BaseModel):
secret: BaseSecret

@classmethod
def from_dict(cls, data: Dict) -> 'ListSecretsResponse':
def from_dict(cls, data: Dict) -> 'SingleSecretResponse':
return cls(
secret=BaseSecret.from_dict(data['secret']),
)
Expand All @@ -125,3 +125,71 @@ class MachineIdentityLoginResponse(BaseModel):
expiresIn: int
accessTokenMaxTTL: int
tokenType: str


class SymmetricEncryption(str, Enum):
AES_GCM_256 = "aes-256-gcm"
AES_GCM_128 = "aes-128-gcm"


class OrderDirection(str, Enum):
ASC = "asc"
DESC = "desc"


class KmsKeysOrderBy(str, Enum):
NAME = "name"


@dataclass
class KmsKey(BaseModel):
"""Infisical KMS Key"""
id: str
description: str
isDisabled: bool
orgId: str
name: str
createdAt: str
updatedAt: str
projectId: str
version: int
encryptionAlgorithm: SymmetricEncryption


@dataclass
class ListKmsKeysResponse(BaseModel):
"""Complete response model for Kms Keys API"""
keys: List[KmsKey]
totalCount: int

@classmethod
def from_dict(cls, data: Dict) -> 'ListKmsKeysResponse':
"""Create model from dictionary with camelCase keys, handling nested objects"""
return cls(
keys=[KmsKey.from_dict(key) for key in data['keys']],
totalCount=data['totalCount']
)


@dataclass
class SingleKmsKeyResponse(BaseModel):
"""Response model for get/create/update/delete API"""
key: KmsKey

@classmethod
def from_dict(cls, data: Dict) -> 'SingleKmsKeyResponse':
return cls(
key=KmsKey.from_dict(data['key']),
)


@dataclass
class KmsKeyEncryptDataResponse(BaseModel):
"""Response model for encrypt data API"""
ciphertext: str


@dataclass
class KmsKeyDecryptDataResponse(BaseModel):
"""Response model for decrypt data API"""
plaintext: str
Loading