| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Tasks definition. | 6 """Tasks definition. |
| 7 | 7 |
| 8 Each user request creates a new TaskRequest. The TaskRequest instance saves the | 8 Each user request creates a new TaskRequest. The TaskRequest instance saves the |
| 9 metadata of the request, e.g. who requested it, when why, etc. It links to the | 9 metadata of the request, e.g. who requested it, when why, etc. It links to the |
| 10 actual data of the request in a TaskProperties. The TaskProperties represents | 10 actual data of the request in a TaskProperties. The TaskProperties represents |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 This is used for: | 652 This is used for: |
| 653 * Read access: ability to read the task info and logs. | 653 * Read access: ability to read the task info and logs. |
| 654 * Write access: ability to cancel the task. | 654 * Write access: ability to cancel the task. |
| 655 | 655 |
| 656 Warning: This function looks at the current Authentication context. | 656 Warning: This function looks at the current Authentication context. |
| 657 """ | 657 """ |
| 658 return ( | 658 return ( |
| 659 acl.is_privileged_user() or | 659 acl.is_privileged_user() or |
| 660 self.authenticated == auth.get_current_identity()) | 660 self.authenticated == auth.get_current_identity()) |
| 661 | 661 |
| 662 def to_dict(self): | 662 def to_dict(self, exclude=None): |
| 663 """Converts properties_hash to hex so it is json serializable.""" | 663 """Converts properties_hash to hex so it is json serializable.""" |
| 664 # to_dict() doesn't recurse correctly into ndb.LocalStructuredProperty! | 664 # to_dict() doesn't recurse correctly into ndb.LocalStructuredProperty! |
| 665 out = super(TaskRequest, self).to_dict( | 665 exclude = (exclude or [])[:] |
| 666 exclude=['pubsub_auth_token', 'properties', 'service_account_token']) | 666 exclude.extend(['pubsub_auth_token', 'properties', 'service_account_token']) |
| 667 out = super(TaskRequest, self).to_dict(exclude=exclude) |
| 667 out['properties'] = self.properties.to_dict() | 668 out['properties'] = self.properties.to_dict() |
| 668 properties_hash = out['properties_hash'] | 669 properties_hash = out['properties_hash'] |
| 669 out['properties_hash'] = ( | 670 out['properties_hash'] = ( |
| 670 properties_hash.encode('hex') if properties_hash else None) | 671 properties_hash.encode('hex') if properties_hash else None) |
| 671 return out | 672 return out |
| 672 | 673 |
| 673 def _pre_put_hook(self): | 674 def _pre_put_hook(self): |
| 674 """Adds automatic tags.""" | 675 """Adds automatic tags.""" |
| 675 super(TaskRequest, self)._pre_put_hook() | 676 super(TaskRequest, self)._pre_put_hook() |
| 676 self.properties._pre_put_hook() | 677 self.properties._pre_put_hook() |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 init_new_request(request, allow_high_priority, original_secret_bytes) | 943 init_new_request(request, allow_high_priority, original_secret_bytes) |
| 943 return request | 944 return request |
| 944 | 945 |
| 945 | 946 |
| 946 def validate_priority(priority): | 947 def validate_priority(priority): |
| 947 """Throws ValueError if priority is not a valid value.""" | 948 """Throws ValueError if priority is not a valid value.""" |
| 948 if 0 > priority or MAXIMUM_PRIORITY < priority: | 949 if 0 > priority or MAXIMUM_PRIORITY < priority: |
| 949 raise datastore_errors.BadValueError( | 950 raise datastore_errors.BadValueError( |
| 950 'priority (%d) must be between 0 and %d (inclusive)' % | 951 'priority (%d) must be between 0 and %d (inclusive)' % |
| 951 (priority, MAXIMUM_PRIORITY)) | 952 (priority, MAXIMUM_PRIORITY)) |
| OLD | NEW |