mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Prepare 5.0.0 (#1123)
* Bump version to 5.0.0-a1. * Drop support for ansible-core 2.15 and 2.16. * Remove Python 2 and early Python 3 compatibility.
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import random
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||
from ansible_collections.community.docker.plugins.module_utils._six import PY2
|
||||
|
||||
|
||||
def generate_insecure_key():
|
||||
@@ -17,10 +15,7 @@ def generate_insecure_key():
|
||||
while True:
|
||||
# Generate a one-byte key. Right now the functions below do not use more
|
||||
# than one byte, so this is sufficient.
|
||||
if PY2:
|
||||
key = chr(random.randint(0, 255))
|
||||
else:
|
||||
key = bytes([random.randint(0, 255)])
|
||||
key = bytes([random.randint(0, 255)])
|
||||
# Return anything that is not zero
|
||||
if key != b'\x00':
|
||||
return key
|
||||
@@ -31,12 +26,8 @@ def scramble(value, key):
|
||||
if len(key) < 1:
|
||||
raise ValueError('Key must be at least one byte')
|
||||
value = to_bytes(value)
|
||||
if PY2:
|
||||
k = ord(key[0])
|
||||
value = b''.join([chr(k ^ ord(b)) for b in value])
|
||||
else:
|
||||
k = key[0]
|
||||
value = bytes([k ^ b for b in value])
|
||||
k = key[0]
|
||||
value = bytes([k ^ b for b in value])
|
||||
return '=S=' + to_native(base64.b64encode(value))
|
||||
|
||||
|
||||
@@ -47,10 +38,6 @@ def unscramble(value, key):
|
||||
if not value.startswith(u'=S='):
|
||||
raise ValueError('Value does not start with indicator')
|
||||
value = base64.b64decode(value[3:])
|
||||
if PY2:
|
||||
k = ord(key[0])
|
||||
value = b''.join([chr(k ^ ord(b)) for b in value])
|
||||
else:
|
||||
k = key[0]
|
||||
value = bytes([k ^ b for b in value])
|
||||
k = key[0]
|
||||
value = bytes([k ^ b for b in value])
|
||||
return to_text(value)
|
||||
|
||||
Reference in New Issue
Block a user