示例#1
0
文件: user.py 项目: 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))
示例#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']))
示例#3
0
文件: user.py 项目: 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)
示例#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']))
示例#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"]))
示例#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']))
示例#7
0
文件: user.py 项目: 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))
示例#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)
示例#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)
示例#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)
示例#11
0
文件: group.py 项目: pcn/cogctl
def create(obj, name):
    """
    Create a new user group.
    """
    group = obj.api.new_group(name)
    output.info(group_table(group))
示例#12
0
文件: group.py 项目: 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))
示例#13
0
文件: group.py 项目: 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))
示例#14
0
文件: group.py 项目: 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))
示例#15
0
文件: group.py 项目: 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))
示例#16
0
文件: group.py 项目: pcn/cogctl
def delete(obj, group):
    """
    Delete a group.
    """
    obj.api.delete_group(group['id'])
    output.info(group_table(group))
示例#17
0
文件: user.py 项目: pcn/cogctl
def password_reset_request(obj, email):
    """
    Request a password reset.
    """
    output.info("Requesting password reset")
    obj.api.request_password_reset(email)
示例#18
0
文件: group.py 项目: 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))
示例#19
0
文件: user.py 项目: pcn/cogctl
def delete(obj, user):
    """
    Deletes a user.
    """
    obj.api.delete_user(user['id'])
    output.info(render_user(user))