nginxinc / nginx-go-crossplane

A library for working with NGINX configs in Go
Apache License 2.0
46 stars 12 forks source link

False positive cyclic detection for some configurations #81

Closed CodeMonkeyF5 closed 6 months ago

CodeMonkeyF5 commented 7 months ago

Is your feature request related to a problem? Please describe

Unable to use XP to parse partial files from existing NGINX configurations due to cyclical check failing. Need to be able to parse file by file (not entirety of config). Cannot bypass the "configs contain include cycle" error returned even when the config is valid.

Describe the solution you'd like

Fix the logic for isAcyclic function to only check the current file being parsed (ignore others).

Describe alternatives you've considered

Creating a custom lib that utilizes the exported nginx-go-crossplane structs with it's own Parse function with new option to perform acyclic check only for the target file being parsed.

Additional context

CodeMonkeyF5 commented 6 months ago

Resolved issue by setting the parse open to get the files from in-memory (not disk).

    args.Open = func(path string) (io.Reader, error) {
        if config, found := myFileMap[path]; found {
            return strings.NewReader(config), nil
        }

        return os.Open(path)
    }