From 217e1d576a69c1e991f0a21605fdbdc9346f074c Mon Sep 17 00:00:00 2001 From: AmbiguousYeoman Date: Thu, 13 Oct 2022 21:34:57 -0400 Subject: [PATCH 1/4] Add option to dig so we can specify type (e.g. TXT, MX, NS) for enhancement #5772 --- contrib/linux/actions/dig.py | 8 +++++++- contrib/linux/actions/dig.yaml | 3 +++ contrib/linux/tests/test_action_dig.py | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index 7eb8518a2a..9f04814208 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,8 @@ 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 +58,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/tests/test_action_dig.py b/contrib/linux/tests/test_action_dig.py index 008cf16e76..a12ebd3ecb 100644 --- a/contrib/linux/tests/test_action_dig.py +++ b/contrib/linux/tests/test_action_dig.py @@ -45,6 +45,18 @@ 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 +66,7 @@ def test_run(self): nameserver=None, hostname="google.com", queryopts="short", + querytype="A", ) self.assertIsInstance(results, list) self.assertGreater(len(results), 0) From f30746723ba011799869f8b4281fe8d248fa40d0 Mon Sep 17 00:00:00 2001 From: AmbiguousYeoman Date: Thu, 13 Oct 2022 21:48:31 -0400 Subject: [PATCH 2/4] Update CHANGELOG.rst --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b0aafea9c0..67341febce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -56,6 +56,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 Contributed by @cognifloyd +* Added querytype parameter to linux.dig action to allow specifying the dig 'type' parameter. Fixes #5772 + + Contributed by @AmbiguousYeoman + Changed ~~~~~~~ From 589cdfac7a600ade5c3ee5c025b7ecffac0ee385 Mon Sep 17 00:00:00 2001 From: AmbiguousYeoman Date: Mon, 17 Oct 2022 14:13:56 -0400 Subject: [PATCH 3/4] Black check format fixes --- contrib/linux/actions/dig.py | 3 +-- contrib/linux/tests/test_action_dig.py | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index 9f04814208..c20f28259e 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -44,7 +44,6 @@ def run(self, rand, count, nameserver, hostname, queryopts, querytype): cmd_args.append(hostname) cmd_args.append(querytype) - try: raw_result = subprocess.Popen( cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE @@ -60,7 +59,7 @@ def run(self, rand, count, nameserver, hostname, queryopts, querytype): # Better format the output when the type is TXT if querytype.lower() == "txt": - result_list_str = result_list_str.replace('"', '') + result_list_str = result_list_str.replace('"', "") result_list = list(filter(None, result_list_str.split("\n"))) diff --git a/contrib/linux/tests/test_action_dig.py b/contrib/linux/tests/test_action_dig.py index a12ebd3ecb..faf0373107 100644 --- a/contrib/linux/tests/test_action_dig.py +++ b/contrib/linux/tests/test_action_dig.py @@ -49,7 +49,12 @@ 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="" + rand=False, + count=0, + nameserver=None, + hostname="google.com", + queryopts="short", + querytype="", ) self.assertIsInstance(results, list) From 728c42b0484670273f1b567853ef2f0a8490dc73 Mon Sep 17 00:00:00 2001 From: AmbiguousYeoman Date: Fri, 21 Oct 2022 11:50:48 -0400 Subject: [PATCH 4/4] Bump linux pack version --- contrib/linux/pack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"