OLD | NEW |
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
2 # | 2 # |
3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
9 # lowing conditions: | 9 # lowing conditions: |
10 # | 10 # |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 param = str(ed['param']) | 67 param = str(ed['param']) |
68 if n not in events_dict: | 68 if n not in events_dict: |
69 events_dict[n] = {} | 69 events_dict[n] = {} |
70 events_dict[n][param] = v | 70 events_dict[n][param] = v |
71 for n in events_dict: | 71 for n in events_dict: |
72 self.events.append(Event(events_dict[n])) | 72 self.events.append(Event(events_dict[n])) |
73 | 73 |
74 def verify(self, secret_key): | 74 def verify(self, secret_key): |
75 """ | 75 """ |
76 Verifies the authenticity of a notification message. | 76 Verifies the authenticity of a notification message. |
| 77 |
| 78 TODO: This is doing a form of authentication and |
| 79 this functionality should really be merged |
| 80 with the pluggable authentication mechanism |
| 81 at some point. |
77 """ | 82 """ |
78 verification_input = NotificationMessage.SERVICE_NAME + NotificationMess
age.OPERATION_NAME + self.timestamp | 83 verification_input = NotificationMessage.SERVICE_NAME |
79 signature_calc = self._auth_handler.sign_string(verification_input) | 84 verification_input += NotificationMessage.OPERATION_NAME |
| 85 verification_input += self.timestamp |
| 86 h = hmac.new(key=secret_key, digestmod=sha) |
| 87 h.update(verification_input) |
| 88 signature_calc = base64.b64encode(h.digest()) |
80 return self.signature == signature_calc | 89 return self.signature == signature_calc |
81 | 90 |
82 class Event: | 91 class Event: |
83 def __init__(self, d): | 92 def __init__(self, d): |
84 self.event_type = d['EventType'] | 93 self.event_type = d['EventType'] |
85 self.event_time_str = d['EventTime'] | 94 self.event_time_str = d['EventTime'] |
86 self.hit_type = d['HITTypeId'] | 95 self.hit_type = d['HITTypeId'] |
87 self.hit_id = d['HITId'] | 96 self.hit_id = d['HITId'] |
88 if 'AssignmentId' in d: # Not present in all event types | 97 if 'AssignmentId' in d: # Not present in all event types |
89 self.assignment_id = d['AssignmentId'] | 98 self.assignment_id = d['AssignmentId'] |
90 | 99 |
91 #TODO: build self.event_time datetime from string self.event_time_str | 100 #TODO: build self.event_time datetime from string self.event_time_str |
92 | 101 |
93 def __repr__(self): | 102 def __repr__(self): |
94 return "<boto.mturk.notification.Event: %s for HIT # %s>" % (self.event_
type, self.hit_id) | 103 return "<boto.mturk.notification.Event: %s for HIT # %s>" % (self.event_
type, self.hit_id) |
OLD | NEW |