def _get_subject_versions(host, session, subject): uri = host + '/subjects{/subject}/versions' uri = uriexpand(uri, subject=subject) r = session.get(uri) r.raise_for_status() versions = r.json() return versions
def _get_subject_compatibility(host, session, subject): uri = host + '/config{/subject}' uri = uriexpand(uri, subject=subject) r = session.get(uri) try: r.raise_for_status() except requests.HTTPError as e: if e.response.status_code == 404: return 'default' else: raise # 'compatibility' is the key in the docs, but apparently it changed return r.json()['compatibilityLevel']
def upload_schema(ctx, subject, schema): """Upload a new version of a subject. The subject is created by the command if necessary. """ host = ctx.obj['host'] session = ctx.obj['session'] schemadata = schema.read() # click automatically closes the file requestdata = {'schema': schemadata} uri = host + '/subjects{/subject}/versions' uri = uriexpand(uri, subject=subject) r = session.post(uri, json=requestdata) r.raise_for_status() data = r.json() print("Uploaded schema ID: {0:d}".format(data['id']))
def test_compatibility(ctx, subject, schema, version): """Test the compatibility of a schema with an existing version of a subject. """ host = ctx.obj['host'] session = ctx.obj['session'] schemadata = schema.read() # click automatically closes the file requestdata = {'schema': schemadata} uri = host + '/compatibility/subjects{/subject}/versions{/version}' uri = uriexpand(uri, subject=subject, version=version) r = session.post(uri, json=requestdata) r.raise_for_status() data = r.json() print('Compatible: {}'.format(data['is_compatible']))
def show_schema(ctx, subject, version): """Show the schema for a subject. By default this command shows the *latest* version of a subject's schema, but a particular version ID can be set with the --version/-v option. """ host = ctx.obj['host'] session = ctx.obj['session'] uri = host + '/subjects{/subject}/versions{/version}' uri = uriexpand(uri, subject=subject, version=version) r = session.get(uri) r.raise_for_status() data = r.json() actual_version = data['version'] schema = json.loads(data['schema']) print(f'{subject} version {actual_version:d}:\n') print(json.dumps(schema, sort_keys=True, indent=2))
def load(self, **kwargs): if self._url: uri = uriexpand(self._url, **kwargs) self.driver.get(uri) else: raise Exception(f"Cant load. {self.__class__} has not _url parameter")
def _delete_subject(host, session, subject): uri = host + '/subjects{/subject}' uri = uriexpand(uri, subject=subject) r = session.delete(uri) r.raise_for_status() return r.json()
def _delete_version(host, session, subject, version): uri = host + '/subjects{/subject}/versions{/version}' uri = uriexpand(uri, subject=subject, version=version) r = session.delete(uri) r.raise_for_status() return r.json()
def _set_subject_compatibility(host, session, subject, level): uri = host + '/config{/subject}' uri = uriexpand(uri, subject=subject) r = session.put(uri, json={'compatibility': level}) r.raise_for_status()