Exemplo n.º 1
0
def get_schema_version(topic_name, version, host=TASR_HOST,
                       port=TASR_PORT, timeout=TIMEOUT):
    ''' GET /tasr/topic/<topic name>/version/<version>
    Retrieve a specific schema registered for the given topic name identified
    by a version (a positive integer).  Returns a RegisteredSchema object.
    '''
    url = ('http://%s:%s/tasr/topic/%s/version/%s' %
           (host, port, topic_name, version))
    return reg_schema_from_url(url, timeout=timeout,
                               err_404='No such version.')
Exemplo n.º 2
0
def register_schema(topic_name, schema_str, host=TASR_HOST,
                          port=TASR_PORT, timeout=TIMEOUT):
    ''' PUT /tasr/topic/<topic name>
    Register a schema string for a topic.  Returns a SchemaMetadata object
    with the topic-version, topic-timestamp and ID metadata.
    '''
    url = 'http://%s:%s/tasr/topic/%s' % (host, port, topic_name)
    headers = {'content-type': 'application/json; charset=utf8', }
    rs = reg_schema_from_url(url, method='PUT', data=schema_str,
                             headers=headers, timeout=timeout)
    return rs
Exemplo n.º 3
0
def schema_for_id_str(id_str, host=TASR_HOST,
                          port=TASR_PORT, timeout=TIMEOUT):
    ''' GET /tasr/id/<ID string>
    Retrieves a schema that has been registered for at least one topic name as
    identified by a hash-based ID string.  The ID string is a base64 encoded
    byte sequence, starting with a 1-byte ID type and followed by fingerprint
    bytes for the ID type.  For example, with an SHA256-based ID, a fingerprint
    is 32 bytes in length, so there would be 33 ID bytes, which would produce
    an ID string of length 44 once base64-encoded.  The MD5-based IDs are 17
    bytes (1 + 16), producing ID strings of length 24.  A RegisteredSchema
    object is returned.
    '''
    url = 'http://%s:%s/tasr/id/%s' % (host, port, id_str)
    return reg_schema_from_url(url, timeout=timeout,
                               err_404='No schema for id.')