Skip to content

Commit 39d2c63

Browse files
debussymanclaude
andcommitted
Format code with black and update vault API endpoints
- Format crypto_provider.py and test_vault.py with black - Update vault API endpoints from data_keys to keys/data-key and keys/decrypt - Remove duplicate test case in test_vault.py 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5257e00 commit 39d2c63

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

tests/test_vault.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,6 @@ def test_update_object_missing_object_id(self):
269269
):
270270
self.vault.update_object(object_id="", value="test-value")
271271

272-
def test_update_object_empty_value(self):
273-
with pytest.raises(
274-
ValueError,
275-
match="Incomplete arguments: 'object_id' is a required argument",
276-
):
277-
self.vault.update_object(object_id="", value="updated-value")
278-
279272
def test_update_object_none_object_id(self):
280273
with pytest.raises(
281274
ValueError,
@@ -316,7 +309,7 @@ def test_create_data_key_success(
316309
)
317310

318311
assert request_kwargs["method"] == "post"
319-
assert request_kwargs["url"].endswith("/vault/v1/data_keys")
312+
assert request_kwargs["url"].endswith("/vault/v1/keys/data-key")
320313
assert request_kwargs["json"]["key_context"] == {"key": "test-key"}
321314
assert data_key_pair.data_key.id == "key_01234567890abcdef"
322315
assert data_key_pair.encrypted_keys == "ZW5jcnlwdGVkX2tleXNfZGF0YQ=="
@@ -331,7 +324,7 @@ def test_decrypt_data_key_success(
331324
data_key = self.vault.decrypt_data_key(keys="ZW5jcnlwdGVkX2tleXNfZGF0YQ==")
332325

333326
assert request_kwargs["method"] == "post"
334-
assert request_kwargs["url"].endswith("/vault/v1/data_keys/decrypt")
327+
assert request_kwargs["url"].endswith("/vault/v1/keys/decrypt")
335328
assert request_kwargs["json"]["keys"] == "ZW5jcnlwdGVkX2tleXNfZGF0YQ=="
336329
assert data_key.id == "key_01234567890abcdef"
337330
assert data_key.key == "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY="
@@ -351,7 +344,7 @@ def test_encrypt_success(
351344

352345
# Verify create_data_key was called
353346
assert request_kwargs["method"] == "post"
354-
assert request_kwargs["url"].endswith("/vault/v1/data_keys")
347+
assert request_kwargs["url"].endswith("/vault/v1/keys/data-key")
355348
assert request_kwargs["json"]["key_context"] == {"key": "test-key"}
356349

357350
# Verify we got encrypted data back

workos/utils/crypto_provider.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,29 @@
55

66

77
class CryptoProvider:
8-
def encrypt(self, plaintext: bytes, key: bytes, iv: bytes, aad: Optional[bytes]) -> dict[str, bytes]:
8+
def encrypt(
9+
self, plaintext: bytes, key: bytes, iv: bytes, aad: Optional[bytes]
10+
) -> dict[str, bytes]:
911
encryptor = Cipher(
10-
algorithms.AES(key),
11-
modes.GCM(iv),
12-
backend=default_backend()
12+
algorithms.AES(key), modes.GCM(iv), backend=default_backend()
1313
).encryptor()
1414

1515
if aad:
1616
encryptor.authenticate_additional_data(aad)
1717

1818
ciphertext = encryptor.update(plaintext) + encryptor.finalize()
19-
return {
20-
"ciphertext": ciphertext,
21-
"iv": iv,
22-
"tag": encryptor.tag
23-
}
19+
return {"ciphertext": ciphertext, "iv": iv, "tag": encryptor.tag}
2420

2521
def decrypt(
2622
self,
2723
ciphertext: bytes,
2824
key: bytes,
2925
iv: bytes,
3026
tag: bytes,
31-
aad: Optional[bytes] = None
27+
aad: Optional[bytes] = None,
3228
) -> bytes:
3329
decryptor = Cipher(
34-
algorithms.AES(key),
35-
modes.GCM(iv, tag),
36-
backend=default_backend()
30+
algorithms.AES(key), modes.GCM(iv, tag), backend=default_backend()
3731
).decryptor()
3832

3933
if aad:

workos/vault.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def create_data_key(self, *, key_context: KeyContext) -> DataKeyPair:
346346
}
347347

348348
response = self._http_client.request(
349-
"vault/v1/data_keys",
349+
"vault/v1/keys/data-key",
350350
method=REQUEST_METHOD_POST,
351351
json=request_data,
352352
)
@@ -363,7 +363,7 @@ def decrypt_data_key(
363363
}
364364

365365
response = self._http_client.request(
366-
"vault/v1/data_keys/decrypt",
366+
"vault/v1/keys/decrypt",
367367
method=REQUEST_METHOD_POST,
368368
json=request_data,
369369
)

0 commit comments

Comments
 (0)