Skip to content

Commit c61c102

Browse files
committed
chocolatey: add viruscheck as an optional cli argument to install
1 parent dce4aad commit c61c102

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

changelog/68558.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an option in the chocolatey state and module so that the viruscheck flag can be controlled.

salt/modules/chocolatey.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ def install(
578578
package_args=None,
579579
allow_multiple=False,
580580
execution_timeout=None,
581+
viruscheck=None,
581582
):
582583
"""
583584
Instructs Chocolatey to install a package.
@@ -642,6 +643,13 @@ def install(
642643
643644
.. versionadded:: 2018.3.0
644645
646+
viruscheck (bool):
647+
Enable or disable the chocolatey virus check extension (licensed
648+
version only). If not provided then no arguments are added.
649+
Default is ``None``.
650+
651+
.. versionadded:: 3006.18
652+
645653
Returns:
646654
str: The output of the ``chocolatey`` command
647655
@@ -683,6 +691,9 @@ def install(
683691
cmd.append("--allow-multiple")
684692
if execution_timeout:
685693
cmd.extend(["--execution-timeout", execution_timeout])
694+
if viruscheck is not None:
695+
virusarg = "--viruscheck" if viruscheck else "--skipviruscheck"
696+
cmd.append(virusarg)
686697

687698
# Salt doesn't need to see the progress
688699
cmd.extend(_no_progress())

salt/states/chocolatey.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def installed(
3535
package_args=None,
3636
allow_multiple=False,
3737
execution_timeout=None,
38+
viruscheck=None,
3839
):
3940
"""
4041
Installs a package if not already installed
@@ -89,6 +90,11 @@ def installed(
8990
Chocolatey execution timeout value you want to pass to the
9091
installation process. Default is ``None``.
9192
93+
viruscheck (bool):
94+
Enable or disable the chocolatey virus check extension (licensed
95+
version only). If not provided then no arguments are added.
96+
Default is ``None``.
97+
9298
Example:
9399
94100
.. code-block:: yaml
@@ -170,6 +176,7 @@ def installed(
170176
package_args=package_args,
171177
allow_multiple=allow_multiple,
172178
execution_timeout=execution_timeout,
179+
viruscheck=viruscheck,
173180
)
174181

175182
if "Running chocolatey failed" not in result:

tests/pytests/unit/modules/test_chocolatey.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ def test_add_source(choco_path):
277277
cmd_run_all_mock.assert_called_with(expected_call, python_shell=False)
278278

279279

280+
def test_install_viruscheck_true():
281+
mock_version = MagicMock(return_value="2.0.1")
282+
mock_find = MagicMock(return_value=choco_path)
283+
mock_run = MagicMock(return_value={"stdout": "No packages", "retcode": 0})
284+
with patch.object(chocolatey, "chocolatey_version", mock_version), patch.object(
285+
chocolatey, "_find_chocolatey", mock_find
286+
), patch.dict(chocolatey.__salt__, {"cmd.run_all": mock_run}):
287+
chocolatey.install("busybox", viruscheck=True)
288+
# --no-progress and --yes populated from separate functions within the module.
289+
expected_call = [choco_path, "install", "busybox", "--viruscheck", "--no-progress", "--yes"]
290+
mock_run.assert_called_with(expected_call, python_shell=False)
291+
292+
293+
def test_install_viruscheck_false():
294+
mock_version = MagicMock(return_value="2.0.1")
295+
mock_find = MagicMock(return_value=choco_path)
296+
mock_run = MagicMock(return_value={"stdout": "No packages", "retcode": 0})
297+
with patch.object(chocolatey, "chocolatey_version", mock_version), patch.object(
298+
chocolatey, "_find_chocolatey", mock_find
299+
), patch.dict(chocolatey.__salt__, {"cmd.run_all": mock_run}):
300+
chocolatey.install("busybox", viruscheck=False)
301+
# --no-progress and --yes populated from separate functions within the module.
302+
expected_call = [choco_path, "install", "busybox", "--skipviruscheck", "--no-progress", "--yes"]
303+
mock_run.assert_called_with(expected_call, python_shell=False)
304+
305+
280306
def test_list_pre_2_0_0():
281307
mock_version = MagicMock(return_value="1.2.1")
282308
mock_find = MagicMock(return_value=choco_path)

0 commit comments

Comments
 (0)