diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 384c0a2..39bae2a 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -137,7 +137,7 @@ class Record(EqualityTupleMixin): reasons.append('missing ttl') try: if data['octodns']['healthcheck']['protocol'] \ - not in ('HTTP', 'HTTPS'): + not in ('HTTP', 'HTTPS', 'TCP'): reasons.append('invalid healthcheck protocol') except KeyError: pass @@ -181,15 +181,21 @@ class Record(EqualityTupleMixin): @property def healthcheck_host(self): + healthcheck = self._octodns.get('healthcheck', {}) + if healthcheck.get('protocol', None) == 'TCP': + return None try: - return self._octodns['healthcheck']['host'] + return healthcheck['host'] except KeyError: return self.fqdn[:-1] @property def healthcheck_path(self): + healthcheck = self._octodns.get('healthcheck', {}) + if healthcheck.get('protocol', None) == 'TCP': + return None try: - return self._octodns['healthcheck']['path'] + return healthcheck['path'] except KeyError: return '/_dns' diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index f76f593..b6dc4e9 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -886,6 +886,40 @@ class TestRecord(TestCase): self.assertEquals('HTTPS', new.healthcheck_protocol) self.assertEquals(443, new.healthcheck_port) + def test_healthcheck_tcp(self): + new = Record.new(self.zone, 'a', { + 'ttl': 44, + 'type': 'A', + 'value': '1.2.3.4', + 'octodns': { + 'healthcheck': { + 'path': '/ignored', + 'host': 'completely.ignored', + 'protocol': 'TCP', + 'port': 8080, + } + } + }) + self.assertIsNone(new.healthcheck_path) + self.assertIsNone(new.healthcheck_host) + self.assertEquals('TCP', new.healthcheck_protocol) + self.assertEquals(8080, new.healthcheck_port) + + new = Record.new(self.zone, 'a', { + 'ttl': 44, + 'type': 'A', + 'value': '1.2.3.4', + 'octodns': { + 'healthcheck': { + 'protocol': 'TCP', + } + } + }) + self.assertIsNone(new.healthcheck_path) + self.assertIsNone(new.healthcheck_host) + self.assertEquals('TCP', new.healthcheck_protocol) + self.assertEquals(443, new.healthcheck_port) + def test_inored(self): new = Record.new(self.zone, 'txt', { 'ttl': 44,