def ramp_split(workspace, split, environment, definition):
    try:
        total_ramp = 0
        treatment_map = {}
        default_treatment = definition['defaultTreatment']
        for treatment in definition['treatments']:
            treatment_name = treatment['name']
            if treatment_name != default_treatment:
                while True:
                    ramp_percent = int(
                        menu.text_input("Ramp percentage for " +
                                        treatment_name))
                    if total_ramp + ramp_percent > 100:
                        menu.error_message(
                            "Total ramp percentage must be less than 100: remaining="
                            + (100 - total_ramp))
                    else:
                        treatment_map[treatment_name] = ramp_percent
                        total_ramp += ramp_percent
                        break
        treatment_map[default_treatment] = 100 - total_ramp
        split_data = split_templates.ramp_default_rule(definition,
                                                       treatment_map)
        definitions_api.full_update(workspace["id"], environment["name"],
                                    split["name"], split_data)
    except Exception as exc:
        menu.error_message("Could not update split\n" + str(exc))
def restore_definition(workspace, split, environment):
    try:
        definitions_api.restore(workspace["id"], environment["name"],
                                split["name"])
        menu.success_message(f"You restored " + split["name"] + " in " +
                             environment["name"] + ". It's Alive!!")
    except Exception as exc:
        menu.error_message("Could not restore split\n" + str(exc))
def kill_definition(workspace, split, environment):
    try:
        definitions_api.kill(workspace["id"], environment["name"],
                             split["name"])
        menu.success_message(f"You killed " + split["name"] + " in " +
                             environment["name"] + ". RIP.")
    except Exception as exc:
        menu.error_message("Could not kill split\n" + str(exc))
def get_definition_operator(workspace_id,
                            environment_name,
                            split_name,
                            expected=False):
    try:
        return definitions_api.get(workspace_id, environment_name, split_name)
    except Exception as exc:
        if expected:
            menu.error_message("Definition does not exist:" + str(exc))
        return None
def create_definition_operator(workspace_id,
                               environment_name,
                               split_name,
                               treatments=["on", "off"],
                               baseline="off"):
    try:
        split_data = split_templates.new_split(treatments, baseline)
        definitions_api.create(workspace_id, environment_name, split_name,
                               split_data)
    except Exception as exc:
        menu.error_message("Could not create split\n" + str(exc))
def target_keys(workspace, split, environment, definition):
    try:
        treatments = map(lambda x: x['name'], definition['treatments'])
        treatment, _ = menu.select("Which treatment are you targeting",
                                   treatments)
        keys = menu.input_list("Provide a key to add to list")
        split_data = split_templates.set_keys(definition, treatment, keys)
        definitions_api.full_update(workspace["id"], environment["name"],
                                    split["name"], split_data)
    except Exception as exc:
        menu.error_message("Could not add keys to split\n" + str(exc))
Example #7
0
def create_account():
    firstname = menu.text_input("Enter Your First Name")
    lastname = menu.text_input("Enter Your Last Name")
    email = menu.text_input("Enter Your Email Address")
    phone = menu.text_input("Enter Your 10 Digit Phone Number")

    menu.info_message("Setting up your account...")
    create_response = requests.post(
        f"{config.SPLIT_CLI_BACKEND_BASE_URL}/create-and-enroll-user",
        json={
            "fields": [{
                "name": "firstname",
                "value": firstname
            }, {
                "name": "lastname",
                "value": lastname
            }, {
                "name": "email",
                "value": email
            }, {
                "name": "phone",
                "value": phone
            }]
        })

    if create_response.status_code != 200:
        menu.error_message(create_response.json())
        exit()

    status = 403
    while status == 403:
        verify_response = verify_and_complete(firstname, lastname, email)
        status = verify_response.status_code
        if (status == 403):
            menu.warn_message("Incorrect confirmation code. Please try again")

    if verify_response.status_code != 200:
        menu.error_message(verify_response.json())
        exit()

    verify_response_json = verify_response.json()
    user = User(verify_response_json["apiToken"],
                verify_response_json["orgId"], verify_response_json["userId"],
                firstname, lastname, email)
    user.write()
    password = verify_response_json["password"]
    menu.info_message(
        f"\nYour admin api key has been written to: {config.config_file}.")
    menu.info_message(
        f"Your email is: {email} and your assigned password is: {password}.")
    menu.info_message(
        "Make note of your password as it will not be repeated. You can change your password by logging in to: https://app.split.io"
    )
Example #8
0
def main():
    major_required = 3
    minor_required = 6

    if sys.version_info.major < major_required or sys.version_info.minor < minor_required:
        menu.error_message(
            f"Minimum version requirement is: {major_required}.{minor_required}. Your version is: {sys.version_info.major}.{sys.version_info.minor}"
        )
        exit()

    menu.print_logo()
    initial_prompt_deprecate()
