@@ -59,18 +59,14 @@ class FileOrData(object):
59
59
content of obj[%file_key_name] and represent it as file or data.
60
60
Note that the data is preferred. The obj[%file_key_name] will be used iff
61
61
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."""
66
63
67
64
def __init__ (self , obj , file_key_name , data_key_name = None ,
68
- file_base_path = "" , base64_file_content = True ):
65
+ file_base_path = "" ):
69
66
if not data_key_name :
70
67
data_key_name = file_key_name + "-data"
71
68
self ._file = None
72
69
self ._data = None
73
- self ._base64_file_content = base64_file_content
74
70
if data_key_name in obj :
75
71
self ._data = obj [data_key_name ]
76
72
elif file_key_name in obj :
@@ -82,11 +78,8 @@ def as_file(self):
82
78
decoded obj[%data_key_name] content otherwise obj[%file_key_name]."""
83
79
use_data_if_no_file = not self ._file and self ._data
84
80
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 ()))
90
83
if self ._file and not os .path .isfile (self ._file ):
91
84
raise ConfigException ("File does not exists: %s" % self ._file )
92
85
return self ._file
@@ -97,11 +90,8 @@ def as_data(self):
97
90
use_file_if_no_data = not self ._data and self ._file
98
91
if use_file_if_no_data :
99
92
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 ())))
105
95
return self ._data
106
96
107
97
@@ -174,8 +164,7 @@ def _load_gcp_token(self):
174
164
def _load_user_token (self ):
175
165
token = FileOrData (
176
166
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 ()
179
168
if token :
180
169
self .token = "Bearer %s" % token
181
170
return True
0 commit comments