diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0ed261e846..e54f3c40f5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -93,6 +93,10 @@ Added to pants' use of PEX lockfiles. This is not a user-facing addition. #5713 #5724 #5726 #5725 #5732 #5733 #5737 #5738 #5758 #5751 #5774 #5776 #5777 #5782 Contributed by @cognifloyd +* Added querytype parameter to linux.dig action to allow specifying the dig 'type' parameter. Fixes #5772 + + Contributed by @AmbiguousYeoman + Changed ~~~~~~~ diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index 7eb8518a2a..c20f28259e 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -25,7 +25,7 @@ class DigAction(Action): - def run(self, rand, count, nameserver, hostname, queryopts): + def run(self, rand, count, nameserver, hostname, queryopts, querytype): opt_list = [] output = [] @@ -42,6 +42,7 @@ def run(self, rand, count, nameserver, hostname, queryopts): cmd_args.extend(["+" + option for option in opt_list]) cmd_args.append(hostname) + cmd_args.append(querytype) try: raw_result = subprocess.Popen( @@ -56,6 +57,10 @@ def run(self, rand, count, nameserver, hostname, queryopts): else: result_list_str = str(raw_result) + # Better format the output when the type is TXT + if querytype.lower() == "txt": + result_list_str = result_list_str.replace('"', "") + result_list = list(filter(None, result_list_str.split("\n"))) # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat diff --git a/contrib/linux/actions/dig.yaml b/contrib/linux/actions/dig.yaml index 77a218af90..861f83f8fb 100644 --- a/contrib/linux/actions/dig.yaml +++ b/contrib/linux/actions/dig.yaml @@ -17,4 +17,7 @@ parameters: count: type: integer default: 0 + querytype: + default: 'A' + type: string runner_type: "python-script" diff --git a/contrib/linux/pack.yaml b/contrib/linux/pack.yaml index e8d84b5bcd..1ca97e01b9 100644 --- a/contrib/linux/pack.yaml +++ b/contrib/linux/pack.yaml @@ -16,7 +16,7 @@ keywords: - open ports - processes - ps -version : 1.1.0 +version : 1.2.0 python_versions: - "2" - "3" diff --git a/contrib/linux/tests/test_action_dig.py b/contrib/linux/tests/test_action_dig.py index 008cf16e76..faf0373107 100644 --- a/contrib/linux/tests/test_action_dig.py +++ b/contrib/linux/tests/test_action_dig.py @@ -45,6 +45,23 @@ def test_run_with_empty_queryopts(self): self.assertIsInstance(result, str) self.assertGreater(len(result), 0) + def test_run_with_empty_querytype(self): + action = self.get_action_instance() + + results = action.run( + rand=False, + count=0, + nameserver=None, + hostname="google.com", + queryopts="short", + querytype="", + ) + self.assertIsInstance(results, list) + + for result in results: + self.assertIsInstance(result, str) + self.assertGreater(len(result), 0) + def test_run(self): action = self.get_action_instance() @@ -54,6 +71,7 @@ def test_run(self): nameserver=None, hostname="google.com", queryopts="short", + querytype="A", ) self.assertIsInstance(results, list) self.assertGreater(len(results), 0)