Debian Codegraph @

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

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