Exemplo n.º 1
0
def test_set_sdk_key_before_init():
    ldclient.set_config(Config.default())

    ldclient.set_sdk_key(sdk_key)
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
Exemplo n.º 2
0
def test_set_sdk_key_after_init():
    ldclient.set_config(Config.default())
    assert ldclient.get().is_initialized() is False
    ldclient.set_sdk_key(sdk_key)
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
def test_set_sdk_key_after_init():
    ldclient.set_config(Config.default())
    assert ldclient.get().is_initialized() is False
    ldclient.set_sdk_key(sdk_key)
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
def test_set_sdk_key_before_init():
    ldclient.set_config(Config.default())

    ldclient.set_sdk_key(sdk_key)
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
Exemplo n.º 5
0
def get_ld_client():
    #if this was an app in prod, keey would go in secret file
    #hard-coding as a shortcut for now! 
    if "ld_client" not in g:
        ldclient.set_config(Config("sdk-6d5668a8-bca4-43e8-a4ed-aae8b501be6c"))
        g.ld_client = ldclient.get()

    return g.ld_client
Exemplo n.º 6
0
def test_set_config():
    offline_config = ldclient.Config(offline=True)
    online_config = ldclient.Config(sdk_key=sdk_key, offline=False)

    ldclient.set_config(offline_config)
    assert ldclient.get().is_offline() is True

    ldclient.set_config(online_config)
    assert ldclient.get().is_offline() is False
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
Exemplo n.º 7
0
    def init_app(app):
        Config.init_app(app)

        with app.app_context():
            from app.db import db
            from app.models import User

            db.init_app(app)
            db.create_all()

            from ldclient.config import Config as __config
            ldclient.set_config(__config(offline=True))
Exemplo n.º 8
0
    def init_app(app):
        Config.init_app(app)

        with app.app_context():
            from zadacha.factory import db
            from zadacha.models.user import User

            db.init_app(app)
            db.create_all()

            from ldclient.config import Config as __config
            ldclient.set_config(__config(offline=True))
def test_set_config():
    offline_config = ldclient.Config(offline=True)
    online_config = ldclient.Config(sdk_key=sdk_key, offline=False)

    ldclient.set_config(offline_config)
    assert ldclient.get().is_offline() is True

    ldclient.set_config(online_config)
    assert ldclient.get().is_offline() is False
    wait_until(ldclient.get().is_initialized, timeout=30)

    ldclient.get().close()
Exemplo n.º 10
0
def test_set_sdk_key_before_init():
    _reset_client()
    with start_server() as stream_server:
        with stream_content(make_put_event()) as stream_handler:
            try:
                stream_server.for_path('/all', stream_handler)

                ldclient.set_config(Config(sdk_key, stream_uri = stream_server.uri, send_events = False))
                wait_until(ldclient.get().is_initialized, timeout=10)

                r = stream_server.await_request()
                assert r.headers['Authorization'] == sdk_key
            finally:
                _reset_client()
Exemplo n.º 11
0
class Config(object):
    """Base Config"""
    # VERSION refers to the latest git SHA1
    VERSION = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode('utf-8').rstrip()
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess-this'
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'postgresql://{0}:{0}@{1}/{0}'.format(
            'supportService',
            'localhost'
        )
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT')
    CACHE_REDIS_HOST = os.environ.get('REDIS_HOST') or 'cache'

    # LaunchDarkly Config
    # If $LD_RELAY_URL is set, client will be pointed to a relay instance.
    if "LD_RELAY_URL" in os.environ:
        config = LdConfig(
            sdk_key = os.environ.get("LD_CLIENT_KEY"),
            base_uri = os.environ.get("LD_RELAY_URL"),
            events_uri = os.environ.get("LD_RELAY_URL"),
            stream_uri = os.environ.get("LD_RELAY_URL")
        )
        ldclient.set_config(config)
    else:
        ldclient.set_sdk_key(os.environ.get("LD_CLIENT_KEY"))

    LD_FRONTEND_KEY = os.environ.get("LD_FRONTEND_KEY")

    root = logging.getLogger()
    root.setLevel(logging.INFO)

    @staticmethod
    def init_app(app):
        pass
Exemplo n.º 12
0
def test_set_sdk_key():
    old_sdk_key = "OLD_SDK_KEY"
    new_sdk_key = "NEW_SDK_KEY"

    old_config = Config(sdk_key=old_sdk_key, stream=False, offline=True)
    ldclient.set_config(old_config)

    old_client = ldclient.get()
    assert old_client.get_sdk_key() == old_sdk_key

    ldclient.set_sdk_key(new_sdk_key)
    new_client = ldclient.get()

    assert new_client.get_sdk_key() == new_sdk_key

    # illustrates bad behavior- assigning value of ldclient.get() means
    # the old_client didn't get updated when we called set_sdk_key()
    assert old_client.get_sdk_key() == old_sdk_key
