use api manager token for sendfile API (#42351)

This commit is contained in:
Frédéric Péters 2020-05-04 09:18:34 +02:00
parent 3755b60ae9
commit b7a96424f1
1 changed files with 7 additions and 2 deletions

View File

@ -94,7 +94,11 @@ class GLCartaDSCS(AbstractCartaDSCS):
# to DoS the server.
# -- https://bz.apache.org/bugzilla/show_bug.cgi?id=39243
# and that's why there's a seemingly unnecessary GET request first.
self.requests.get(self.sendfile_ws_url)
api_manager_token = self.resource.get_api_manager_token()
response = self.requests.get(self.sendfile_ws_url,
headers={'Authorization': api_manager_token})
if response.status_code == 401:
api_manager_token = self.resource.get_api_manager_token(renew=True)
b64_zip = base64.b64encode(open(zip_filename, 'rb').read())
chunk_size = 16777216 # 16MB
for n in range(0, len(b64_zip), chunk_size):
@ -102,7 +106,8 @@ class GLCartaDSCS(AbstractCartaDSCS):
data={
'fileName': self.sendfile_ws_dirname + os.path.basename(zip_filename),
'b64_fileContent': b64_zip[n:n+chunk_size].decode('ascii'),
}
},
headers={'Authorization': api_manager_token}
)
resp.raise_for_status()
if resp.content: