Documentation
¶
Index ¶
- Constants
- Variables
- func Build(w io.Writer, config Config, options *BuildOptions) error
- func BuildFiles(payload Payload, dir string, options *BuildOptions) error
- func BuildInto(payload *Payload, into Creator, options *BuildOptions) error
- func DefaultDirectivesMatchFunc(directive string) ([]uint, bool)
- func Enquote(arg string) string
- func Lex(reader io.Reader) chan NgxToken
- func LexWithOptions(r io.Reader, options LexOptions) chan NgxToken
- func MatchAppProtectWAFv4(directive string) ([]uint, bool)
- func MatchAppProtectWAFv5(directive string) ([]uint, bool)
- func MatchGeoip2Latest(directive string) ([]uint, bool)
- func MatchHeadersMoreLatest(directive string) ([]uint, bool)
- func MatchLuaLatest(directive string) ([]uint, bool)
- func MatchNginxPlusLatest(directive string) ([]uint, bool)
- func MatchNginxPlusR30(directive string) ([]uint, bool)
- func MatchNginxPlusR31(directive string) ([]uint, bool)
- func MatchNginxPlusR33(directive string) ([]uint, bool)
- func MatchNjsLatest(directive string) ([]uint, bool)
- func MatchOss124(directive string) ([]uint, bool)
- func MatchOss126(directive string) ([]uint, bool)
- func MatchOssLatest(directive string) ([]uint, bool)
- func MatchOtelLatest(directive string) ([]uint, bool)
- func SetTokenChanCap(size int)
- type BuildOptions
- type Builder
- type Config
- type ConfigError
- type Creator
- type Directive
- type Directives
- type FileString
- type LexOptions
- type Lexer
- type Lua
- type MatchFunc
- type NgxToken
- type ParseError
- type ParseOptions
- type Payload
- type PayloadError
- type RegisterBuilder
- type RegisterLexer
- type StringsCreator
- type SubScanner
Constants ¶
const MaxIndent = 100
const TokenChanCap = 2048
Variables ¶
var (
ErrPrematureLexEnd = errors.New("premature end of file")
)
Functions ¶
func Build ¶
func Build(w io.Writer, config Config, options *BuildOptions) error
Build creates an NGINX config from a crossplane.Config.
func BuildFiles ¶
func BuildFiles(payload Payload, dir string, options *BuildOptions) error
BuildFiles builds all of the config files in a crossplane.Payload and writes them to disk.
func BuildInto ¶
func BuildInto(payload *Payload, into Creator, options *BuildOptions) error
BuildInto builds all of the config files in a crossplane.Payload and writes them to the Creator.
func DefaultDirectivesMatchFunc ¶ added in v0.4.45
func LexWithOptions ¶ added in v0.4.42
func LexWithOptions(r io.Reader, options LexOptions) chan NgxToken
LexWithOptions allows for custom lexing behavior through external lexers specified in the LexOptions.
func MatchAppProtectWAFv4 ¶ added in v0.4.37
MatchAppProtectWAFv4 is a MatchFunc for App Protect v4 module.
func MatchAppProtectWAFv5 ¶ added in v0.4.37
MatchAppProtectWAFv5 is a MatchFunc for App Protect v5 module.
func MatchGeoip2Latest ¶ added in v0.4.62
MatchGeoip2Latest is a MatchFunc for the latest version of geoip2.
func MatchHeadersMoreLatest ¶ added in v0.4.59
MatchHeadersMoreLatest is a MatchFunc for the latest version of headersmore.
func MatchLuaLatest ¶ added in v0.4.59
MatchLuaLatest is a MatchFunc for latest version of Lua.
func MatchNginxPlusLatest ¶ added in v0.4.59
MatchNginxPlusLatest contains directives in latest version of Nginx Plus source code(including GEOIP, Perl, and XSLT)
func MatchNginxPlusR30 ¶ added in v0.4.59
func MatchNginxPlusR31 ¶ added in v0.4.59
func MatchNginxPlusR33 ¶ added in v0.4.72
MatchNginxPlusR33 contains directives in Nginx Plus R33 source code(including GEOIP, Perl, and XSLT)
func MatchNjsLatest ¶ added in v0.4.59
MatchNjsLatest is a MatchFunc for the latest version of njs.
func MatchOss124 ¶ added in v0.4.59
MatchOss124 contains directives in OSS 1.2.4 source code(including GEOIP, Perl, and XSLT)
func MatchOss126 ¶ added in v0.4.59
MatchOss126 contains directives in OSS 1.2.6 source code(including GEOIP, Perl, and XSLT)
func MatchOssLatest ¶ added in v0.4.59
MatchOssLatest contains directives in latest version of OSS source code(including GEOIP, Perl, and XSLT)
func MatchOtelLatest ¶ added in v0.4.59
MatchOtelLatest is a MatchFunc for latest version of otel.
func SetTokenChanCap ¶
func SetTokenChanCap(size int)
note: this is only used during tests, should not be changed
Types ¶
type BuildOptions ¶
type BuildOptions struct { Indent int Tabs bool Header bool Builders []RegisterBuilder // handle specific directives // contains filtered or unexported fields }
type Builder ¶ added in v0.4.42
Builder is the interface implemented by types that can render a Directive as it appears in NGINX configuration files.
Build writes the strings that represent the Directive and it's Block to the io.StringWriter returning any error encountered that caused the write to stop early. Build must not modify the Directive.
type Config ¶
type Config struct { File string `json:"file"` Status string `json:"status"` Errors []ConfigError `json:"errors"` Parsed Directives `json:"parsed"` }
type ConfigError ¶
type Creator ¶
type Creator interface { Create(path string) (io.WriteCloser, error) Reset() }
Creator abstracts file creation (to write configs to something other than files).
type Directive ¶
type Directive struct { Directive string `json:"directive"` Line int `json:"line"` Args []string `json:"args"` File string `json:"file,omitempty"` Includes []int `json:"includes,omitempty"` Block Directives `json:"block,omitempty"` Comment *string `json:"comment,omitempty"` // IsMapBlockParameter is true if the directive represents a parameter in the body of a "map-like" directive. IsMapBlockParameter bool `json:"mapBlockParameter,omitempty"` }
type Directives ¶
type Directives []*Directive
type FileString ¶
type FileString struct { Name string // contains filtered or unexported fields }
FileString is a string representation of a file.
type LexOptions ¶ added in v0.4.42
type LexOptions struct { Lexers []RegisterLexer // contains filtered or unexported fields }
LexOptions allows customization of the lexing process by specifying external lexers that can handle specific directives. By registering interest in particular directives, external lexers can ensure that these directives are processed separately from the general lexical analysis logic.
type Lexer ¶ added in v0.4.42
type Lexer interface { // Lex processes a matched token and returns a channel of NgxToken objects. // This method performs lexical analysis on the matched token and produces a stream of tokens for the parser to consume. // The external lexer should close the channel once it has completed lexing the input to signal the end of tokens. // Failure to close the channel will cause the receiver to wait indefinitely. Lex(s *SubScanner, matchedToken string) <-chan NgxToken }
Lexer is an interface for implementing lexers that handle external NGINX tokens during the lexical analysis phase.
type Lua ¶ added in v0.4.42
type Lua struct{}
Lua adds support for directives added to NGINX by the ngx_http_lua_module module.
Lua implements the Lexer interface by tokenizing *_by_lua_block directives with a simple Lua parser. The Lua blocks will be placed into a token to be set as an argument on the Lua directive.
Lua also implements the Builder interface by writing the *_by_lua_block directive's contents into the directive's block.
func (*Lua) Build ¶ added in v0.4.42
Build generates Lua configurations based on the provided directive.
func (*Lua) Lex ¶ added in v0.4.42
func (l *Lua) Lex(s *SubScanner, matchedToken string) <-chan NgxToken
Lex lexically analyzes the Lua blocks based on directives detected. It is used by the lexer to tokenize Lua content within configuration files.
func (*Lua) RegisterBuilder ¶ added in v0.4.42
func (l *Lua) RegisterBuilder() RegisterBuilder
RegisterBuilder registers a builder for generating Lua NGINX configuration.
func (*Lua) RegisterLexer ¶ added in v0.4.42
func (l *Lua) RegisterLexer() RegisterLexer
RegisterLexer registers a lexer for parsing Lua blocks.
type MatchFunc ¶ added in v0.4.37
MatchFunc is the signature of the match function used to identify NGINX directives that can be encountered when parsing an NGINX configuration that references dynamic or non-core modules. The argument is the name of a directive found when parsing an NGINX configuration.
The return value is a list of bitmasks that indicate the valid contexts in which the directive may appear as well as the number of arguments the directive accepts. The return value must contain at least one non-zero bitmask if matched is true.
type ParseError ¶
type ParseError struct { What string File *string Line *int // Raw directive statement causing the parse error. Statement string // Block in which parse error occurred. BlockCtx string // contains filtered or unexported fields }
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) MarshalJSON ¶
func (e *ParseError) MarshalJSON() ([]byte, error)
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type ParseOptions ¶
type ParseOptions struct { // An array of directives to skip over and not include in the payload. IgnoreDirectives []string // If an error is found while parsing, it will be passed to this callback // function. The results of the callback function will be set in the // PayloadError struct that's added to the Payload struct's Errors array. ErrorCallback func(error) interface{} // If specified, use this alternative to open config files Open func(path string) (io.ReadCloser, error) // Glob will return a matching list of files if specified Glob func(path string) ([]string, error) // If true, parsing will stop immediately if an error is found. StopParsingOnError bool // If true, include directives are used to combine all of the Payload's // Config structs into one. CombineConfigs bool // If true, only the config file with the given filename will be parsed // and Parse will not parse files included files. SingleFile bool // If true, comments will be parsed and added to the resulting Payload. ParseComments bool // If true, add an error to the payload when encountering a directive that // is unrecognized. The unrecognized directive will not be included in the // resulting Payload. ErrorOnUnknownDirectives bool // If true, checks that directives are in valid contexts. SkipDirectiveContextCheck bool // If true, checks that directives have a valid number of arguments. SkipDirectiveArgsCheck bool // DirectiveSources is used to indicate the set of directives to be expected // by the parser. DirectiveSources can include different versions of NGINX // and dynamic modules. If DirectiveSources is empty, the parser defaults // to DefaultDirectivesMatchFunc. DirectiveSources []MatchFunc LexOptions LexOptions }
ParseOptions determine the behavior of an NGINX config parse.
type Payload ¶
type Payload struct { Status string `json:"status"` Errors []PayloadError `json:"errors"` Config []Config `json:"config"` }
type PayloadError ¶
type RegisterBuilder ¶ added in v0.4.42
type RegisterBuilder interface {
// contains filtered or unexported methods
}
RegisterBuilder is an option that can be used to add a builder to build NGINX configuration for custom directives.
func BuildWithBuilder ¶ added in v0.4.42
func BuildWithBuilder(b Builder, directives ...string) RegisterBuilder
BuildWithBuilder registers a builder to build the NGINX configuration for the given directives.
type RegisterLexer ¶ added in v0.4.42
type RegisterLexer interface {
// contains filtered or unexported methods
}
RegisterLexer is an option that cna be used to add a lexer to tokenize external NGINX tokens.
func LexWithLexer ¶ added in v0.4.42
func LexWithLexer(l Lexer, stringTokens ...string) RegisterLexer
LexWithLexer registers a Lexer that implements tokenization of an NGINX configuration after one of the given stringTokens is encountered by Lex.
type StringsCreator ¶
type StringsCreator struct {
Files []*FileString
}
StringsCreator is an option for rendering config files to strings(s).
func (*StringsCreator) Create ¶
func (sc *StringsCreator) Create(file string) (io.WriteCloser, error)
Create makes this a Creator.
func (*StringsCreator) Reset ¶
func (sc *StringsCreator) Reset()
Reset returns the Creator to its initial state.
type SubScanner ¶ added in v0.4.42
type SubScanner struct {
// contains filtered or unexported fields
}
SubScanner provides an interface for scanning alternative grammars within NGINX configuration data.
func (*SubScanner) Err ¶ added in v0.4.42
func (e *SubScanner) Err() error
Err returns the fist non-EOF error encountered by the Scanner.
func (*SubScanner) Line ¶ added in v0.4.42
func (e *SubScanner) Line() int
Line returns the line number of the most recent token generated by a call to Scan.
func (*SubScanner) Scan ¶ added in v0.4.42
func (e *SubScanner) Scan() bool
Scan advances the scanner to the next token which will be available though the Text method. It returns false when the scan stops by reaching the end of input.
func (*SubScanner) Text ¶ added in v0.4.42
func (e *SubScanner) Text() string
Text returns the most recent token generated by a call to Scan.
Source Files
¶
- analyze.go
- analyze_appProtectWAFv4_directives.gen.go
- analyze_appProtectWAFv5_directives.gen.go
- analyze_geoip2_directives.gen.go
- analyze_headersMore_directives.gen.go
- analyze_lua_directives.gen.go
- analyze_map.go
- analyze_njs_directives.gen.go
- analyze_nplus_R30_directives.go
- analyze_nplus_R31_directives.go
- analyze_nplus_R33_directives.gen.go
- analyze_nplus_latest_directives.gen.go
- analyze_oss_124_directives.gen.go
- analyze_oss_126_directives.gen.go
- analyze_oss_latest_directives.gen.go
- analyze_otel_directives.gen.go
- buffer.go
- build.go
- errors.go
- lex.go
- lua.go
- parse.go
- types.go
- util.go