Exemplo n.º 13
0
def test_set_sdk_key():
    old_sdk_key = "OLD_SDK_KEY"
    new_sdk_key = "NEW_SDK_KEY"

    old_config = Config(sdk_key=old_sdk_key, stream=False, offline=True)
    ldclient.set_config(old_config)

    old_client = ldclient.get()
    assert old_client.get_sdk_key() == old_sdk_key

    ldclient.set_sdk_key(new_sdk_key)
    new_client = ldclient.get()

    assert new_client.get_sdk_key() == new_sdk_key

    # illustrates bad behavior- assigning value of ldclient.get() means
    # the old_client didn't get updated when we called set_sdk_key()
    assert old_client.get_sdk_key() == old_sdk_key
Exemplo n.º 14
0
def test_set_sdk_key_after_init():
    _reset_client()
    other_key = 'other-key'
    with start_server() as stream_server:
        with stream_content(make_put_event()) as stream_handler:
            try:
                stream_server.for_path('/all', BasicResponse(401))

                config = Config(other_key, stream_uri = stream_server.uri, send_events = False)
                ldclient.set_config(config)
                assert ldclient.get().is_initialized() is False

                r = stream_server.await_request()
                assert r.headers['Authorization'] == other_key

                stream_server.for_path('/all', stream_handler)

                ldclient.set_config(config.copy_with_new_sdk_key(sdk_key))
                wait_until(ldclient.get().is_initialized, timeout=30)

                r = stream_server.await_request()
                assert r.headers['Authorization'] == sdk_key
            finally:
                _reset_client()
Exemplo n.º 15
0
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)

if __name__ == "__main__":
    store = Redis.new_feature_store(
        url='redis://*****:*****@example.com",
        "firstName": "Bob",
        "lastName": "Loblaw",
        "custom": {
            "groups": "beta_testers"
        }
    }

    show_feature = ldclient.get().variation("YOUR_FLAG_KEY", user, False)

    if show_feature:
        print("Showing your feature")
    else:
Exemplo n.º 16
0
# define character sets for the user key
key_set = string.ascii_lowercase + string.ascii_uppercase + string.digits

# reach out and get external IP
ip_addr = get('https://api.ipify.org').text


# function to create a random key for this session
def make_key():
    return ''.join(random.choice(key_set) for _ in range(8))


