Esempio n. 1
0
File: group.py Progetto: pcn/cogctl
def group(ctx):
    """Manage Cog user groups.

    If invoked without a subcommand, lists all user groups.
    """
    if ctx.invoked_subcommand is None:
        groups = ctx.obj.api.groups()
        table = tbl.render_dicts(groups, ["name", "id"])
        output.echo(table)
Esempio n. 2
0
def role(context):
    """
    Manage roles and role grants.

    Lists roles when called without a subcommand.
    """
    if context.invoked_subcommand is None:
        roles = context.obj.api.roles()
        output = table.render_dicts(roles, ["name", "id"])
        click.echo(output)
Esempio n. 3
0
def trigger(context):
    """
    Create, edit, delete, and view Cog triggers.

    If invoked without a subcommand, lists all triggers.
    """
    if context.invoked_subcommand is None:
        triggers = context.obj.api.triggers()
        output = table.render_dicts(triggers, SUMMARY_FIELDS)
        click.echo(output)
Esempio n. 4
0
def info(group):
    "Show details of a single relay group."

    group_info = [["Name", group["name"]],
                  ["ID", group["id"]],
                  ["Creation Time", group["inserted_at"]]]

    click.echo(table.render(group_info))

    click.echo()
    click.echo("Relays")
    click.echo(table.render_dicts(
        sorted(group["relays"], key=itemgetter("name")),
        ["name", "id"]))

    click.echo()
    click.echo("Bundles")
    click.echo(table.render_dicts(
        sorted(group["bundles"], key=itemgetter("name")),
        ["name", "id"]))
Esempio n. 5
0
File: relay.py Progetto: pcn/cogctl
def relay(context):
    """
    Manage relays.

    Lists relays when called without a subcommand.
    """
    if context.invoked_subcommand is None:
        relays = context.obj.api.relays()
        for relay in relays:
            relay["status"] = "enabled" if relay["enabled"] else "disabled"
        output = table.render_dicts(relays, ["name", "status", "id"])
        click.echo(output)
Esempio n. 6
0
def permission(context):
    """
    Manage permissions.

    Lists permissions when called without a subcommand.
    """
    if context.invoked_subcommand is None:
        permissions = context.obj.api.permissions()
        for p in permissions:
            p["name"] = p["bundle"] + ":" + p["name"]
        output = table.render_dicts(permissions, ["name", "id"])
        click.echo(output)
Esempio n. 7
0
File: user.py Progetto: pcn/cogctl
def user(ctx):
    """Manage Cog users.

    If invoked without a subcommand, lists all the users on the
    server.
    """
    if ctx.invoked_subcommand is None:
        users = ctx.obj.api.users()
        data = [tx_user(user) for user in users]
        headers = ["username", "full_name", "email_address"]
        table = tbl.render_dicts(data, headers)
        output.echo(table)
Esempio n. 8
0
def relay_group(ctx):
    """Manage relay groups.

    If invoked without a subcommand, lists all relay groups that
    exist.

    """
    if ctx.invoked_subcommand is None:
        groups = ctx.obj.api.relay_groups()
        click.echo(table.render_dicts(
            sorted(groups, key=itemgetter("name")),
            # TODO: Not sure how useful "inserted_at" is?
            ["name", "inserted_at", "id"]))
Esempio n. 9
0
def chat_handle(context):
    """
    Manage user chat handles.

    Lists chat handles when called without a subcommand.
    """
    if context.invoked_subcommand is None:
        chat_handles = context.obj.api.chat_handles()
        chat_handles = [
            chat_handle_tx(chat_handle) for chat_handle in chat_handles
        ]
        output = table.render_dicts(chat_handles,
                                    ["user", "chat_provider", "handle"])
        click.echo(output)
Esempio n. 10
0
def test_table_render_dicts_default():
    dicts = [{
        "first_name": "Patrick",
        "last_name": "Van Stee",
        "email_address": "*****@*****.**",
        "username": "******"
    }, {
        "first_name": "Kevin",
        "last_name": "Smith",
        "email_address": "*****@*****.**",
        "username": "******"
    }]
    result = table.render_dicts(dicts)
    assert result == """\
Esempio n. 11
0
File: rule.py Progetto: pcn/cogctl
def list_rules(obj, command):
    rules = obj.api.rules_for_command(command)
    output = table.render_dicts(rules, ["id", "rule"])
    click.echo(output)