Debian Codegraph @

ansible_collections/community/docker/plugins/action/docker_container_copy_into.py

raw
1 # Copyright (c) 2022, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import annotations
6
7 import base64
8 import typing as t
9
10 from ansible import constants as C
11 from ansible.plugins.action import ActionBase
12 from ansible.utils.vars import merge_hash
13
14 from ansible_collections.community.docker.plugins.module_utils._scramble import (
15 unscramble,
16 )
17
18
19 class ActionModule(ActionBase):
20 # Set to True when transferring files to the remote
21 TRANSFERS_FILES = False
22
23 def run(
24 self, tmp: str | None = None, task_vars: dict[str, t.Any] | None = None
25 ) -> dict[str, t.Any]:
26 self._supports_check_mode = True
27 self._supports_async = True
28
29 result = super().run(tmp, task_vars)
30 del tmp # tmp no longer has any effect
31
32 # pylint: disable-next=no-member
33 max_file_size_for_diff: int = C.MAX_FILE_SIZE_FOR_DIFF # type: ignore
34 self._task.args["_max_file_size_for_diff"] = max_file_size_for_diff
35
36 result = merge_hash(
37 result,
38 self._execute_module(task_vars=task_vars, wrap_async=self._task.async_val),
39 )
40
41 if "diff" in result and result["diff"].get("scrambled_diff"):
42 # Scrambling is not done for security, but to avoid no_log screwing up the diff
43 diff = result["diff"]
44 key = base64.b64decode(diff.pop("scrambled_diff"))
45 for k in ("before", "after"):
46 if k in diff:
47 diff[k] = unscramble(diff[k], key)
48
49 return result