nserver.rules 🔗
ALL_QTYPES
module-attribute
🔗
All supported Query Types
New in 2.0
.
ResponseFunction
module-attribute
🔗
Type Alias for functions that will be called when a rule is matched
RuleResult
module-attribute
🔗
Type Alias for the result of a rule response function
RegexRule 🔗
RegexRule(
regex: Pattern,
allowed_qtypes: List[str],
func: ResponseFunction,
case_sensitive: bool = False,
)
Bases: RuleBase
Rule that uses the provided regex to attempt to match the query name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regex |
Pattern
|
compiled regex for matching |
required |
allowed_qtypes |
List[str]
|
match only the given query types |
required |
func |
ResponseFunction
|
response function to call |
required |
case_sensitive |
bool
|
how to case when matching
if |
False
|
RuleBase 🔗
Base class for all Rules to inherit from.
get_func 🔗
From the given query return the function to run, if any.
If no function should be run (i.e. because it does not match the rule),
then return None
.
This is to allow more efficient methods when determining a match and getting the rule function may be expensive (e.g. blueprints).
StaticRule 🔗
StaticRule(
match_string: str,
allowed_qtypes: List[str],
func: ResponseFunction,
case_sensitive: bool = False,
)
Bases: RuleBase
Rule that matches only the given string
StaticRule
is more efficient than using a WildcardStringRule
for static strings.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
match_string |
str
|
string to match |
required |
allowed_qtypes |
List[str]
|
match only the given query types |
required |
func |
ResponseFunction
|
response function to call |
required |
case_sensitive |
bool
|
how to case when matching |
False
|
WildcardStringRule 🔗
WildcardStringRule(
wildcard_string: str,
allowed_qtypes: List,
func: ResponseFunction,
case_sensitive: bool = False,
)
Bases: RuleBase
Rule that allows a more concise way of matching query names.
The following substitutions can be made:
*
will match a single domain label**
will match multiple domain labelsbase_domain
will match the registered domain using the Public Suffix List (PSL)
Examples:
_dmarc.{base_domain}
*._dkim.**
foo.*.bar.com
When operating with case_sensitive=False
, both the wildcard string and the
query name are covereted to lowercase prior to matching.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wildcard_string |
str
|
wildcard string to use |
required |
allowed_qtypes |
List
|
match only the given query types |
required |
func |
ResponseFunction
|
response function to call |
required |
case_sensitive |
bool
|
how to case when matching |
False
|
ZoneRule 🔗
ZoneRule(
zone: str,
allowed_qtypes: List[str],
func: ResponseFunction,
case_sensitive: bool = False,
)
Bases: RuleBase
Rule that matches the given domain or any subdomain
An empty zone (""
) will match any domain as this refers to the domain root (.
).
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zone |
str
|
zone root |
required |
allowed_qtypes |
List[str]
|
match only the given query types. |
required |
func |
ResponseFunction
|
response function to call |
required |
case_sensitive |
bool
|
how to case when matching |
False
|
smart_make_rule 🔗
Create a rule using shorthand notation.
The exact type of rule returned depends on what is povided by rule
.
If rule is a
RuleBase
class, then it is used directly.str
then it is checked to see if it contains substitutions. If it does then it will be aWildcardStringRule
, else aStaticRule
.Pattern
then aRegexRule
.
New in 2.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
Union[Type[RuleBase], str, Pattern]
|
input to process |
required |
args |
extra arguments to provide to the constructor |
()
|
|
kwargs |
extra keyword arguments to provide to the constructor |
{}
|