Skip to content

Commit 7a62165

Browse files
authored
fix: read config data with bytes (python3) (#41)
1 parent b0b29f3 commit 7a62165

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

kubernetes_asyncio/config/kube_config.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ def as_file(self):
9595
use_data_if_no_file = not self._file and self._data
9696
if use_data_if_no_file:
9797
if self._base64_file_content:
98+
if isinstance(self._data, str):
99+
content = self._data.encode()
100+
else:
101+
content = self._data
98102
self._file = _create_temp_file_with_content(
99-
base64.decodestring(self._data.encode()))
103+
base64.decodestring(content))
100104
else:
101105
self._file = _create_temp_file_with_content(self._data)
102106
if self._file and not os.path.isfile(self._file):

kubernetes_asyncio/config/kube_config_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ def test_create_temp_file_with_content(self):
197197
_create_temp_file_with_content(TEST_DATA)))
198198
_cleanup_temp_files()
199199

200+
def test_file_given_data_bytes(self):
201+
obj = {TEST_DATA_KEY: TEST_DATA_BASE64.encode()}
202+
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
203+
data_key_name=TEST_DATA_KEY)
204+
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
205+
206+
def test_file_given_data_bytes_no_base64(self):
207+
obj = {TEST_DATA_KEY: TEST_DATA.encode()}
208+
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
209+
data_key_name=TEST_DATA_KEY, base64_file_content=False)
210+
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
211+
200212

201213
class TestConfigNode(BaseTestCase):
202214

0 commit comments

Comments
 (0)