# main using my sdk key
if __name__ == "__main__":
    sdk_key = "sdk-e77356dd-34ee-4c86-8219-018a22e6f13d"
    ldclient.set_config(Config(sdk_key))

    # get inputs from user
    firstname = input("Please enter your first name: ")
    lastname = input("Please enter your last name: ")
    emailaddr = input("Please enter your email address: ")

    # create the user key
    make_key()
    key = make_key()

    # user data to pass through, note IP info for targeting
    user = {
        "key": key,
        "firstName": firstname,
        "lastName": lastname,
Exemplo n.º 17
0
1. Deals with special values (e.g. 0)
2. Deals with negative integers
3. Deals with out of range values
4. Loop through billions, millions, thousands, and hundreds. Decrement the integer moving from left to right (e.g. 432 -> 32)
5. Possibly include the word 'and'. This is dependent on FEATURE_INCLUDE_THE_WORD_AND.
6. Determine the remainder below 100.
7. Returns integer in words.
'''

# import ld client for launchDarkly
import ldclient
from ldclient.config import Config

# setting key for launchDarkly
ldclient.set_config(Config(sdk_key="sdk-e1cd70a1-f68f-4b96-8461-8214c479ccea"))
ld_client = ldclient.get()

# user model for launchDarkly dashboard
user = {
    "key": "*****@*****.**",
    "firstName": "Kyle",
    "lastName": "Reynolds",
    "email": "*****@*****.**",
    "custom": {
        "groups": ["Google", "Microsoft"]
    }
}

# Feature Flags
FEATURE_NUMBERS_GREATER_THAN_99 = ld_client.variation(
Exemplo n.º 18
0
os.environ["http_proxy"] = "http://127.0.0.1:8080"

root = logging.getLogger()
root.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)

if __name__ == "__main__":
    http_config = ldclient.config.HTTPConfig(
        disable_ssl_verification=True, http_proxy="https://127.0.0.1:8083")
    ldclient.set_config(
        ldclient.Config(sdk_key="sdk-da4e7cfe-e958-4c6c-9ad2-ced60853d668",
                        http=http_config))

    user = {
        "key": "*****@*****.**",
        "firstName": "Bob2",
        "lastName": "Loblaw2",
        "custom": {
            "groups": "beta_testers"
        }
    }

    show_feature = ldclient.get().variation("my_feature_flag", user, False)

    if show_feature:
        print("Showing your feature")
Exemplo n.º 19
0
#simple Python3 code to demonstrate the use of LaunchDarkly feature flags

#import the LaunchDarkly client 
import ldclient
from ldclient.config import Config

#create instance of LaunchDarkly client using Test Env key
ldclient.set_config(Config("sdk-1c869509-b2b1-47d6-8fa2-827e08db955f"))
ld_client = ldclient.get()

#set value of user - in a dynamic execution this would be set on the fly
user = {
  "key": "UNIQUE IDENTIFIER",
  "firstName": "Bob",
  "lastName": "Loblaw",
  "custom": {
    "groups": "beta_testers"
  }
}

#set the feature flag value (t/F) based on the flag ID and user name. 
show_feature = ld_client.variation("use-simple-average",user, False)


# Score Calculating Function
# using the "use-simple-average" feature flag to determine the algo
def compute_score(r1,r2,r3):

	if show_feature:
  		return (r1 + r2 + r3) / 3
Exemplo n.º 20
0
def index():
    import uwsgi  # fails in flask
    print("Threads: ", uwsgi.opt.get('threads'))
    ldclient.set_config(Config(LD_SDK_KEY))
    ld_client = ldclient.get()
    return "Hello world"
Exemplo n.º 21
0
#!/usr/bin/env python
"""Tests for `ld_patch` package."""

from __future__ import absolute_import

from unittest import TestCase
from unittest.mock import patch

import ldclient
from ldclient.config import Config

from ld_patch import patch_feature

ldclient.set_config(Config("YOUR_SDK_KEY", offline=True))
client = ldclient.get()


def get_feature_status(feature_key: str,
                       user_key: str = "*****@*****.**",
                       default=False):
    return client.variation(feature_key, user_key, default)


class TestPatchFeatureSimple(TestCase):
    def test_with_statement(self):
        with patch_feature("test-with-statement", "PASSED"):
            value = get_feature_status("test-with-statement")
            self.assertEqual(value, "PASSED")

    @patch_feature("method-decorator", "PASSED")
    def test_single_method_decorator(self):
Exemplo n.º 22
0
import ldclient
from ldclient.config import Config

LD_SDK_KEY='<TODO: Insert LD SDK key here>'
FLAG_KEY='<TODO: Insert LD flag key here>'

ldclient.set_config(Config(LD_SDK_KEY))
ld_client = ldclient.get()

show_feature = ld_client.variation(FLAG_KEY, {"key": "*****@*****.**"}, False)
print(show_feature)

ldclient.get().flush()
#ldclient.get().close() # If you uncomment this LD updates the 'Evaluated ...' string correctly
Exemplo n.º 23
0
            'When "FEATURE_FLAGS_FROM_FILE" is set, you have to specify a valid path for feature flags file, e.g.'
            'FEATURE_FLAGS_FILE=my_flags.yml')

    package_name = 'label_studio' if settings.VERSION_EDITION == 'Community Edition' else 'label_studio_enterprise'
    if settings.FEATURE_FLAGS_FILE.startswith('/'):
        feature_flags_file = settings.FEATURE_FLAGS_FILE
    else:
        feature_flags_file = find_node(package_name,
                                       settings.FEATURE_FLAGS_FILE, 'file')

    logger.info(f'Read flags from file {feature_flags_file}')
    data_source = Files.new_data_source(paths=[feature_flags_file])
    config = Config(sdk_key=settings.FEATURE_FLAGS_API_KEY or 'whatever',
                    update_processor_class=data_source,
                    send_events=False)
    ldclient.set_config(config)
    client = ldclient.get()
elif settings.FEATURE_FLAGS_OFFLINE:
    # On-prem usage, without feature flags file
    ldclient.set_config(
        Config(settings.FEATURE_FLAGS_API_KEY or 'whatever', offline=True))
    client = ldclient.get()
else:
    # Production usage
    if hasattr(settings, 'REDIS_LOCATION'):
        logger.debug(
            f'Set LaunchDarkly config with Redis feature store at {settings.REDIS_LOCATION}'
        )
        store = Redis.new_feature_store(url=settings.REDIS_LOCATION,
                                        prefix='feature-flags',
                                        caching=CacheConfig(expiration=30))