def export_arr_config()

in ebcli/controllers/migrate.py [0:0]


def export_arr_config(upload_target_dir: str, verbose: bool) -> None:
    """
    Export IIS Application Request Routing (ARR) configuration to XML files.

    Exports modified (non-default) settings from ARR-related IIS configuration
    sections to XML files. These files can be used to replicate ARR configuration
    on other servers during Elastic Beanstalk deployments.

    Args:
        upload_target_dir: Base directory for deployment artifacts. Configuration files
                          will be written to '{upload_target_dir}/ebmigrateScripts/'
        verbose: If True, provides detailed output about each configuration section
                and export operation

    Configuration Sections Exported:
        - system.webServer/proxy: ARR proxy settings
        - system.webServer/rewrite: URL rewrite rules
        - system.webServer/caching: Caching configuration

    Notes:
        - Only exports attributes that differ from default values
        - Creates one XML file per configuration section:
            * arr_config_proxy.xml
            * arr_config_rewrite.xml
            * arr_config_caching.xml
        - Skips sections that don't exist in the current configuration
        - Automatically generates ARR import script after export

    Raises:
        Exception: If export fails, with detailed error message

    Example XML Output:
        <proxy enabled="true" timeout="00:02:00" />
    """
    config_sections = [
        "system.webServer/proxy",
        "system.webServer/rewrite",
        "system.webServer/caching",
    ]
    if not _arr_enabled() and verbose:
        io.echo("No Automatic Request Routing (ARR) configuration found.")
        return
    else:
        io.echo("Automatic Request Routing (ARR) configuration found.")

    server_manager = ServerManager()
    try:
        for i, section in enumerate(config_sections, 1):
            section_name = section.split("/")[-1]
            arr_config_file = f"arr_config_{section_name}.xml"
            arr_config_file_path = os.path.join(
                upload_target_dir, "ebmigrateScripts", arr_config_file
            )
            with open(arr_config_file_path, "w") as file:
                config = server_manager.GetApplicationHostConfiguration()
                try:
                    section_obj = config.GetSection(section)
                except COMException:
                    if verbose:
                        io.echo(f"  {i}. Section {section} not found")
                    continue

                modified_attributes = [
                    attr
                    for attr in section_obj.Attributes
                    if not attr.IsInheritedFromDefaultValue
                ]

                # TODO: Handle child attributes for system.webserver/caching as well
                xml_content = f"<{section_name}"
                for attr in modified_attributes:
                    xml_content += f' {attr.Name}="{attr.Value}"'
                xml_content += " />"

                file.write(xml_content)
                if verbose:
                    io.echo(
                        f"  {i}. Modified {section_name} configuration exported to {arr_config_file_path}"
                    )
        if not verbose:
            io.echo("Exported ARR config.")
    except Exception as e:
        io.log_error(f"Failed to export ARR configuration: {str(e)}")
        raise
    write_arr_import_script_to_source_bundle(upload_target_dir)