Skip to content

Commit 15bfcba

Browse files
committed
add types for SR rules
1 parent 84f4ca0 commit 15bfcba

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

src/confluent_kafka/schema_registry/error.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
from typing import Optional
19+
1820
try:
1921
from fastavro.schema import SchemaParseException, UnknownType
2022
except ImportError:
@@ -41,15 +43,15 @@ class SchemaRegistryError(Exception):
4143
""" # noqa: E501
4244
UNKNOWN = -1
4345

44-
def __init__(self, http_status_code: int, error_code: int, error_message: str):
46+
def __init__(self, http_status_code: int, error_code: int, error_message: str) -> None:
4547
self.http_status_code = http_status_code
4648
self.error_code = error_code
4749
self.error_message = error_message
4850

49-
def __repr__(self):
51+
def __repr__(self) -> str:
5052
return str(self)
5153

52-
def __str__(self):
54+
def __str__(self) -> str:
5355
return "{} (HTTP status code {}, SR code {})".format(self.error_message,
5456
self.http_status_code,
5557
self.error_code)
@@ -58,7 +60,8 @@ def __str__(self):
5860
class OAuthTokenError(Exception):
5961
"""Raised when an OAuth token cannot be retrieved."""
6062

61-
def __init__(self, message, status_code=None, response_text=None):
63+
def __init__(self, message: str, status_code: Optional[int] = None,
64+
response_text: Optional[str] = None) -> None:
6265
self.message = message
6366
self.status_code = status_code
6467
self.response_text = response_text

src/confluent_kafka/schema_registry/rules/cel/cel_field_presence.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
import threading
17+
from typing import Any
1718

1819
import celpy # type: ignore
1920

@@ -33,9 +34,9 @@ def in_has() -> bool:
3334

3435

3536
class InterpretedRunner(celpy.InterpretedRunner):
36-
def evaluate(self, context):
37+
def evaluate(self, context: Any) -> Any:
3738
class Evaluator(celpy.Evaluator):
38-
def macro_has_eval(self, exprlist) -> celpy.celtypes.BoolType:
39+
def macro_has_eval(self, exprlist: Any) -> celpy.celtypes.BoolType:
3940
_has_state.in_has = True
4041
result = super().macro_has_eval(exprlist)
4142
_has_state.in_has = False

src/confluent_kafka/schema_registry/rules/encryption/awskms/aws_driver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
from typing import Dict, Any, Optional
1516

1617
import boto3
1718
import tink
@@ -34,13 +35,13 @@
3435

3536

3637
class AwsKmsDriver(KmsDriver):
37-
def __init__(self):
38+
def __init__(self) -> None:
3839
pass
3940

4041
def get_key_url_prefix(self) -> str:
4142
return _PREFIX
4243

43-
def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
44+
def new_kms_client(self, conf: Dict[str, Any], key_url: Optional[str]) -> KmsClient:
4445
uri_prefix = _PREFIX
4546
if key_url is not None:
4647
uri_prefix = key_url
@@ -92,7 +93,7 @@ def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
9293
return new_client(boto3_client=client, key_uri=uri_prefix)
9394

9495
@classmethod
95-
def register(cls):
96+
def register(cls) -> None:
9697
register_kms_driver(AwsKmsDriver())
9798

9899

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from typing import Dict, Any, Optional
1415

1516
from azure.identity import DefaultAzureCredential, ClientSecretCredential
1617

@@ -28,13 +29,13 @@
2829

2930

3031
class AzureKmsDriver(KmsDriver):
31-
def __init__(self):
32+
def __init__(self) -> None:
3233
pass
3334

3435
def get_key_url_prefix(self) -> str:
3536
return _PREFIX
3637

37-
def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
38+
def new_kms_client(self, conf: Dict[str, Any], key_url: Optional[str]) -> KmsClient:
3839
uri_prefix = _PREFIX
3940
if key_url is not None:
4041
uri_prefix = key_url
@@ -50,5 +51,5 @@ def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
5051
return AzureKmsClient(uri_prefix, creds)
5152

5253
@classmethod
53-
def register(cls):
54+
def register(cls) -> None:
5455
register_kms_driver(AzureKmsDriver())

src/confluent_kafka/schema_registry/rules/encryption/gcpkms/gcp_driver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from typing import Dict, Any, Optional
1415

1516
import tink
1617
from google.oauth2 import service_account
@@ -32,13 +33,13 @@
3233

3334

3435
class GcpKmsDriver(KmsDriver):
35-
def __init__(self):
36+
def __init__(self) -> None:
3637
pass
3738

3839
def get_key_url_prefix(self) -> str:
3940
return _PREFIX
4041

41-
def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
42+
def new_kms_client(self, conf: Dict[str, Any], key_url: Optional[str]) -> KmsClient:
4243
uri_prefix = _PREFIX
4344
if key_url is not None:
4445
uri_prefix = key_url
@@ -70,7 +71,7 @@ def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
7071
return _GcpKmsClient(uri_prefix, creds)
7172

7273
@classmethod
73-
def register(cls):
74+
def register(cls) -> None:
7475
register_kms_driver(GcpKmsDriver())
7576

7677

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
from typing import Dict, Any, Optional
1516

1617
from tink import KmsClient
1718

@@ -28,13 +29,13 @@
2829

2930

3031
class HcVaultKmsDriver(KmsDriver):
31-
def __init__(self):
32+
def __init__(self) -> None:
3233
pass
3334

3435
def get_key_url_prefix(self) -> str:
3536
return _PREFIX
3637

37-
def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
38+
def new_kms_client(self, conf: Dict[str, Any], key_url: Optional[str]) -> KmsClient:
3839
uri_prefix = _PREFIX
3940
if key_url is not None:
4041
uri_prefix = key_url
@@ -53,5 +54,5 @@ def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
5354
return HcVaultKmsClient(uri_prefix, token, namespace, role_id, secret_id)
5455

5556
@classmethod
56-
def register(cls):
57+
def register(cls) -> None:
5758
register_kms_driver(HcVaultKmsDriver())

src/confluent_kafka/schema_registry/rules/encryption/localkms/local_driver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
from typing import Dict, Any, Optional
1516

1617
import tink
1718
from tink import KmsClient
@@ -26,13 +27,13 @@
2627

2728

2829
class LocalKmsDriver(KmsDriver):
29-
def __init__(self):
30+
def __init__(self) -> None:
3031
pass
3132

3233
def get_key_url_prefix(self) -> str:
3334
return _PREFIX
3435

35-
def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
36+
def new_kms_client(self, conf: Dict[str, Any], key_url: Optional[str]) -> KmsClient:
3637
secret = conf.get(_SECRET)
3738
if secret is None:
3839
secret = os.getenv("LOCAL_SECRET")
@@ -41,5 +42,5 @@ def new_kms_client(self, conf: dict, key_url: str) -> KmsClient:
4142
return LocalKmsClient(secret)
4243

4344
@classmethod
44-
def register(cls):
45+
def register(cls) -> None:
4546
register_kms_driver(LocalKmsDriver())

0 commit comments

Comments
 (0)