Skip to content
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~

Expand Down
7 changes: 6 additions & 1 deletion contrib/linux/actions/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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(
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions contrib/linux/actions/dig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ parameters:
count:
type: integer
default: 0
querytype:
default: 'A'
type: string
runner_type: "python-script"
2 changes: 1 addition & 1 deletion contrib/linux/pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ keywords:
- open ports
- processes
- ps
version : 1.1.0
version : 1.2.0
python_versions:
- "2"
- "3"
Expand Down
18 changes: 18 additions & 0 deletions contrib/linux/tests/test_action_dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down