def get_role(roles, role_id=None, role_name=None):
    """Gets a role from its id or name."""
    for role in roles:
        if role_id and role.id == int(role_id):
            return role
        if role_name and role.name == role_name:
            return role
    return None