forked from datacontract/datacontract-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
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
74e98c6
commit 3c3704b
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
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
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
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,32 @@ | ||
import os | ||
|
||
import requests | ||
|
||
from datacontract.data_contract import DataContract | ||
|
||
|
||
def publish_to_datamesh_manager(data_contract: DataContract): | ||
try: | ||
headers = {"Content-Type": "application/json", "x-api-key": _require_datamesh_manager_api_key()} | ||
spec = data_contract.get_data_contract_specification() | ||
id = spec.id | ||
url = "https://api.datamesh-manager.com/api/datacontracts/{0}".format(id) | ||
request_body = spec.model_dump_json().encode("utf-8") | ||
response = requests.put( | ||
url=url, | ||
data=request_body, | ||
headers=headers, | ||
) | ||
if response.status_code != 200: | ||
print(f"Error publishing data contract to Data Mesh Manager: {response.text}") | ||
exit(1) | ||
print(f"Published data contract to {url}") | ||
except Exception as e: | ||
print(f"Failed publishing data contract. Error: {str(e)}") | ||
|
||
|
||
def _require_datamesh_manager_api_key(): | ||
datamesh_manager_api_key = os.getenv("DATAMESH_MANAGER_API_KEY") | ||
if datamesh_manager_api_key is None: | ||
raise Exception("Cannot publish data contract, as DATAMESH_MANAGER_API_KEY is not set") | ||
return datamesh_manager_api_key |