@@ -59,14 +59,18 @@ 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."""
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."""
6366
6467 def __init__ (self , obj , file_key_name , data_key_name = None ,
65- file_base_path = "" ):
68+ file_base_path = "" , base64_file_content = True ):
6669 if not data_key_name :
6770 data_key_name = file_key_name + "-data"
6871 self ._file = None
6972 self ._data = None
73+ self ._base64_file_content = base64_file_content
7074 if data_key_name in obj :
7175 self ._data = obj [data_key_name ]
7276 elif file_key_name in obj :
@@ -78,8 +82,11 @@ def as_file(self):
7882 decoded obj[%data_key_name] content otherwise obj[%file_key_name]."""
7983 use_data_if_no_file = not self ._file and self ._data
8084 if use_data_if_no_file :
81- self ._file = _create_temp_file_with_content (
82- base64 .decodestring (self ._data .encode ()))
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 )
8390 if self ._file and not os .path .isfile (self ._file ):
8491 raise ConfigException ("File does not exists: %s" % self ._file )
8592 return self ._file
@@ -90,8 +97,11 @@ def as_data(self):
9097 use_file_if_no_data = not self ._data and self ._file
9198 if use_file_if_no_data :
9299 with open (self ._file ) as f :
93- self ._data = bytes .decode (
94- base64 .encodestring (str .encode (f .read ())))
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 ()
95105 return self ._data
96106
97107
@@ -164,7 +174,8 @@ def _load_gcp_token(self):
164174 def _load_user_token (self ):
165175 token = FileOrData (
166176 self ._user , 'tokenFile' , 'token' ,
167- file_base_path = self ._config_base_path ).as_data ()
177+ file_base_path = self ._config_base_path ,
178+ base64_file_content = False ).as_data ()
168179 if token :
169180 self .token = "Bearer %s" % token
170181 return True
0 commit comments