def main():
    # Get the Cloud Services config files (main source of truth) for all configured releases
    releases = util.getYMLFromFile("../releases.yml")

    # This arg will be either "prod-stable" or "prod-beta", and tells us which release our local main.yml is for.
    # This guarantees that the newest main.yml is used instead of the one it intends to replace.
    if len(sys.argv) > 3:
        local_branch = sys.argv[3]
    else:
        local_branch = "prod-stable"

    if len(sys.argv) > 2:
        crc_env = sys.argv[2]
    else:
        crc_env = "stage"

    crc_env_prefix = ""
    if crc_env == "stage":
        crc_env_prefix = "/stage"

    cs_config_list = []
    for env in releases:
        source_branch = releases[env]["branch"] if "branch" in releases[env] else ""
        url_prefix = releases[env]["url_prefix"] if "url_prefix" in releases[env] else ""
        content_path_prefix = crc_env_prefix + releases[env]["content_path_prefix"] if "content_path_prefix" in releases[env] else crc_env_prefix

        cs_config_list.append({
            "name": env,
            "url_prefix": url_prefix,
            "content_path_prefix": content_path_prefix,
            "cookie_required": releases[env]["cookie_required"] if "cookie_required" in releases[env] else False,
            "config": generateConfigForBranch(source_branch, url_prefix, local_branch)
        })

    if len(sys.argv) > 1:
        property_env = sys.argv[1]
    else:
        property_env = "STAGING"

    # Authenticate with EdgeGrid
    util.initEdgeGridAuth()

    # Create a new version based off of the active Prod version
    new_version_number = createNewVersion(crc_env, property_env)

    # Update the rules JSON using the CS configuration as a reference
    updatePropertyRulesUsingConfig(new_version_number, cs_config_list, crc_env)

    # Activate version
    util.activateVersion(new_version_number, property_env, crc_env)

    # Wait for new version to be active
    util.waitForActiveVersion(int(new_version_number), property_env, crc_env)
def main():
    # Authenticate with EdgeGrid
    util.initEdgeGridAuth()

    waitForActivation = False

    if len(sys.argv) > 1:
        version_to_activate = sys.argv[1]
    else:
        sys.exit("Activation failed: no property version number specified")
    
    if len(sys.argv) > 2:
        aka_env = sys.argv[2]
    else:
        aka_env = "STAGING"
    
    if len(sys.argv) > 3:
        crc_env = sys.argv[3]
    else:
        crc_env = "stage"
    
    if len(sys.argv) > 4:
        waitForActivation = (sys.argv[4].lower() == "true")
    
    previous_version = util.getLatestVersionNumber(crc_env, aka_env)
    with open("previousversion.txt", "w") as f:
        f.write(str(previous_version))

    print(">>>>>>>>>>>>>>>>>>>>>>>> Beginning activation for {} in {}! <<<<<<<<<<<<<<<<<<<<<<<<".format(crc_env, aka_env))
    print("Activating v{}".format(version_to_activate))

    # Activate on given env
    util.activateVersion(version_to_activate, aka_env, crc_env)

    # Wait, if necessary
    if waitForActivation:
        util.waitForActiveVersion(int(version_to_activate), aka_env, crc_env)