Skip to content

Commit 58c4e8f

Browse files
authored
Merge pull request #192 from kubernetes-incubator/revert-189-automated-cherry-pick-of-#183-upstream-release-1.0
Revert "Automated cherry pick of #183"
2 parents f45238d + eec70a6 commit 58c4e8f

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

kubernetes/config/kube_config.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,14 @@ class FileOrData(object):
5959
content of obj[%file_key_name] and represent it as file or data.
6060
Note that the data is preferred. The obj[%file_key_name] will be used iff
6161
obj['%data_key_name'] is not set or empty. Assumption is file content is
62-
raw data and data field is base64 string. The assumption can be changed
63-
with base64_file_content flag. If set to False, the content of the file
64-
will assumed to be base64 and read as is. The default True value will
65-
result in base64 encode of the file content after read."""
62+
raw data and data field is base64 string."""
6663

6764
def __init__(self, obj, file_key_name, data_key_name=None,
68-
file_base_path="", base64_file_content=True):
65+
file_base_path=""):
6966
if not data_key_name:
7067
data_key_name = file_key_name + "-data"
7168
self._file = None
7269
self._data = None
73-
self._base64_file_content = base64_file_content
7470
if data_key_name in obj:
7571
self._data = obj[data_key_name]
7672
elif file_key_name in obj:
@@ -82,11 +78,8 @@ def as_file(self):
8278
decoded obj[%data_key_name] content otherwise obj[%file_key_name]."""
8379
use_data_if_no_file = not self._file and self._data
8480
if use_data_if_no_file:
85-
if self._base64_file_content:
86-
self._file = _create_temp_file_with_content(
87-
base64.decodestring(self._data.encode()))
88-
else:
89-
self._file = _create_temp_file_with_content(self._data)
81+
self._file = _create_temp_file_with_content(
82+
base64.decodestring(self._data.encode()))
9083
if self._file and not os.path.isfile(self._file):
9184
raise ConfigException("File does not exists: %s" % self._file)
9285
return self._file
@@ -97,11 +90,8 @@ def as_data(self):
9790
use_file_if_no_data = not self._data and self._file
9891
if use_file_if_no_data:
9992
with open(self._file) as f:
100-
if self._base64_file_content:
101-
self._data = bytes.decode(
102-
base64.encodestring(str.encode(f.read())))
103-
else:
104-
self._data = f.read()
93+
self._data = bytes.decode(
94+
base64.encodestring(str.encode(f.read())))
10595
return self._data
10696

10797

@@ -174,8 +164,7 @@ def _load_gcp_token(self):
174164
def _load_user_token(self):
175165
token = FileOrData(
176166
self._user, 'tokenFile', 'token',
177-
file_base_path=self._config_base_path,
178-
base64_file_content=False).as_data()
167+
file_base_path=self._config_base_path).as_data()
179168
if token:
180169
self.token = "Bearer %s" % token
181170
return True

kubernetes/config/kube_config_test.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ def test_file_given_data(self):
108108
data_key_name=TEST_DATA_KEY)
109109
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
110110

111-
def test_file_given_data_no_base64(self):
112-
obj = {TEST_DATA_KEY: TEST_DATA}
113-
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
114-
data_key_name=TEST_DATA_KEY, base64_file_content=False)
115-
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
116-
117111
def test_data_given_data(self):
118112
obj = {TEST_DATA_KEY: TEST_DATA_BASE64}
119113
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
@@ -126,13 +120,6 @@ def test_data_given_file(self):
126120
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY)
127121
self.assertEqual(TEST_DATA_BASE64, t.as_data())
128122

129-
def test_data_given_file_no_base64(self):
130-
obj = {
131-
TEST_FILE_KEY: self._create_temp_file(content=TEST_DATA)}
132-
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
133-
base64_file_content=False)
134-
self.assertEqual(TEST_DATA, t.as_data())
135-
136123
def test_data_given_file_and_data(self):
137124
obj = {
138125
TEST_DATA_KEY: TEST_DATA_BASE64,
@@ -575,7 +562,7 @@ def test_ssl_with_relative_ssl_files(self):
575562
with open(os.path.join(temp_dir, "client_key"), "wb") as fd:
576563
fd.write(TEST_CLIENT_KEY.encode())
577564
with open(os.path.join(temp_dir, "token_file"), "wb") as fd:
578-
fd.write(TEST_DATA_BASE64.encode())
565+
fd.write(TEST_DATA.encode())
579566
KubeConfigLoader(
580567
config_dict=self.TEST_KUBE_CONFIG,
581568
active_context="ssl-local-file",

0 commit comments

Comments
 (0)