Skip to content

Commit a5ff8aa

Browse files
committed
encryption clients
1 parent d9df343 commit a5ff8aa

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/confluent_kafka/schema_registry/rules/encryption/azurekms/azure_client.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,27 @@ class AzureKmsClient(tink.KmsClient):
3030
"""Basic Azure client for AEAD."""
3131

3232
def __init__(
33-
self, key_uri: Optional[str], credentials: TokenCredential
33+
self, key_uri: str, credentials: TokenCredential
3434
) -> None:
3535
"""Creates a new AzureKmsClient that is bound to the key specified in 'key_uri'.
3636
3737
Uses the specified credentials when communicating with the KMS.
3838
3939
Args:
40-
key_uri: The URI of the key the client should be bound to. If it is None
41-
or empty, then the client is not bound to any particular key.
40+
key_uri: The URI of the key the client should be bound to.
4241
credentials: The token credentials.
4342
4443
Raises:
4544
TinkError: If the key uri is not valid.
4645
"""
4746

48-
if not key_uri:
49-
self._key_uri = None
50-
self._client = None # type: ignore[assignment]
51-
elif key_uri.startswith(AZURE_KEYURI_PREFIX):
47+
if key_uri.startswith(AZURE_KEYURI_PREFIX):
5248
self._key_uri = key_uri
53-
key_id = key_uri[len(AZURE_KEYURI_PREFIX):]
54-
self._client = CryptographyClient(key_id, credentials)
5549
else:
5650
raise tink.TinkError('Invalid key_uri.')
51+
52+
key_id = key_uri[len(AZURE_KEYURI_PREFIX):]
53+
self._client = CryptographyClient(key_id, credentials)
5754

5855
def does_support(self, key_uri: str) -> bool:
5956
"""Returns true iff this client supports KMS key specified in 'key_uri'.

src/confluent_kafka/schema_registry/rules/encryption/hcvault/hcvault_client.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,35 @@ class HcVaultKmsClient(tink.KmsClient):
2929
"""Basic HashiCorp Vault client for AEAD."""
3030

3131
def __init__(
32-
self, key_uri: Optional[str], token: Optional[str], ns: Optional[str] = None,
32+
self, key_uri: str, token: Optional[str], ns: Optional[str] = None,
3333
role_id: Optional[str] = None, secret_id: Optional[str] = None
3434
) -> None:
3535
"""Creates a new HcVaultKmsClient that is bound to the key specified in 'key_uri'.
3636
3737
Uses the specified credentials when communicating with the KMS.
3838
3939
Args:
40-
key_uri: The URI of the key the client should be bound to. If it is None
41-
or empty, then the client is not bound to any particular key.
40+
key_uri: The URI of the key the client should be bound to.
4241
token: The Vault token.
4342
ns: The Vault namespace.
4443
4544
Raises:
4645
TinkError: If the key uri is not valid.
4746
"""
4847

49-
if not key_uri:
50-
self._key_uri = None
51-
self._client = None # type: ignore[assignment]
52-
elif key_uri.startswith(VAULT_KEYURI_PREFIX):
48+
if key_uri.startswith(VAULT_KEYURI_PREFIX):
5349
self._key_uri = key_uri
54-
parsed = urlparse(key_uri[len(VAULT_KEYURI_PREFIX):])
55-
vault_url = parsed.scheme + '://' + parsed.netloc
56-
self._client = hvac.Client(
57-
url=vault_url,
58-
token=token,
59-
namespace=ns,
60-
verify=False
61-
)
6250
else:
6351
raise tink.TinkError('Invalid key_uri.')
52+
53+
parsed = urlparse(key_uri[len(VAULT_KEYURI_PREFIX):])
54+
vault_url = parsed.scheme + '://' + parsed.netloc
55+
self._client = hvac.Client(
56+
url=vault_url,
57+
token=token,
58+
namespace=ns,
59+
verify=False
60+
)
6461
if role_id and secret_id and self._client is not None:
6562
self._client.auth.approle.login(role_id=role_id, secret_id=secret_id)
6663

0 commit comments

Comments
 (0)