Beispiel #1
0
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
Beispiel #2
0
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']
Beispiel #3
0
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']))
Beispiel #4
0
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']))
Beispiel #5
0
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))
Beispiel #6
0
 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")
Beispiel #7
0
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()
Beispiel #8
0
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()
Beispiel #9
0
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()