Show More
@@ -5,6 +5,11 b' from boards.utils import get_file_mimety' | |||||
5 | from django.db import transaction |
|
5 | from django.db import transaction | |
6 | from boards.models import KeyPair, GlobalId, Signature, Post, Tag |
|
6 | from boards.models import KeyPair, GlobalId, Signature, Post, Tag | |
7 |
|
7 | |||
|
8 | EXCEPTION_NODE = 'Sync node returned an error: {}' | |||
|
9 | EXCEPTION_OP = 'Load the OP first' | |||
|
10 | EXCEPTION_DOWNLOAD = 'File was not downloaded' | |||
|
11 | EXCEPTION_HASH = 'File hash does not match attachment hash' | |||
|
12 | EXCEPTION_SIGNATURE = 'Invalid model signature for {}' | |||
8 | ENCODING_UNICODE = 'unicode' |
|
13 | ENCODING_UNICODE = 'unicode' | |
9 |
|
14 | |||
10 | TAG_MODEL = 'model' |
|
15 | TAG_MODEL = 'model' | |
@@ -176,7 +181,7 b' class SyncManager:' | |||||
176 | if exists: |
|
181 | if exists: | |
177 | opening_post = Post.objects.get(global_id=op_global_id) |
|
182 | opening_post = Post.objects.get(global_id=op_global_id) | |
178 | else: |
|
183 | else: | |
179 |
raise SyncException( |
|
184 | raise SyncException(EXCEPTION_OP) | |
180 | else: |
|
185 | else: | |
181 | opening_post = None |
|
186 | opening_post = None | |
182 | tag_tags = tag_content.find(TAG_TAGS) |
|
187 | tag_tags = tag_content.find(TAG_TAGS) | |
@@ -197,11 +202,11 b' class SyncManager:' | |||||
197 | url = tag_ref.get(ATTR_URL) |
|
202 | url = tag_ref.get(ATTR_URL) | |
198 | attached_file = download(hostname + url) |
|
203 | attached_file = download(hostname + url) | |
199 | if attached_file is None: |
|
204 | if attached_file is None: | |
200 |
raise SyncException( |
|
205 | raise SyncException(EXCEPTION_DOWNLOAD) | |
201 |
|
206 | |||
202 | hash = get_file_hash(attached_file) |
|
207 | hash = get_file_hash(attached_file) | |
203 | if hash != attachment.text: |
|
208 | if hash != attachment.text: | |
204 |
raise SyncException( |
|
209 | raise SyncException(EXCEPTION_HASH) | |
205 |
|
210 | |||
206 | files.append(attached_file) |
|
211 | files.append(attached_file) | |
207 |
|
212 | |||
@@ -210,8 +215,7 b' class SyncManager:' | |||||
210 | opening_post=opening_post, tags=tags, |
|
215 | opening_post=opening_post, tags=tags, | |
211 | global_id=global_id, files=files) |
|
216 | global_id=global_id, files=files) | |
212 | else: |
|
217 | else: | |
213 | raise SyncException('Sync node returned an error: {}'.format( |
|
218 | raise SyncException(EXCEPTION_NODE.format(tag_status.text)) | |
214 | tag_status.text)) |
|
|||
215 |
|
219 | |||
216 | @staticmethod |
|
220 | @staticmethod | |
217 | def generate_response_pull(): |
|
221 | def generate_response_pull(): | |
@@ -247,7 +251,7 b' class SyncManager:' | |||||
247 | signature=signature_value) |
|
251 | signature=signature_value) | |
248 |
|
252 | |||
249 | if not KeyPair.objects.verify(signature, content_str): |
|
253 | if not KeyPair.objects.verify(signature, content_str): | |
250 |
raise SyncException( |
|
254 | raise SyncException(EXCEPTION_SIGNATURE.format(content_str)) | |
251 |
|
255 | |||
252 | signatures.append(signature) |
|
256 | signatures.append(signature) | |
253 |
|
257 |
General Comments 0
You need to be logged in to leave comments.
Login now