def get_internal_tenant_from_mapping_with_external(tenant_mappings, external_tenant_id):
    """
    finds the respond tenant id that matches the external tenant id provided, if exists and accessible
    :param tenant_mappings: dictionary where (k,v) -> (internal_tenant_id,external_tenant_id)
    :param external_tenant_id:
    :return:
    """
    for curr_internal_tid, curr_external_tid in tenant_mappings.items():
        if external_tenant_id == curr_external_tid:
            return curr_internal_tid
    raise Exception(
        'no respond tenant matches external tenant: ' + external_tenant_id + ' or user does not have '
                                                                             'permission to access tenant')