Debian Codegraph @

ansible_collections/community/aws/tests/unit/mock/vault_helper.py

raw
1 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6
7 __metaclass__ = type
8
9 from ansible.module_utils._text import to_bytes
10 from ansible.parsing.vault import VaultSecret
11
12
13 class TextVaultSecret(VaultSecret):
14 """A secret piece of text. ie, a password. Tracks text encoding.
15
16 The text encoding of the text may not be the default text encoding so
17 we keep track of the encoding so we encode it to the same bytes."""
18
19 def __init__(self, text, encoding=None, errors=None, _bytes=None):
20 super(TextVaultSecret, self).__init__()
21 self.text = text
22 self.encoding = encoding or "utf-8"
23 self._bytes = _bytes
24 self.errors = errors or "strict"
25
26 @property
27 def bytes(self):
28 """The text encoded with encoding, unless we specifically set _bytes."""
29 return self._bytes or to_bytes(self.text, encoding=self.encoding, errors=self.errors)