| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
| 2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 } | 398 } |
| 399 | 399 |
| 400 issued = int(time.time()) | 400 issued = int(time.time()) |
| 401 payload = { | 401 payload = { |
| 402 'iss': get_config().get('extensions', 'amo_key'), | 402 'iss': get_config().get('extensions', 'amo_key'), |
| 403 'jti': random.random(), | 403 'jti': random.random(), |
| 404 'iat': issued, | 404 'iat': issued, |
| 405 'exp': issued + 60, | 405 'exp': issued + 60, |
| 406 } | 406 } |
| 407 | 407 |
| 408 input = '.'.join([ | 408 input = '{}.{}'.format( |
|
Sebastian Noack
2016/09/13 15:03:12
'{}.{}'.format(...) seems more appropriate rather
Wladimir Palant
2016/09/13 15:16:54
Done.
| |
| 409 base64.b64encode(json.dumps(header)), | 409 base64.b64encode(json.dumps(header)), |
| 410 base64.b64encode(json.dumps(payload)) | 410 base64.b64encode(json.dumps(payload)) |
| 411 ]) | 411 ) |
| 412 | 412 |
| 413 signature = hmac.new(get_config().get('extensions', 'amo_secret'), | 413 signature = hmac.new(get_config().get('extensions', 'amo_secret'), |
| 414 msg=input, | 414 msg=input, |
| 415 digestmod=hashlib.sha256).digest() | 415 digestmod=hashlib.sha256).digest() |
| 416 token = '.'.join([input, base64.b64encode(signature)]) | 416 token = '{}.{}'.format(input, base64.b64encode(signature)) |
| 417 | 417 |
| 418 upload_url = ('https://addons.mozilla.org/api/v3/addons/{0}/' | 418 upload_url = ('https://addons.mozilla.org/api/v3/addons/{}/' |
|
Sebastian Noack
2016/09/13 15:03:12
Nit: Note that the indices in the placeholders are
Wladimir Palant
2016/09/13 15:16:54
Done.
| |
| 419 'versions/{1}/').format(self.extensionID, self.version) | 419 'versions/{}/').format(self.extensionID, self.version) |
| 420 | 420 |
| 421 with open(self.path, 'rb') as file: | 421 with open(self.path, 'rb') as file: |
| 422 data, content_type = urllib3.filepost.encode_multipart_formdata({ | 422 data, content_type = urllib3.filepost.encode_multipart_formdata({ |
| 423 'upload': ( | 423 'upload': ( |
| 424 os.path.basename(self.path), | 424 os.path.basename(self.path), |
| 425 file.read(), | 425 file.read(), |
| 426 'application/x-xpinstall' | 426 'application/x-xpinstall' |
| 427 ) | 427 ) |
| 428 }) | 428 }) |
| 429 | 429 |
| 430 request = urllib2.Request(upload_url, data=data) | 430 request = urllib2.Request(upload_url, data=data) |
| 431 request.add_header('Content-Type', content_type) | 431 request.add_header('Content-Type', content_type) |
| 432 request.add_header('Authorization', 'JWT ' + token) | 432 request.add_header('Authorization', 'JWT ' + token) |
| 433 request.get_method = lambda: 'PUT' | 433 request.get_method = lambda: 'PUT' |
| 434 | 434 |
| 435 try: | 435 try: |
| 436 urllib2.urlopen(request).close() | 436 urllib2.urlopen(request).close() |
| 437 except urllib2.HTTPError as e: | 437 except urllib2.HTTPError as e: |
| 438 logging.error(e.read()) | 438 try: |
|
Sebastian Noack
2016/09/13 15:03:12
The error response should be closed as well.
Wladimir Palant
2016/09/13 15:16:54
Done.
| |
| 439 logging.error(e.read()) | |
| 440 finally: | |
| 441 e.close() | |
| 439 raise | 442 raise |
| 440 | 443 |
| 441 def uploadToChromeWebStore(self): | 444 def uploadToChromeWebStore(self): |
| 442 # Google APIs use HTTP error codes with error message in body. So we add | 445 # Google APIs use HTTP error codes with error message in body. So we add |
| 443 # the response body to the HTTPError to get more meaningful error messag es. | 446 # the response body to the HTTPError to get more meaningful error messag es. |
| 444 | 447 |
| 445 class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler): | 448 class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler): |
| 446 def http_error_default(self, req, fp, code, msg, hdrs): | 449 def http_error_default(self, req, fp, code, msg, hdrs): |
| 447 raise urllib2.HTTPError(req.get_full_url(), code, '%s\n%s' % (ms g, fp.read()), hdrs, fp) | 450 raise urllib2.HTTPError(req.get_full_url(), code, '%s\n%s' % (ms g, fp.read()), hdrs, fp) |
| 448 | 451 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 except Exception, ex: | 581 except Exception, ex: |
| 579 logging.error('The build for %s failed:', repo) | 582 logging.error('The build for %s failed:', repo) |
| 580 logging.exception(ex) | 583 logging.exception(ex) |
| 581 | 584 |
| 582 file = open(nightlyConfigFile, 'wb') | 585 file = open(nightlyConfigFile, 'wb') |
| 583 nightlyConfig.write(file) | 586 nightlyConfig.write(file) |
| 584 | 587 |
| 585 | 588 |
| 586 if __name__ == '__main__': | 589 if __name__ == '__main__': |
| 587 main() | 590 main() |
| LEFT | RIGHT |