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

Commit

Permalink
Merge pull request #86 from tomplus/fix/config-bytes
Browse files Browse the repository at this point in the history
fix: read config data with bytes (python3)
  • Loading branch information
k8s-ci-robot committed Sep 19, 2018
2 parents d68e456 + 9d78cd7 commit 7d1e449
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 7d1e449

Please sign in to comment.