Ejemplo n.º 1
0
Archivo: user.py Proyecto: pcn/cogctl
def update(obj, first_name, last_name, email, username, password, user):
    """
    Updates an existing user.
    """
    # Create the updated user object
    attrs = {
        "first_name": first_name,
        "last_name": last_name,
        "email_address": email,
        "username": username,
        "password": password
    }

    # Get rid of 'None' values
    attrs = {key: value for (key, value) in attrs.items() if value is not None}

    # If there are no fields to update exit with an error
    if len(attrs) is 0:
        raise click.UsageError(message="You must specify a field to update.")

    output.debug("Updating '%s' with '%s'" % (user["username"], attrs))

    # Finally update the user
    updated = obj.api.update_user(user["id"], attrs)
    output.info(render_user(updated))
Ejemplo n.º 2
0
def create(state, bundle, config_file, layer):
    """Create a new dynamic configuration layer for a bundle.

    Layers are combined to create the final dynamic configuration that
    is in place when a command is executed. The layer names are as
    follows:

    - "base": in the absence of anything else, this configuration will
      be in effect.
    - "room/$ROOM": commands executed in the chat room `$ROOM` will
      layer this configuration on top of `base`
    - "user/$USER": commands executed by the user `$USER` will layer
      this configuration on last

    If no `--layer` option is given, a `base` layer is created.

    The configuration file given must be a YAML map.

    For more details, see
    https://cog-book.operable.io/sections/dynamic_command_configuration.html.
    """

    try:
        with click.open_file(config_file) as f:
            content = yaml.load(f.read())
    except yaml.parser.ParserError:
        raise click.BadParameter("Invalid YAML", param_hint=["config_file"])

    layer, name = layer
    r = state.api.create_config_layer(bundle, layer, name, content)
    output.info("Created {} layer for '{}' bundle".format(
        layer_name(r), r['bundle_name']))
Ejemplo n.º 3
0
Archivo: user.py Proyecto: pcn/cogctl
def password_reset(obj, token, password):
    """
    Reset user password with a token.

    A token is received by email after a password reset request.
    """
    output.info("Resetting password")
    obj.api.password_reset(token, password)
Ejemplo n.º 4
0
def delete(state, bundle, layer):
    """
    Delete a dynamic configuration layer.
    """

    state.api.delete_dynamic_config(bundle, layer['layer'], layer['name'])

    output.info("Deleted '{}' layer for bundle '{}'".format(
        layer_name(layer), bundle['name']))
Ejemplo n.º 5
0
def delete(state, groups):
    """Delete relay groups.

    Groups must have neither bundles assigned to it, nor relays
    associated with it.

    """

    for g in groups:
        state.api.delete_relay_group(g)
        output.info("Deleted relay group '{}'".format(g["name"]))
Ejemplo n.º 6
0
def layers(state, bundle):
    """List the configuration layers of a bundle.
    """

    layer_names = sorted(
        [layer_name(c) for c in state.api.dynamic_configs(bundle)])

    if layer_names:
        for l in layer_names:
            click.echo(l)
    else:
        output.info("No dynamic configuration layers for {}".format(
            bundle['name']))
Ejemplo n.º 7
0
Archivo: user.py Proyecto: pcn/cogctl
def create(obj, first_name, last_name, email, username, password):
    """
    Create a new user.
    """
    user = obj.api.new_user({
        "first_name": first_name,
        "last_name": last_name,
        "email_address": email,
        "username": username,
        "password": password
    })

    output.info(render_user(user))
Ejemplo n.º 8
0
def create(state, name, relays):
    """Create a relay group.

    If any relay names are supplied, they will be added as members of
    the newly-created group.

    """

    group = state.api.create_relay_group(name)
    output.info("Created relay group '{}'".format(group["name"]))

    if relays:
        add_relays_to_group(state.api, group, relays)
Ejemplo n.º 9
0
def show_current_relay_members(response):
    """Given an API response object, generate a message showing the
    current relay members of a group. Use after modifying the
    membership.

    """
    if response["relays"]:
        msg = "Relay group '{}' has the following relay members: {}".format(
            response["name"],
            ", ".join(sorted([r["name"] for r in response["relays"]])))
    else:
        msg = "Relay group '{}' has no relay members.".format(response["name"])

    output.info(msg)
Ejemplo n.º 10
0
def show_current_assigned_bundles(response):
    """Given an API response object, generate a message showing the
    currently assigned bundles of a group. Use after modifying the
    membership.

    """
    if response["bundles"]:
        msg = "Relay group '{}' has the following assigned bundles: {}".format(
            response["name"],
            ", ".join(sorted([b["name"] for b in response["bundles"]])))
    else:
        msg = "Relay group '{}' has no assigned bundles.".format(
            response["name"])

    output.info(msg)
Ejemplo n.º 11
0
Archivo: group.py Proyecto: pcn/cogctl
def create(obj, name):
    """
    Create a new user group.
    """
    group = obj.api.new_group(name)
    output.info(group_table(group))
Ejemplo n.º 12
0
Archivo: group.py Proyecto: pcn/cogctl
def revoke(obj, group, roles):
    """
    Revoke one or more roles from a group.
    """
    group = obj.api.revoke_group_roles(group['id'], roles)
    output.info(group_table(group))
Ejemplo n.º 13
0
Archivo: group.py Proyecto: pcn/cogctl
def grant(obj, group, roles):
    """
    Grant one or more roles to a group.
    """
    group = obj.api.grant_group_roles(group['id'], roles)
    output.info(group_table(group))
Ejemplo n.º 14
0
Archivo: group.py Proyecto: pcn/cogctl
def remove(obj, group, usernames):
    """
    Remove one or more users from a group.
    """
    group = obj.api.remove_group_users(group['id'], usernames)
    output.info(group_table(group))
Ejemplo n.º 15
0
Archivo: group.py Proyecto: pcn/cogctl
def add(obj, group, usernames):
    """
    Add one or more users to a group.
    """
    group = obj.api.add_group_users(group['id'], usernames)
    output.info(group_table(group))
Ejemplo n.º 16
0
Archivo: group.py Proyecto: pcn/cogctl
def delete(obj, group):
    """
    Delete a group.
    """
    obj.api.delete_group(group['id'])
    output.info(group_table(group))
Ejemplo n.º 17
0
Archivo: user.py Proyecto: pcn/cogctl
def password_reset_request(obj, email):
    """
    Request a password reset.
    """
    output.info("Requesting password reset")
    obj.api.request_password_reset(email)
Ejemplo n.º 18
0
Archivo: group.py Proyecto: pcn/cogctl
def rename(obj, group, new_name):
    """
    Rename a user group.
    """
    group = obj.api.update_group(group['id'], {'name': new_name})
    output.info(group_table(group))
Ejemplo n.º 19
0
Archivo: user.py Proyecto: pcn/cogctl
def delete(obj, user):
    """
    Deletes a user.
    """
    obj.api.delete_user(user['id'])
    output.info(render_user(user))