crossplane icon indicating copy to clipboard operation
crossplane copied to clipboard

Make `map` and `types` directives analysable

Open chrisnovakovic opened this issue 2 years ago • 0 comments

Proposed changes

The map directive (from ngx_http_map_module and ngx_stream_map_module) and types directive (from ngx_http_core_module) are distinct from other directives, in that their child directives may be arbitrary strings that aren't known to Nginx. This causes crossplane to report unrecognised/misused directive errors when analysing them with strict or check_ctx enabled; it also means that no meaningful analysis can be performed when check_args is enabled because the arity of child directives is unknown.

Add support for map's special directives (default, hostnames, and volatile) to the analyser. Recognise that arbitrary directive names inside a map or types block are valid and that they accept either one argument (if used in map) or one or more arguments (if used in types).

Fixes #101 and #103.


The restructuring of the bit masks in analyzer.py is necessary because there's no space left in the combined one on 32-bit architectures. Exploiting the fact that there isn't actually a need for the valid contexts and arguments information to be represented by the same bit mask, I've separated them into individual bit masks for each directive, restructured DIRECTIVES so each directive has a pair of bit masks (contexts + arguments) instead of an individual one, and modified analyze so it inspects the relevant one depending on the check being performed. This restructuring also creates space for 12 further new fields in the contexts bit mask and 19 further new fields in the arguments bit mask.

Checklist

  • [x] I have read the CONTRIBUTING doc
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] I have checked that all unit tests pass after adding my changes
  • [x] I have updated necessary documentation
  • [x] I have rebased my branch onto master
  • [x] I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

chrisnovakovic avatar Jul 19 '22 15:07 chrisnovakovic