예제 #1
0
 def test_code_as_config_jwt(self):
     config = Config(
         cluster=RandomCluster(urls=helper.TEST_CLUSTER_URLS),
         timeout_seconds=3,
         back_off=StepBackOffStrategy(steps=[0.1, 0.5, 1, 1, 1]),
         ttl_seconds=31622400,
         auth=JWTAuth(
             username=helper.TEST_USERNAME,
             password=helper.TEST_PASSWORD,
             cache=JWTDiskCache(  # See JWT Caches
                 lock_file='.arango_jwt.lock',
                 lock_time_seconds=10,
                 store_file='.arango_jwt')))
     self.assertIsNotNone(config)
     config.prepare()
예제 #2
0
    def test_reset_affinity(self):
        cfg = Config(
            cluster=RandomCluster(urls=helper.TEST_CLUSTER_URLS),
            timeout_seconds=10,
            back_off=StepBackOffStrategy(steps=[1]),
            ttl_seconds=None,
            auth=JWTAuth(
                username=helper.TEST_USERNAME,
                password=helper.TEST_PASSWORD,
                cache=JWTDiskCache(
                    lock_file='test.jwt.lock',
                    lock_time_seconds=10,
                    store_file='test.jwt'
                )
            )
        )
        cfg.prepare()
        th = threading.Thread(target=run_with_reset_affinity, args=(cfg, RuntimeError, False))
        th.start()
        th.join()

        th = threading.Thread(target=run_with_reset_affinity, args=(cfg, None, True))
        th.start()
        th.join()

        cfg.auth.reset_affinity()
        cfg.prepare()
        proc = multiprocessing.Process(
            target=run_with_reset_affinity,
            args=(cfg, None, False)
        )
        proc.start()
        proc.join()

        self.assertTrue(True)

        os.remove('test.jwt')
        os.remove('test.jwt.lock')
예제 #3
0
def main():
    # Normally one would use env_config instead of parsing the environment
    # variables directly, but we do this here to make the example have as
    # little magic as possible.
    urls = os.environ.get('ARANGO_CLUSTER', 'http://localhost:8529').split(',')
    username = os.environ.get('ARANGO_AUTH_USERNAME', 'root')
    password = os.environ.get('ARANGO_AUTH_PASSWORD')

    cfg = Config(
        cluster=RandomCluster(urls=urls),
        timeout_seconds=3,
        back_off=StepBackOffStrategy(steps=[0.1, 0.5, 1, 1, 1]),
        ttl_seconds=31622400,
        auth=JWTAuth(
            username=username,
            password=password,
            cache=JWTDiskCache(  # See JWT Caches
                lock_file='.jwt_disk_example.lock',
                lock_time_seconds=10,
                store_file='.jwt_disk_example')))

    print(f'Connecting to cluster={urls}, username={username}')
    cfg.prepare()

    db: Database = cfg.database('fake_db')
    assert isinstance(db, Database)
    assert db.check_if_exists() is False

    print('Lock file:')
    with open('.jwt_disk_example.lock') as fin:
        print(fin.read())
    print()
    print('JWT file:')
    with open('.jwt_disk_example') as fin:
        print(fin.read())

    os.remove('.jwt_disk_example.lock')
    os.remove('.jwt_disk_example')
예제 #4
0
    def test_recover(self):
        self.assertFalse(os.path.exists('test.jwt'))
        self.assertFalse(os.path.exists('test.jwt.lock'))

        cfg = Config(
            cluster=RandomCluster(urls=helper.TEST_CLUSTER_URLS),
            timeout_seconds=10,
            back_off=StepBackOffStrategy(steps=[1]),
            ttl_seconds=None,
            auth=JWTAuth(
                username=helper.TEST_USERNAME,
                password=helper.TEST_PASSWORD,
                cache=JWTDiskCache(
                    lock_file='test.jwt.lock',
                    lock_time_seconds=10,
                    store_file='test.jwt'
                )
            )
        )
        cfg.prepare()
        self.assertTrue(cfg.auth.try_recover_auth_failure())
        self.assertFalse(cfg.auth.try_recover_auth_failure())
        os.remove('test.jwt')
        os.remove('test.jwt.lock')