Debian Codegraph @

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

raw
1 # Ansible is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # Ansible is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
13
14 # Make coding more python3-ish
15 from __future__ import (absolute_import, division, print_function)
16 __metaclass__ = type
17
18 from ansible.module_utils._text import to_bytes
19
20 from ansible.parsing.vault import VaultSecret
21
22
23 class TextVaultSecret(VaultSecret):
24 '''A secret piece of text. ie, a password. Tracks text encoding.
25
26 The text encoding of the text may not be the default text encoding so
27 we keep track of the encoding so we encode it to the same bytes.'''
28
29 def __init__(self, text, encoding=None, errors=None, _bytes=None):
30 super(TextVaultSecret, self).__init__()
31 self.text = text
32 self.encoding = encoding or 'utf-8'
33 self._bytes = _bytes
34 self.errors = errors or 'strict'
35
36 @property
37 def bytes(self):
38 '''The text encoded with encoding, unless we specifically set _bytes.'''
39 return self._bytes or to_bytes(self.text, encoding=self.encoding, errors=self.errors)