Example #9
0
def create_segment(workspace):
    try:
        segment_name = menu.text_input("Enter a name for your segment")
        segment_description = menu.text_input(
            "Enter a description for your segment")
        traffic_type = core_selectors.selection_traffic_type(workspace["id"])

        segments_api.create_segment(workspace["id"], traffic_type["name"],
                                    segment_name, segment_description)

        create_segment_in_all_environments(workspace, segment_name)
        menu.success_message("Your segment has been created!")
    except Exception as exc:
        menu.error_message("Could not create segment\n" + str(exc))
def target_segments_operator(workspace_id, environment_name, split_name,
                             treatment_name, segment_names):
    try:
        # Get current definition
        definition = get_definition_operator(workspace_id,
                                             environment_name,
                                             split_name,
                                             expected=True)
        if definition is None:
            raise ValueError("Definition not found")
        split_data = split_templates.set_segments(definition, treatment_name,
                                                  segment_names)
        definitions_api.full_update(workspace_id, environment_name, split_name,
                                    split_data)
    except Exception as exc:
        menu.error_message("Could not update split\n" + str(exc))
def ramp_split_operator(workspace_id,
                        environment_name,
                        split_name,
                        ramp_percent=None,
                        treatment_map=None):
    try:
        # Validate Inputs
        if ramp_percent is not None and treatment_map is not None:
            raise ValueError(
                "Either ramp_percent or treatment_map must be set, currently both"
            )

        # Get current definition
        definition = get_definition_operator(workspace_id,
                                             environment_name,
                                             split_name,
                                             expected=True)
        if definition is None:
            raise ValueError("Definition not found")

        if ramp_percent is not None:
            # Set Ramp Percent
            treatment_map = {}
            treatments = definition["treatments"]
            if len(definition["treatments"]) != 2:
                raise ValueError(
                    "Definition must have two treatments to use ramp_percent")
            default_treatment = definition['defaultTreatment']
            for treatment in treatments:
                treatment_name = treatment['name']
                if treatment_name != default_treatment:
                    treatment_map[treatment_name] = ramp_percent
            treatment_map[default_treatment] = 100 - ramp_percent
        elif treatment_map is None:
            raise ValueError(
                "Either ramp_percent or treatment_map must be set, currently neither"
            )

        # Update Split
        split_data = split_templates.ramp_default_rule(definition,
                                                       treatment_map)
        definitions_api.full_update(workspace_id, environment_name, split_name,
                                    split_data)
    except Exception as exc:
        menu.error_message("Could not update split\n" + str(exc))
Example #12
0
 def __init__(self, sdk_token):
     super(BatchClient, self).__init__()
     try:
         self.factory = get_factory(sdk_token,
                                    config={
                                        "connectionTimeout":
                                        connection_timeout,
                                        "impressionsQueueSize": queue_size,
                                        "eventsQueueSize": queue_size,
                                        "eventsBulkSize": bulk_size,
                                        "impressionsBulkSize": bulk_size,
                                        "impressionsMode": "optimized"
                                    })
         self.factory.block_until_ready(20)
     except TimeoutException:
         menu.error_message("SDK failed to initialize")
         sys.exit(1)
     self.split_client = self.factory.client()
def create_split(workspace):
    try:
        split_name = menu.text_input("Enter a name for your split")
        split_description = menu.text_input(
            "Enter a description for your split")
        traffic_type = core_selectors.selection_traffic_type(workspace["id"])

        (treatments, baseline) = definition_selectors.select_treatments()

        create_split_operator(workspace["id"], traffic_type["name"],
                              split_name, split_description, treatments,
                              baseline)
        menu.success_message("Your split has been created!")

        split = splits_api.get_split(workspace['id'], split_name)
        manage_split(workspace, split)
    except Exception as exc:
        menu.error_message("Could not create split\n" + str(exc))
def target_segments(workspace, split, environment, definition):
    try:
        traffic_type_name = split['trafficType']['name']
        segments = segments_api.list_segments_environment(
            workspace['id'], environment['name'])
        segments = list(
            filter(lambda x: x['trafficType']['name'] == traffic_type_name,
                   segments))
        segment_names = list(map(lambda x: x['name'], segments))

        treatment = menu.select("Which treatment are you targeting",
                                definition['treatments'],
                                name_field="name")
        default = treatment.get("segments", [])
        result = menu.checkbox("Select segments to target", segment_names,
                               default)

        split_data = split_templates.set_segments(definition,
                                                  treatment["name"], result)
        definitions_api.full_update(workspace["id"], environment["name"],
                                    split["name"], split_data)
    except Exception as exc:
        menu.error_message("Could not update split\n" + str(exc))
def treatments_validator(treatments):
    if len(treatments) < 2:
        return menu.error_message("At least two treatments are required")
    else:
        return None