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( |
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/{}/' |
419 'versions/{1}/').format(self.extensionID, self.version) | 419 'versions/{}/').format(self.extensionID, self.version) |
420 | 420 |
421 opener = urllib2.build_opener(urllib2.HTTPHandler) | |
422 with open(self.path, 'rb') as file: | 421 with open(self.path, 'rb') as file: |
423 data, content_type = urllib3.filepost.encode_multipart_formdata({ | 422 data, content_type = urllib3.filepost.encode_multipart_formdata({ |
424 'upload': ( | 423 'upload': ( |
425 os.path.basename(self.path), | 424 os.path.basename(self.path), |
426 file.read(), | 425 file.read(), |
427 'application/x-xpinstall' | 426 'application/x-xpinstall' |
428 ) | 427 ) |
429 }) | 428 }) |
430 | 429 |
431 request = urllib2.Request(upload_url, data=data) | 430 request = urllib2.Request(upload_url, data=data) |
432 request.add_header('Content-Type', content_type) | 431 request.add_header('Content-Type', content_type) |
433 request.add_header('Authorization', 'JWT ' + token) | 432 request.add_header('Authorization', 'JWT ' + token) |
434 request.get_method = lambda: 'PUT' | 433 request.get_method = lambda: 'PUT' |
435 | 434 |
436 try: | 435 try: |
437 opener.open(request).close() | 436 urllib2.urlopen(request).close() |
438 except urllib2.HTTPError as e: | 437 except urllib2.HTTPError as e: |
439 logging.error(e.read()) | 438 try: |
| 439 logging.error(e.read()) |
| 440 finally: |
| 441 e.close() |
440 raise | 442 raise |
441 | 443 |
442 def uploadToChromeWebStore(self): | 444 def uploadToChromeWebStore(self): |
443 # 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 |
444 # 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. |
445 | 447 |
446 class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler): | 448 class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler): |
447 def http_error_default(self, req, fp, code, msg, hdrs): | 449 def http_error_default(self, req, fp, code, msg, hdrs): |
448 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) |
449 | 451 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 except Exception, ex: | 581 except Exception, ex: |
580 logging.error('The build for %s failed:', repo) | 582 logging.error('The build for %s failed:', repo) |
581 logging.exception(ex) | 583 logging.exception(ex) |
582 | 584 |
583 file = open(nightlyConfigFile, 'wb') | 585 file = open(nightlyConfigFile, 'wb') |
584 nightlyConfig.write(file) | 586 nightlyConfig.write(file) |
585 | 587 |
586 | 588 |
587 if __name__ == '__main__': | 589 if __name__ == '__main__': |
588 main() | 590 main() |
LEFT | RIGHT |