(self, filePath)
| 363 | return None |
| 364 | |
| 365 | def get_upload_info(self, filePath): |
| 366 | _, filename = split(filePath) |
| 367 | _, fileExtension = splitext(filename) |
| 368 | design_id = uuid.uuid4().hex |
| 369 | s3_key = design_id + fileExtension |
| 370 | |
| 371 | #only registered users can upload files to the cloud |
| 372 | if current_user and not current_user.is_anonymous: |
| 373 | try: |
| 374 | #Get credentials to upload the file |
| 375 | r = requests.get( "%s/designs/upload/params?key=%s" % (self.apiHost, s3_key), auth=self.hmacAuth ) |
| 376 | data = r.json() |
| 377 | except: |
| 378 | data = None |
| 379 | |
| 380 | if data and 'url' in data and 'post_data' in data: |
| 381 | publicKey = current_user.publicKey |
| 382 | privateKey = current_user.privateKey |
| 383 | |
| 384 | request = json.dumps({ |
| 385 | 'design_id': design_id, |
| 386 | 's3_key': s3_key, |
| 387 | 'filename': filename |
| 388 | }) |
| 389 | |
| 390 | hashed = hmac.new(privateKey, request, sha256) |
| 391 | signature = binascii.b2a_base64(hashed.digest())[:-1] |
| 392 | |
| 393 | redirect_url = "%s/design/uploaded?public_key=%s&req=%s&sig=%s" % ( |
| 394 | self.apiHost.replace('api', 'cloud'), |
| 395 | publicKey, |
| 396 | quote_plus(request), |
| 397 | quote_plus(signature)) |
| 398 | |
| 399 | #url, post parameters, redirect Url |
| 400 | return { |
| 401 | 'url': data['url'], |
| 402 | 'params': data['post_data'], |
| 403 | 'redirect': redirect_url |
| 404 | } |
| 405 | |
| 406 | else: |
| 407 | return { |
| 408 | 'error': 'invalid_data', |
| 409 | } |
| 410 | |
| 411 | else: |
| 412 | return { |
| 413 | 'error': 'no_user', |
| 414 | } |
| 415 | |
| 416 | def get_private_key(self, email, password): |
| 417 |
no test coverage detected