mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Merge remote-tracking branch 'origin/main' into meta-processor
This commit is contained in:
@@ -14,7 +14,14 @@
|
||||
* YamlProvider now supports a `shared_filename` that can be used to add a set of
|
||||
common records across all zones using the provider. It can be used stand-alone
|
||||
or in combination with zone files and/or split configs to aid in DRYing up DNS
|
||||
configs.
|
||||
* YamlProvider now supports an `!include` directive which enables shared
|
||||
snippets of config to be reused across many records, e.g. common dynamic rules
|
||||
across a set of services with service-specific pool values or a unified SFP
|
||||
value included in TXT records at the root of all zones.
|
||||
* SpfRecord is formally deprecated with an warning and will become a
|
||||
ValidationError in 2.x
|
||||
* SpfDnsLookupProcessor is formally deprcated in favor of the version relocated
|
||||
into https://github.com/octodns/octodns-spf and will be removed in 2.x
|
||||
* MetaProcessor added to enable some useful/cool options for debugging/tracking
|
||||
DNS changes. Specifically timestamps/uuid so you can track whether changes
|
||||
that have been pushed to providers have propogated/transferred correctly.
|
||||
|
||||
@@ -55,6 +55,9 @@ class SpfDnsLookupProcessor(BaseProcessor):
|
||||
|
||||
def __init__(self, name):
|
||||
self.log.debug(f"SpfDnsLookupProcessor: {name}")
|
||||
self.log.warning(
|
||||
'SpfDnsLookupProcessor is DEPRECATED in favor of the version relocated into octodns-spf and will be removed in 2.0'
|
||||
)
|
||||
super().__init__(name)
|
||||
|
||||
def _get_spf_from_txt_values(
|
||||
|
||||
@@ -10,5 +10,11 @@ class SpfRecord(_ChunkedValuesMixin, Record):
|
||||
_type = 'SPF'
|
||||
_value_type = _ChunkedValue
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.log.warning(
|
||||
'The SPF record type is DEPRECATED in favor of TXT values and will become an ValidationError in 2.0'
|
||||
)
|
||||
|
||||
|
||||
Record.register_type(SpfRecord)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#
|
||||
#
|
||||
|
||||
from os.path import dirname, join
|
||||
|
||||
from natsort import natsort_keygen
|
||||
from yaml import SafeDumper, SafeLoader, dump, load
|
||||
from yaml.constructor import ConstructorError
|
||||
@@ -23,7 +25,17 @@ class ContextLoader(SafeLoader):
|
||||
def _construct(self, node):
|
||||
return self._pairs(node)[0]
|
||||
|
||||
def include(self, node):
|
||||
mark = self.get_mark()
|
||||
directory = dirname(mark.name)
|
||||
|
||||
filename = join(directory, self.construct_scalar(node))
|
||||
|
||||
with open(filename, 'r') as fh:
|
||||
return safe_load(fh, self.__class__)
|
||||
|
||||
|
||||
ContextLoader.add_constructor('!include', ContextLoader.include)
|
||||
ContextLoader.add_constructor(
|
||||
ContextLoader.DEFAULT_MAPPING_TAG, ContextLoader._construct
|
||||
)
|
||||
|
||||
5
tests/config/include/array.yaml
Normal file
5
tests/config/include/array.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- 14
|
||||
- 15
|
||||
- 16
|
||||
- 72
|
||||
3
tests/config/include/dict.yaml
Normal file
3
tests/config/include/dict.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
k: v
|
||||
z: 42
|
||||
1
tests/config/include/empty.yaml
Normal file
1
tests/config/include/empty.yaml
Normal file
@@ -0,0 +1 @@
|
||||
---
|
||||
2
tests/config/include/include-doesnt-exist.yaml
Normal file
2
tests/config/include/include-doesnt-exist.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
key: !include does-not-exist.yaml
|
||||
8
tests/config/include/main.yaml
Normal file
8
tests/config/include/main.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
included-array: !include array.yaml
|
||||
included-dict: !include dict.yaml
|
||||
included-empty: !include empty.yaml
|
||||
included-nested: !include nested.yaml
|
||||
included-subdir: !include subdir/value.yaml
|
||||
key: value
|
||||
name: main
|
||||
2
tests/config/include/nested.yaml
Normal file
2
tests/config/include/nested.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
!include subdir/value.yaml
|
||||
2
tests/config/include/subdir/value.yaml
Normal file
2
tests/config/include/subdir/value.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
Hello World!
|
||||
@@ -62,3 +62,27 @@ class TestYaml(TestCase):
|
||||
buf = StringIO()
|
||||
safe_dump({'45a03129': 42, '45a0392a': 43}, buf)
|
||||
self.assertEqual("---\n45a0392a: 43\n45a03129: 42\n", buf.getvalue())
|
||||
|
||||
def test_include(self):
|
||||
with open('tests/config/include/main.yaml') as fh:
|
||||
data = safe_load(fh)
|
||||
self.assertEqual(
|
||||
{
|
||||
'included-array': [14, 15, 16, 72],
|
||||
'included-dict': {'k': 'v', 'z': 42},
|
||||
'included-empty': None,
|
||||
'included-nested': 'Hello World!',
|
||||
'included-subdir': 'Hello World!',
|
||||
'key': 'value',
|
||||
'name': 'main',
|
||||
},
|
||||
data,
|
||||
)
|
||||
|
||||
with open('tests/config/include/include-doesnt-exist.yaml') as fh:
|
||||
with self.assertRaises(FileNotFoundError) as ctx:
|
||||
data = safe_load(fh)
|
||||
self.assertEqual(
|
||||
"[Errno 2] No such file or directory: 'tests/config/include/does-not-exist.yaml'",
|
||||
str(ctx.exception),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user