Documentation
¶
Index ¶
- Constants
- Variables
- func AppProtectWAFv4DirectivesMatchFn(directive string) ([]uint, bool)
- func AppProtectWAFv5DirectivesMatchFn(directive string) ([]uint, bool)
- 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 HeadersMoreDirectivesMatchFn(directive string) ([]uint, bool)
- func Lex(reader io.Reader) chan NgxToken
- func LexWithOptions(r io.Reader, options LexOptions) chan NgxToken
- func LuaDirectivesMatchFn(directive string) ([]uint, bool)
- func NgxPlusLatestDirectivesMatchFn(directive string) ([]uint, bool)
- func NgxPlusR30DirectivesMatchFn(directive string) ([]uint, bool)
- func NgxPlusR31DirectivesMatchFn(directive string) ([]uint, bool)
- func NjsDirectivesMatchFn(directive string) ([]uint, bool)
- func Oss124DirectivesMatchFn(directive string) ([]uint, bool)
- func Oss126DirectivesMatchFn(directive string) ([]uint, bool)
- func OssLatestDirectivesMatchFn(directive string) ([]uint, bool)
- func OtelDirectivesMatchFn(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 AppProtectWAFv4DirectivesMatchFn ¶ added in v0.4.45
AppProtectWAFv4DirectivesMatchFn is a match function for parsing an NGINX config that contains the App Protect v4 module.
func AppProtectWAFv5DirectivesMatchFn ¶ added in v0.4.45
AppProtectWAFv5DirectivesMatchFn is a match function for parsing an NGINX config that contains the App Protect v5 module.
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 HeadersMoreDirectivesMatchFn ¶ 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 LuaDirectivesMatchFn ¶ added in v0.4.45
func NgxPlusLatestDirectivesMatchFn ¶ added in v0.4.45
func NgxPlusR30DirectivesMatchFn ¶ added in v0.4.45
func NgxPlusR31DirectivesMatchFn ¶ added in v0.4.45
func NjsDirectivesMatchFn ¶ added in v0.4.45
func Oss124DirectivesMatchFn ¶ added in v0.4.45
func Oss126DirectivesMatchFn ¶ added in v0.4.45
func OssLatestDirectivesMatchFn ¶ added in v0.4.45
func OtelDirectivesMatchFn ¶ added in v0.4.45
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(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"` }
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.go
- analyze_appProtectWAFv5_directives.go
- analyze_headersMore_directives.go
- analyze_lua_directives.go
- analyze_map.go
- analyze_njs_directives.go
- analyze_nplus_R30_directives.go
- analyze_nplus_R31_directives.go
- analyze_nplus_latest_directives.go
- analyze_oss_124_directives.go
- analyze_oss_126_directives.go
- analyze_oss_latest_directives.go
- analyze_otel_directives.go
- buffer.go
- build.go
- errors.go
- lex.go
- lua.go
- parse.go
- types.go
- util.go