Ejemplo n.º 1
0
def get_table_metadata() -> Response:
    """
    call the metadata service endpoint and return matching results
    :return: a json output containing a table metdata object as 'tableData'

    Schema Defined Here: https://github.com/lyft/amundsenmetadatalibrary/blob/master/metadata_service/api/table.py
    TODO: Define type for this

    TODO: Define an interface for envoy_client
    """
    try:
        table_key = get_table_key(request.args)
        list_item_index = get_query_param(request.args, 'index')
        list_item_source = get_query_param(request.args, 'source')

        results_dict = _get_table_metadata(table_key=table_key,
                                           index=list_item_index,
                                           source=list_item_source)
        return make_response(
            jsonify(results_dict),
            results_dict.get('status_code', HTTPStatus.INTERNAL_SERVER_ERROR))
    except Exception as e:
        message = 'Encountered exception: ' + str(e)
        logging.exception(message)
        return make_response(jsonify({
            'tableData': {},
            'msg': message
        }), HTTPStatus.INTERNAL_SERVER_ERROR)
Ejemplo n.º 2
0
def update_table_tags() -> Response:
    @action_logging
    def _log_update_table_tags(*, table_key: str, method: str,
                               tag: str) -> None:
        pass  # pragma: no cover

    try:
        args = request.get_json()
        method = request.method

        table_endpoint = _get_table_endpoint()
        table_key = get_table_key(args)

        tag = get_query_param(args, 'tag')

        url = '{0}/{1}/tag/{2}'.format(table_endpoint, table_key, tag)

        _log_update_table_tags(table_key=table_key, method=method, tag=tag)

        response = request_metadata(url=url, method=method)
        status_code = response.status_code

        if status_code == HTTPStatus.OK:
            message = 'Success'
        else:
            message = 'Encountered error: {0} tag failed'.format(method)
            logging.error(message)

        payload = jsonify({'msg': message})
        return make_response(payload, status_code)
    except Exception as e:
        message = 'Encountered exception: ' + str(e)
        logging.exception(message)
        payload = jsonify({'msg': message})
        return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)
Ejemplo n.º 3
0
def get_column_description() -> Response:
    try:
        table_endpoint = _get_table_endpoint()
        table_key = get_table_key(request.args)

        column_name = get_query_param(request.args, 'column_name')

        url = '{0}/{1}/column/{2}/description'.format(table_endpoint,
                                                      table_key, column_name)

        response = request_metadata(url=url)
        status_code = response.status_code

        if status_code == HTTPStatus.OK:
            message = 'Success'
            description = response.json().get('description')
        else:
            message = 'Get column description failed'
            description = None

        payload = jsonify({'description': description, 'msg': message})
        return make_response(payload, status_code)
    except Exception as e:
        payload = jsonify({
            'description': None,
            'msg': 'Encountered exception: ' + str(e)
        })
        return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)
Ejemplo n.º 4
0
def put_table_description() -> Response:
    @action_logging
    def _log_put_table_description(*, table_key: str, description: str,
                                   source: str) -> None:
        pass  # pragma: no cover

    try:
        args = request.get_json()
        table_endpoint = _get_table_endpoint()

        table_key = get_table_key(args)

        description = get_query_param(args, 'description')
        description = ' '.join(description.split())
        src = get_query_param(args, 'source')

        url = '{0}/{1}/description/{2}'.format(table_endpoint, table_key,
                                               description)
        _log_put_table_description(table_key=table_key,
                                   description=description,
                                   source=src)

        response = request_metadata(url=url, method='PUT')
        status_code = response.status_code

        if status_code == HTTPStatus.OK:
            message = 'Success'
        else:
            message = 'Update table description failed'

        payload = jsonify({'msg': message})
        return make_response(payload, status_code)
    except Exception as e:
        payload = jsonify({'msg': 'Encountered exception: ' + str(e)})
        return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)
Ejemplo n.º 5
0
def update_table_owner() -> Response:
    try:
        args = request.get_json()
        table_key = get_table_key(args)
        owner = get_query_param(args, 'owner')

        payload = jsonify(
            _update_table_owner(table_key=table_key,
                                method=request.method,
                                owner=owner))
        return make_response(payload, HTTPStatus.OK)
    except Exception as e:
        payload = jsonify({'msg': 'Encountered exception: ' + str(e)})
        return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)