Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

fix: read config data with bytes (python3) #86

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ def as_file(self):
use_data_if_no_file = not self._file and self._data
if use_data_if_no_file:
if self._base64_file_content:
if isinstance(self._data, str):
content = self._data.encode()
else:
content = self._data
self._file = _create_temp_file_with_content(
base64.decodestring(self._data.encode()))
base64.decodestring(content))
else:
self._file = _create_temp_file_with_content(self._data)
if self._file and not os.path.isfile(self._file):
Expand Down
12 changes: 12 additions & 0 deletions config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ def test_create_temp_file_with_content(self):
_create_temp_file_with_content(TEST_DATA)))
_cleanup_temp_files()

def test_file_given_data_bytes(self):
obj = {TEST_DATA_KEY: TEST_DATA_BASE64.encode()}
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
data_key_name=TEST_DATA_KEY)
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))

def test_file_given_data_bytes_no_base64(self):
obj = {TEST_DATA_KEY: TEST_DATA.encode()}
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
data_key_name=TEST_DATA_KEY, base64_file_content=False)
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))


class TestConfigNode(BaseTestCase):

Expand Down