Пример #1
0
    def configure(create, path, inline_policy, attached_policy, user_name):
        """Create/configure/get IAM user."""

        iam_conn = awscontext.GLOBAL.iam

        try:
            user = iamclient.get_user(iam_conn, user_name)
        except exc.NotFoundError:
            if not create:
                raise
            user = None

        if not user:
            user = iamclient.create_user(iam_conn, user_name, path)

        if inline_policy:
            _set_user_policy(iam_conn, user_name, inline_policy)

        if attached_policy:
            _set_attached_policy(iam_conn, user_name, attached_policy)

        user['UserPolicies'] = iamclient.list_user_policies(
            iam_conn, user_name)
        user['AttachedPolicies'] = iamclient.list_attached_user_policies(
            iam_conn, user_name)
        cli.out(formatter(user))
Пример #2
0
def get_iam_user(iam_conn, user_name):
    """Get IAM user details."""
    iam_user = iamclient.get_user(iam_conn=iam_conn, user_name=user_name)
    iam_role = iamclient.get_role(iam_conn=iam_conn, role_name=user_name)
    return {
        'user': iam_user,
        'role': iam_role,
    }
Пример #3
0
def create_iam_user(iam_conn, user_name):
    """ Create user account with AWS IAM if not already created.
    """
    try:
        iam_user = iamclient.get_user(iam_conn=iam_conn, user_name=user_name)
    except exc.NotFoundError:
        # If account does not exist:
        iam_user = iamclient.create_user(
            iam_conn=iam_conn,
            user_name=user_name,
        )

    return iam_user
Пример #4
0
def get_user(iam_conn, ipa_client, user_name):
    """Get user details."""
    user = {
        '_ipa': None,
        '_iam': {
            'user': None,
            'role': None,
        }
    }
    ipa_user = ipa_client.show_user(user_name=user_name)
    iam_user = iamclient.get_user(iam_conn=iam_conn, user_name=user_name)
    iam_role = iamclient.get_role(iam_conn=iam_conn, role_name=user_name)
    user['_ipa'] = ipa_user
    user['_iam']['user'] = iam_user
    user['_iam']['role'] = iam_role
    return _user(user)
Пример #5
0
def create_iam_user(iam_conn, user_name, policy):
    """ Create user account with AWS IAM if not already created.
    """
    try:
        iam_user = iamclient.get_user(iam_conn=iam_conn, user_name=user_name)
    except exc.NotFoundError:
        # If account does not exist:
        iam_user = iamclient.create_user(
            iam_conn=iam_conn,
            user_name=user_name,
        )

    try:
        iam_role = iamclient.get_role(iam_conn=iam_conn, role_name=user_name)
    except exc.NotFoundError:
        # If role does not exist:
        iam_role = iamclient.create_role(iam_conn=iam_conn,
                                         role_name=user_name,
                                         policy_document=json.dumps(policy))

    return {
        'user': iam_user,
        'role': iam_role,
    }