def unique_identities(db, uuid=None, source=None):
    """List the unique identities available in the registry.

    The function returns a list of unique identities. When 'uuid'
    parameter is set, it will only return the information related
    to the unique identity identified by 'uuid'. When 'source' is
    given, only thouse unique identities with one or more identities
    related to that source will be returned.

    When the given 'uuid', assigned to the given 'source', is not in the
    registry, a 'NotFoundError' exception will be raised.

    :param db: database manager
    :param uuid: unique identifier for the identity
    :param source: source of the identities

    :raises NotFoundError: raised when the given uuid is not found
        in the registry
    """
    uidentities = []

    with db.connect() as session:
        query = session.query(UniqueIdentity)

        if source:
            query = query.join(Identity).\
                filter(UniqueIdentity.uuid == Identity.uuid,
                       Identity.source == source)

        if uuid:
            uidentity = query.\
                filter(UniqueIdentity.uuid == uuid).first()

            if not uidentity:
                raise NotFoundError(entity=uuid)

            uidentities = [uidentity]
        else:
            uidentities = query.\
                order_by(UniqueIdentity.uuid).all()

        # Detach objects from the session
        session.expunge_all()

    return uidentities
List the unique identities available in the registry.

    The function returns a list of unique identities. When 'uuid'
    parameter is set, it will only return the information related
    to the unique identity identified by 'uuid'. When 'source' is
    given, only thouse unique identities with one or more identities
    related to that source will be returned.

    When the given 'uuid', assigned to the given 'source', is not in the
    registry, a 'NotFoundError' exception will be raised.

    :param db: database manager
    :param uuid: unique identifier for the identity
    :param source: source of the identities

    :raises NotFoundError: raised when the given uuid is not found
        in the registry