function _M.read_yaml_conf()

in apisix/cli/file.lua [229:332]


function _M.read_yaml_conf(apisix_home)
    if apisix_home then
        profile.apisix_home = apisix_home .. "/"
    end

    local local_conf_path = profile:customized_yaml_path()
    if not local_conf_path then
        local_conf_path = profile:yaml_path("config")
    end
    local user_conf_yaml, err = util.read_file(local_conf_path)
    if not user_conf_yaml then
        return nil, err
    end

    local is_empty_file = true
    for line in str_gmatch(user_conf_yaml .. '\n', '(.-)\r?\n') do
        if not is_empty_yaml_line(line) then
            is_empty_file = false
            break
        end
    end

    if not is_empty_file then
        local user_conf = yaml.load(user_conf_yaml)
        if not user_conf then
            return nil, "invalid config.yaml file"
        end

        local ok, err = resolve_conf_var(user_conf)
        if not ok then
            return nil, err
        end

        ok, err = merge_conf(default_conf, user_conf)
        if not ok then
            return nil, err
        end
    end

    
    local ok, err = schema.validate(default_conf)
    if not ok then
        return nil, err
    end
    if default_conf.deployment then
        default_conf.deployment.config_provider = "etcd"
        if default_conf.deployment.role == "traditional" then
            default_conf.etcd = default_conf.deployment.etcd

        elseif default_conf.deployment.role == "control_plane" then
            default_conf.etcd = default_conf.deployment.etcd
            default_conf.apisix.enable_admin = true

        elseif default_conf.deployment.role == "data_plane" then
            default_conf.etcd = default_conf.deployment.etcd
            if default_conf.deployment.role_data_plane.config_provider == "yaml" then
                default_conf.deployment.config_provider = "yaml"
            elseif default_conf.deployment.role_data_plane.config_provider == "xds" then
                default_conf.deployment.config_provider = "xds"
            end
            default_conf.apisix.enable_admin = false
        end
    end

    if default_conf.deployment.config_provider == "yaml" then
        local apisix_conf_path = profile:yaml_path("apisix")
        local apisix_conf_yaml, _ = util.read_file(apisix_conf_path)
        if apisix_conf_yaml then
            local apisix_conf = yaml.load(apisix_conf_yaml)
            if apisix_conf then
                local ok, err = resolve_conf_var(apisix_conf)
                if not ok then
                    return nil, err
                end
            end
        end
    end

    local apisix_ssl = default_conf.apisix.ssl
    if apisix_ssl and apisix_ssl.ssl_trusted_certificate then
        
        if apisix_ssl.ssl_trusted_certificate == "system" then
            local trusted_certs_path, err = util.get_system_trusted_certs_filepath()
            if not trusted_certs_path then
                util.die(err)
            end

            apisix_ssl.ssl_trusted_certificate = trusted_certs_path
        else
            
            
            
            local cert_path = pl_path.abspath(apisix_ssl.ssl_trusted_certificate)
            if not pl_path.exists(cert_path) then
                util.die("certificate path", cert_path, "doesn't exist\n")
            end
            apisix_ssl.ssl_trusted_certificate = cert_path
        end
    end

    replace_by_reserved_env_vars(default_conf)

    return default_conf
end