Exemplo n.º 1
0
def sync_all_users():
    logger.info('Azure Complete Sync Process started')
    url = '{}/{}/users?$top={}'.format(settings.AZURE_GRAPH_API_BASE_URL,
                                       settings.AZURE_GRAPH_API_VERSION,
                                       settings.AZURE_GRAPH_API_PAGE_SIZE)
    azure_sync_users(url)
    logger.info('Azure Complete Sync Process finished')
Exemplo n.º 2
0
def sync_user(username):
    logger.info('Azure Sync User started for %s', username)
    url = '{}/{}/users/{}'.format(
        settings.AZURE_GRAPH_API_BASE_URL,
        settings.AZURE_GRAPH_API_VERSION,
        username
    )
    azure_sync_users(url)
    logger.info('User %s synchronized', username)
Exemplo n.º 3
0
 def test_azure_sync_users_bad_request(self, token):
     url = '{}/{}/users?$top={}'.format(settings.AZURE_GRAPH_API_BASE_URL,
                                        settings.AZURE_GRAPH_API_VERSION,
                                        settings.AZURE_GRAPH_API_PAGE_SIZE)
     responses.add(
         responses.GET,
         url,
         status=400,
         json={},
     )
     with self.assertRaisesRegexp(AzureHttpError,
                                  "Error processing the response 400"):
         azure_sync_users(url)
     self.assertEqual(token.call_count, 1)
     self.assertEqual(token.call_args[0], ())
Exemplo n.º 4
0
def sync_delta_users():
    logger.info('Azure Delta Sync Process started')
    log = VisionSyncLog.objects.create(
        country=Country.objects.get(schema_name="public"), handler_name='UserADSyncDelta')
    try:
        url = cache.get(
            AZURE_GRAPH_API_USER_CACHE_KEY,
            '{}/{}/users/delta?$top={}'.format(
                settings.AZURE_GRAPH_API_BASE_URL,
                settings.AZURE_GRAPH_API_VERSION,
                settings.AZURE_GRAPH_API_PAGE_SIZE
            )
        )
        status, delta_link = azure_sync_users(url)
        cache.set(AZURE_GRAPH_API_USER_CACHE_KEY, delta_link)

    except Exception as e:
        log.exception_message = force_text(e)
        logger.exception(force_text(e))
        raise VisionException(*e.args)
    else:
        log.total_records = status['processed'] + status['skipped']
        log.total_processed = status['processed']
        log.successful = True
    finally:
        log.save()
    logger.info('Azure Delta Sync Process finished')
    return delta_link
Exemplo n.º 5
0
def sync_delta_users():
    logger.info('Azure Delta Sync Process started')
    url = cache.get(
        AZURE_GRAPH_API_USER_CACHE_KEY,
        '{}/{}/users/delta?$top={}'.format(settings.AZURE_GRAPH_API_BASE_URL,
                                           settings.AZURE_GRAPH_API_VERSION,
                                           settings.AZURE_GRAPH_API_PAGE_SIZE))
    delta_link = azure_sync_users(url)
    cache.set(AZURE_GRAPH_API_USER_CACHE_KEY, delta_link)
    logger.info('Azure Delta Sync Process finished')
    return delta_link
Exemplo n.º 6
0
 def test_azure_sync_users_ok(self, handle_function, token):
     url = '{}/{}/users?$top={}'.format(settings.AZURE_GRAPH_API_BASE_URL,
                                        settings.AZURE_GRAPH_API_VERSION,
                                        settings.AZURE_GRAPH_API_PAGE_SIZE)
     responses.add(
         responses.GET,
         url,
         status=200,
         json={'@odata.deltaLink': 'delta'},
     )
     delta = azure_sync_users(url)
     self.assertEquals(delta, 'delta')
     self.assertEqual(token.call_count, 1)
     self.assertEqual(token.call_args[0], ())
     self.assertEqual(handle_function.call_count, 1)
     self.assertEqual(handle_function.call_args[0],
                      ({
                          '@odata.deltaLink': 'delta'
                      }, ))
Exemplo n.º 7
0
def sync_all_users():
    logger.info('Azure Complete Sync Process started')
    log = VisionSyncLog.objects.create(country=Country.objects.get(schema_name="public"), handler_name='UserADSync')
    try:
        url = '{}/{}/users?$top={}'.format(
            settings.AZURE_GRAPH_API_BASE_URL,
            settings.AZURE_GRAPH_API_VERSION,
            settings.AZURE_GRAPH_API_PAGE_SIZE
        )
        status, _ = azure_sync_users(url)
    except Exception as e:
        log.exception_message = force_text(e)
        logger.exception(force_text(e))
        raise VisionException(*e.args)
    else:
        log.total_records = status['processed'] + status['skipped']
        log.total_processed = status['processed']
        log.successful = status['created'] + status['updated']
    finally:
        log.save()
    logger.info('Azure Complete Sync Process finished')