def do_transform_get(mc, args):
    """Get specific transform."""
    fields = {'transform_id': args.id}
    try:
        transform = mc.transforms.get(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(transform))
        return
    cols = ['id', 'tenant_id', 'name', 'description']
    formatters = {
        'id': lambda x: x['id'],
        'tenant_id': lambda x: x['tenant_id'],
        'name': lambda x: x['name'],
        'description': lambda x: x['description'],
    }
    # add to list so print_list will work
    transform_list = list()
    transform_list.append(transform)
    utils.print_list(transform_list, cols, formatters=formatters)
    specification = yaml.load(transform['specification'])
    print (yaml.dump(specification))
def do_stream_definition_list(mc, args):
    """Show list of stream definitions."""
    fields = {}
    if args.limit:
        fields['limit'] = args.limit
    if args.offset:
        fields['offset'] = args.offset
    try:
        definitions = mc.stream_definitions.list(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(definitions))
        return
    cols = ['id', 'name', 'description', 'select', 'group_by',
            'fire_criteria', 'expiration', 'fire_actions', 'expire_actions']
    formatters = {
        'id': lambda x: x['id'],
        'name': lambda x: x['name'],
        'description': lambda x: x['description'],
        'select': lambda x: utils.format_dictlist(x['select']),
        'group_by': lambda x: x['group_by'],
        'fire_criteria': lambda x: utils.format_dictlist(x['fire_criteria']),
        'expiration': lambda x: x['expiration'],
        'fire_actions': lambda x: x['fire_actions'],
        'expire_actions': lambda x: x['expire_actions'],
    }
    utils.print_list(definitions, cols, formatters=formatters)
def do_stream_definition_get(mc, args):
    """Get specific stream definition."""
    fields = {'definition_id': args.id}
    try:
        definition = mc.stream_definitions.get(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(definition))
        return
    cols = ['id', 'name', 'description', 'select', 'group_by',
            'fire_criteria', 'expiration', 'fire_actions', 'expire_actions']
    formatters = {
        'id': lambda x: x['id'],
        'name': lambda x: x['name'],
        'description': lambda x: x['description'],
        'select': lambda x: utils.format_dictlist(x['select']),
        'group_by': lambda x: x['group_by'],
        'fire_criteria': lambda x: utils.format_dictlist(x['fire_criteria']),
        'expiration': lambda x: x['expiration'],
        'fire_actions': lambda x: x['fire_actions'],
        'expire_actions': lambda x: x['expire_actions'],
    }
    # add to list so print_list will work
    definition_list = list()
    definition_list.append(definition)
    utils.print_list(definition_list, cols, formatters=formatters)
def do_event_get(mc, args):
    """Get specific event."""
    fields = {'event_id': args.id}
    try:
        event = mc.events.get(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(event))
        return
    cols = ['id', 'description', 'generated', 'data']
    formatters = {
        'id': lambda x: x['id'],
        'description': lambda x: x['description'],
        'generated': lambda x: x['generated'],
        'data': lambda x: utils.format_dict(x['data'])
    }
    utils.print_list(event, cols, formatters=formatters)
def do_event_list(mc, args):
    """Show list of events."""
    fields = {}
    if args.limit:
        fields['limit'] = args.limit
    if args.offset:
        fields['offset'] = args.offset
    try:
        events = mc.events.list(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(events))
        return
    cols = ['id', 'description', 'generated', 'data']
    formatters = {
        'id': lambda x: x['id'],
        'description': lambda x: x['description'],
        'generated': lambda x: x['generated'],
        'data': lambda x: utils.format_dict(x['data'])
    }
    utils.print_list(events, cols, formatters=formatters)
def do_transform_list(mc, args):
    """Show list of transforms."""
    fields = {}
    if args.limit:
        fields['limit'] = args.limit
    if args.offset:
        fields['offset'] = args.offset
    try:
        transforms = mc.transforms.list(**fields)
    except exc.HTTPException as he:
        raise exc.CommandError(
            'HTTPException code=%s message=%s' %
            (he.code, he.message))
    if args.json:
        print(utils.json_formatter(transforms))
        return
    cols = ['id', 'tenant_id', 'name', 'description']
    formatters = {
        'id': lambda x: x['id'],
        'tenant_id': lambda x: x['tenant_id'],
        'name': lambda x: x['name'],
        'description': lambda x: x['description'],
    }
    utils.print_list(transforms, cols, formatters=formatters)