How to use the okta.cache.okta_cache.OktaCache function in okta

To help you get started, we’ve selected a few okta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_TTI(monkeypatch):
    local_TTL = float(10)
    local_TTI = float(1)
    cache = OktaCache(local_TTL, local_TTI)

    assert(cache.get(CACHE_KEY) is None)
    cache.add(CACHE_KEY, CACHE_VALUE)
    time.sleep(local_TTI / 2)
    monkeypatch.setattr(OktaCache, 'get', mock_cache_return_value)
    assert(cache.get(CACHE_KEY) is CACHE_VALUE)  # resets TTI
    time.sleep(local_TTI)
    monkeypatch.setattr(OktaCache, 'get', mock_cache_return_none)
    assert(cache.get(CACHE_KEY) is None)
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_get_value():
    cache = OktaCache(TTL, TTI)

    assert(cache.get(CACHE_KEY) is None)
    cache.add(CACHE_KEY, CACHE_VALUE)
    assert(cache.get(CACHE_KEY) is CACHE_VALUE)
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_clear():
    cache = OktaCache(TTL, TTI)

    first_key = CACHE_KEY
    first_value = CACHE_VALUE

    second_key = ALT_CACHE_KEY
    second_value = ALT_CACHE_VALUE

    cache.add(first_key, first_value)
    cache.add(second_key, second_value)
    assert(cache.contains(first_key) and cache.contains(second_key))
    cache.clear()
    assert(not (cache.contains(first_key) or cache.contains(second_key)))
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_delete_value():
    cache = OktaCache(TTL, TTI)
    cache.add(CACHE_KEY, CACHE_VALUE)

    assert(cache.contains(CACHE_KEY))
    cache.delete(CACHE_KEY)
    assert(not cache.contains(CACHE_KEY))
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_has_key():
    cache = OktaCache(TTL, TTI)

    assert(not cache.contains(CACHE_KEY))

    cache.add(CACHE_KEY, CACHE_VALUE)

    assert(cache.contains(CACHE_KEY))
    assert(not cache.contains(ALT_CACHE_KEY))
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_add_entry():
    cache = OktaCache(TTL, TTI)
    cache.add(CACHE_KEY, CACHE_VALUE)
    assert cache._store[CACHE_KEY]["value"] == CACHE_VALUE

    cache.add("test string", CACHE_VALUE)
    assert cache._store["test string"]["value"] == CACHE_VALUE
github okta / okta-sdk-python / tests / unit / test_cache.py View on Github external
def test_cache_TTL(monkeypatch):
    local_TTL = float(2)
    local_TTI = float(10)
    cache = OktaCache(local_TTL, local_TTI)
    KEY = "12345"
    VALUE = "54321"

    assert(cache.get(KEY) is None)
    cache.add(KEY, VALUE)
    time.sleep(local_TTL)
    monkeypatch.setattr(OktaCache, 'get', mock_cache_return_none)
    assert(cache.get(KEY) is None)  # deleted by now

    cache.add(KEY, VALUE)
    time.sleep(local_TTL / 2)
    monkeypatch.setattr(OktaCache, 'get', mock_cache_return_value)
    assert(cache.get(KEY) is VALUE)
    time.sleep(local_TTL / 2)
    monkeypatch.setattr(OktaCache, 'get', mock_cache_return_none)
    assert(cache.get(KEY) is None)  # deleted by now
github okta / okta-sdk-python / okta / client.py View on Github external
# set client variables since validation passes
        self._authorization_mode = self._config["client"]["authorizationMode"]
        self._base_url = self._config["client"]["orgUrl"]
        self._api_token = self._config["client"].get("token", None)
        self._client_id = None
        self._scopes = None
        self._private_key = None

        # Determine which cache to use
        cache = NoOpCache()
        if self._config["client"]["cache"]["enabled"] is True:
            if user_config.get("cacheManager", None) is None:
                time_to_idle = self._config["client"]["cache"]["defaultTti"]
                time_to_live = self._config["client"]["cache"]["defaultTtl"]
                cache = OktaCache(
                    time_to_live,
                    time_to_idle
                )
            else:
                cache = user_config.get("cacheManager")

        # Determine request executor to use
        self._request_executor = \
            user_config.get("request_executor",
                            RequestExecutor(
                                self._config,
                                cache,
                                user_config.get("httpClient", None),
                            ))

        # set private key variables