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

Commit 7d1e449

Browse files
authoredSep 19, 2018
Merge pull request #86 from tomplus/fix/config-bytes
fix: read config data with bytes (python3)
2 parents d68e456 + 9d78cd7 commit 7d1e449

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎config/kube_config.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ def as_file(self):
100100
use_data_if_no_file = not self._file and self._data
101101
if use_data_if_no_file:
102102
if self._base64_file_content:
103+
if isinstance(self._data, str):
104+
content = self._data.encode()
105+
else:
106+
content = self._data
103107
self._file = _create_temp_file_with_content(
104-
base64.decodestring(self._data.encode()))
108+
base64.decodestring(content))
105109
else:
106110
self._file = _create_temp_file_with_content(self._data)
107111
if self._file and not os.path.isfile(self._file):

‎config/kube_config_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ def test_create_temp_file_with_content(self):
201201
_create_temp_file_with_content(TEST_DATA)))
202202
_cleanup_temp_files()
203203

204+
def test_file_given_data_bytes(self):
205+
obj = {TEST_DATA_KEY: TEST_DATA_BASE64.encode()}
206+
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
207+
data_key_name=TEST_DATA_KEY)
208+
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
209+
210+
def test_file_given_data_bytes_no_base64(self):
211+
obj = {TEST_DATA_KEY: TEST_DATA.encode()}
212+
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
213+
data_key_name=TEST_DATA_KEY, base64_file_content=False)
214+
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
215+
204216

205217
class TestConfigNode(BaseTestCase):
206218

0 commit comments

Comments
 (0)
This repository has been archived.