Created
July 9, 2019 08:04
-
-
Save mk0y/972331920a1be2835994c0bfa9733ca5 to your computer and use it in GitHub Desktop.
Register AVRO schema
This file contains hidden or 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
#!/usr/bin/env python | |
import os | |
import sys | |
import requests | |
schema_registry_url = sys.argv[1] | |
topic = sys.argv[2] | |
schema_file = sys.argv[3] | |
aboslute_path_to_schema = os.path.join(os.getcwd(), schema_file) | |
print("Schema Registry URL: " + schema_registry_url) | |
print("Topic: " + topic) | |
print("Schema file: " + schema_file) | |
with open(aboslute_path_to_schema, 'r') as content_file: | |
schema = content_file.read() | |
payload = "{ \"schema\": \"" \ | |
+ schema.replace("\"", "\\\"").replace("\t", "").replace("\n", "") \ | |
+ "\" }" | |
print("Payload: " + payload) | |
url = schema_registry_url + "/subjects/" + topic + "-value/versions" | |
headers = {"Content-Type": "application/vnd.schemaregistry.v1+json"} | |
r = requests.post(url, headers=headers, data=payload) | |
if r.status_code == requests.codes.ok: | |
print("Success") | |
else: | |
r.raise_for_status() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment