Returns export data, for usage on API handlers or queue consumers. No permissions are cheked here, make sure to use in conjunction with the appropriate permissions handlers. :param export: :param format: :param return_type: :return:
(export: Export, format: str = "JSON", return_type: str = "url")
| 8 | |
| 9 | |
| 10 | def export_view_core(export: Export, format: str = "JSON", return_type: str = "url") -> str: |
| 11 | """ |
| 12 | Returns export data, for usage on API handlers |
| 13 | or queue consumers. No permissions are cheked here, make sure to use |
| 14 | in conjunction with the appropriate permissions handlers. |
| 15 | :param export: |
| 16 | :param format: |
| 17 | :param return_type: |
| 18 | :return: |
| 19 | """ |
| 20 | |
| 21 | # TODO format string validation? |
| 22 | |
| 23 | blob_name = None |
| 24 | if export.kind == "Annotations": |
| 25 | |
| 26 | if format == "JSON": |
| 27 | blob_name = export.json_blob_name |
| 28 | |
| 29 | if format == "YAML": |
| 30 | blob_name = export.yaml_blob_name |
| 31 | |
| 32 | if export.kind == "TF Records": |
| 33 | blob_name = export.tf_records_blob_name |
| 34 | |
| 35 | if blob_name is None: |
| 36 | logger.error(f'Invalid export kind or format: Kind: {export.kind}, format: {format}') |
| 37 | return |
| 38 | expiration_offset = 60 * 5 # seconds |
| 39 | |
| 40 | # TODO not clear what we want this flag to be... |
| 41 | # I think it should be seperate from format maybe? |
| 42 | # ie a new attribute like "return_kind" or something? |
| 43 | if return_type in ['data', 'bytes']: |
| 44 | # Caution this is in Bytes |
| 45 | blob_data = data_tools.get_string_from_blob(blob_name) |
| 46 | |
| 47 | if return_type == 'bytes': |
| 48 | return blob_data |
| 49 | |
| 50 | # We don't seem to need decode with json.loads() |
| 51 | # blob_data = blob_data.decode() |
| 52 | |
| 53 | json_data = json.loads(blob_data) |
| 54 | |
| 55 | return json_data |
| 56 | |
| 57 | # Default case URL |
| 58 | url = data_tools.build_secure_url( |
| 59 | blob_name, |
| 60 | expiration_offset, |
| 61 | bucket = "ml") |
| 62 | return url |
no test coverage detected