forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3c7f42
commit 35a022c
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
sdk/python/feast/expediagroup/schema_registry/schema_registry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
Wrapper for SchemaRegistryClient, to separate Feast from | ||
the extensive auth and configuration process of | ||
connecting to a SchemaRegistry. | ||
Copyright 2024 Expedia Group | ||
Author: [email protected] | ||
""" | ||
|
||
import requests | ||
|
||
from confluent_kafka.schema_registry import SchemaRegistryClient | ||
|
||
|
||
class SchemaRegistry(): | ||
# spark: SparkSession | ||
# format: str | ||
# preprocess_fn: Optional[MethodType] | ||
# join_keys: List[str] | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def get_properties( | ||
user: String, | ||
password: String, | ||
urn: String, | ||
environment: String, | ||
cert_path: String, #https://stackoverflow.com/questions/55203791/python-requests-using-certificate-value-instead-of-path | ||
) -> dict: | ||
"""Discover a Schema Registry with the provided urn and credentials, | ||
and obtain a set of properties for use in Schema Registry calls.""" | ||
discovery_url = "https://stream-discovery-service-{environment}.rcp.us-east-1.data.{environment}.exp-aws.net/v2/discovery/urn/{urn}".format( | ||
environment=environment, urn=urn | ||
) | ||
|
||
response = requests.get( | ||
discovery_url, | ||
auth=(user, password), | ||
headers={"Accept": "application/json"}, | ||
verify=cert_path, | ||
) | ||
|
||
if response.status_code != 200: | ||
raise RuntimeError( | ||
"Discovery API returned unexpected HTTP status: {status}".format( | ||
status=str(response.status_code) | ||
) | ||
) | ||
|
||
try: | ||
props = json.loads(response.text) | ||
except (TypeError, UnicodeDecodeError): | ||
raise TypeError( | ||
"Discovery API response did not contain valid json: {response}".format( | ||
response=response.text | ||
) | ||
) | ||
|
||
return props |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters