(self, opts)
| 477 | @with_connection |
| 478 | @with_s3_exception_handler |
| 479 | def __send_export(self, opts): |
| 480 | spec_list = [{'project_string_id': dict}] |
| 481 | log = regular_log.default() |
| 482 | log, input = regular_input.input_check_many(untrusted_input = self.config_data, |
| 483 | spec_list = spec_list, |
| 484 | log = log) |
| 485 | if len(log["error"].keys()) >= 1: |
| 486 | return {'log': log} |
| 487 | spec_list = [ |
| 488 | {'path': str}, |
| 489 | {"format": { |
| 490 | 'default': 'JSON', |
| 491 | 'kind': str, |
| 492 | 'valid_values_list': ['JSON', 'YAML'] |
| 493 | }}, |
| 494 | {'export_id': str}, |
| 495 | {'bucket_name': str}, |
| 496 | |
| 497 | ] |
| 498 | log = regular_log.default() |
| 499 | log, input = regular_input.input_check_many(untrusted_input = opts, |
| 500 | spec_list = spec_list, |
| 501 | log = log, |
| 502 | string_len_not_zero = False) |
| 503 | if len(log["error"].keys()) >= 1: |
| 504 | return {'log': log} |
| 505 | if not opts['path'].endswith('/') and opts['path'] != '': |
| 506 | log['error']['path'] = 'Path on bucket must be a folder, not a filename.' |
| 507 | return log |
| 508 | |
| 509 | with sessionMaker.session_scope() as session: |
| 510 | project = Project.get_by_string_id(session, self.config_data['project_string_id']) |
| 511 | member = session.query(Member).filter(Member.user_id == opts['event_data']['request_user']).first() |
| 512 | export = session.query(Export).filter(Export.id == opts['export_id']).first() |
| 513 | # Check perms and export status. |
| 514 | export_check_result = check_export_permissions_and_status(export, |
| 515 | self.config_data['project_string_id'], |
| 516 | session) |
| 517 | if regular_log.log_has_error(export_check_result): |
| 518 | return export_check_result |
| 519 | |
| 520 | result = export_view_core( |
| 521 | export = export, |
| 522 | format = opts['format'], |
| 523 | return_type = 'bytes') |
| 524 | result = bytes(result, 'utf-8') |
| 525 | filename = generate_file_name_from_export(export, session) |
| 526 | if opts['path'] != '': |
| 527 | key = f"{opts['path']}{filename}.{opts['format'].lower()}" |
| 528 | else: |
| 529 | key = f"{filename}.{opts['format'].lower()}" |
| 530 | |
| 531 | file = io.BytesIO(result) |
| 532 | self.connection_client.upload_fileobj(file, opts['bucket_name'], key) |
| 533 | log = regular_log.default() |
| 534 | log['opts'] = opts |
| 535 | Event.new( |
| 536 | session = session, |
no test coverage detected