mds_plugin/user.py
def delete_user_group_membership(user_name=None, group_name=None, user_id=None,
                                 group_id=None, config=None, interactive=True):
    """Removes a user from a group

    Args:
        user_name (str): The name of the user.
        group_name (str): The name of the group.
        user_id (str): The OCID of the user
        group_id (str): The OCID of the group
        config (object): An OCI config object or None.
        interactive (bool): If the True should be returned on success

    Returns:
        The membership object or None
    """

    # Get the current config
    try:
        config = configuration.get_current_config(config=config)
    except ValueError as e:
        print(e)
        return

    import oci.identity

    # Get user
    user = get_user(user_name=user_name, user_id=user_id, config=config)
    if user is None:
        print("Operation cancelled.")
        return

    # Get user
    group = get_group(name=group_name, group_id=group_id, config=config)
    if group is None:
        print("Operation cancelled.")
        return

    # Initialize the identity client
    identity = core.get_oci_identity_client(config=config)

    try:
        # List the groups of the given user
        data = identity.list_user_group_memberships(
            compartment_id=config.get("tenancy"), user_id=user.id).data

        group_found = False

        for m in data:
            # If the right group was found, remove the membership
            if m.group_id == group.id:
                identity.remove_user_from_group(m.id).data
                group_found = True
                break

        if not group_found:
            if interactive:
                print(f"User {user.name} is not a member of {group.name}.")
            return

    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except (ValueError, oci.exceptions.ClientError) as e:
        print(f'ERROR: {e}')

    # Return the response
    if interactive:
        print(f"User {user.name} was removed from {group.name}.")
    else:
        return True
Removes a user from a group

    Args:
        user_name (str): The name of the user.
        group_name (str): The name of the group.
        user_id (str): The OCID of the user
        group_id (str): The OCID of the group
        config (object): An OCI config object or None.
        interactive (bool): If the True should be returned on success

    Returns:
        The membership object or None
    
Removes a user from a group
Removes a user from a group
def delete_user_group_membership(user_name=None, group_name=None, user_id=None,
                                 group_id=None, config=None, interactive=True):
    try:
        config = configuration.get_current_config(config=config)
    except ValueError as e:
        print(e)
        return
    import oci.identity
    user = get_user(user_name=user_name, user_id=user_id, config=config)
    if user is None:
        print("Operation cancelled.")
        return
    group = get_group(name=group_name, group_id=group_id, config=config)
    if group is None:
        print("Operation cancelled.")
        return
    identity = core.get_oci_identity_client(config=config)
    try:
        data = identity.list_user_group_memberships(
            compartment_id=config.get("tenancy"), user_id=user.id).data
        group_found = False
        for m in data:
            if m.group_id == group.id:
                identity.remove_user_from_group(m.id).data
                group_found = True
                break
        if not group_found:
            if interactive:
                print(f"User {user.name} is not a member of {group.name}.")
            return
    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except (ValueError, oci.exceptions.ClientError) as e:
        print(f'ERROR: {e}')
    if interactive:
        print(f"User {user.name} was removed from {group.name}.")
    else:
        return True
def delete_user_group_membership ( user_name = None , group_name = None , user_id = None , group_id = None , config = None , interactive = True ) : try : config = configuration . get_current_config ( config = config ) except ValueError as e : print ( e ) return import oci . identity user = get_user ( user_name = user_name , user_id = user_id , config = config ) if user is None : print ( "Operation cancelled." ) return group = get_group ( name = group_name , group_id = group_id , config = config ) if group is None : print ( "Operation cancelled." ) return identity = core . get_oci_identity_client ( config = config ) try : data = identity . list_user_group_memberships ( compartment_id = config . get ( "tenancy" ) , user_id = user . id ) . data group_found = False for m in data : if m . group_id == group . id : identity . remove_user_from_group ( m . id ) . data group_found = True break if not group_found : if interactive : print ( f"User {user.name} is not a member of {group.name}." ) return except oci . exceptions . ServiceError as e : print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) return except ( ValueError , oci . exceptions . ClientError ) as e : print ( f'ERROR: {e}' ) if interactive : print ( f"User {user.name} was removed from {group.name}." ) else : return True
Removes a user from a group
Removes a user from a group
"""Removes a user from a group

    Args:
        user_name (str): The name of the user.
        group_name (str): The name of the group.
        user_id (str): The OCID of the user
        group_id (str): The OCID of the group
        config (object): An OCI config object or None.
        interactive (bool): If the True should be returned on success

    Returns:
        The membership object or None
    """ # Get the current config
 # Get user
 # Get user
 # Initialize the identity client
 # List the groups of the given user
 # If the right group was found, remove the membership
 # Return the response

The membership object or None
The membership object or None
user_name
The name of the user.
The name of the user .
group_name
The name of the group.
The name of the group .
user_id
The OCID of the user
The OCID of the user
group_id
The OCID of the group
The OCID of the group
config
An OCI config object or None.
An OCI config object or None .
interactive
If the True should be returned on success
If the True should be returned on success