Imports datasources from environment variable Parameters ---------- environment_variable_name : str The name of the environment variable to load the datasources from Returns ------- None
(
environment_variable_name="IQENGINE_CONNECTION_INFO",
)
| 7 | |
| 8 | |
| 9 | async def import_datasources_from_env( |
| 10 | environment_variable_name="IQENGINE_CONNECTION_INFO", |
| 11 | ): |
| 12 | """ |
| 13 | Imports datasources from environment variable |
| 14 | |
| 15 | Parameters |
| 16 | ---------- |
| 17 | environment_variable_name : str |
| 18 | The name of the environment variable to load the datasources from |
| 19 | |
| 20 | Returns |
| 21 | ------- |
| 22 | None |
| 23 | """ |
| 24 | connection_info = os.getenv(environment_variable_name, None) |
| 25 | if not connection_info: |
| 26 | return None |
| 27 | connections = json.loads(connection_info)["settings"] |
| 28 | for connection in connections: |
| 29 | try: |
| 30 | if await datasource_repo.datasource_exists( |
| 31 | connection["accountName"], connection["containerName"] |
| 32 | ): |
| 33 | continue |
| 34 | datasource = DataSource( |
| 35 | account=connection["accountName"], |
| 36 | container=connection["containerName"], |
| 37 | sasToken=connection["sasToken"], |
| 38 | accountKey=connection["accountKey"] if "accountKey" in connection else None, |
| 39 | name=connection["name"], |
| 40 | description=connection["description"] |
| 41 | if "description" in connection |
| 42 | else None, |
| 43 | imageURL=connection["imageURL"] if "imageURL" in connection else None, |
| 44 | type="api", |
| 45 | public=connection["public"] if "public" in connection else True, |
| 46 | owners=connection["owners"] if "owners" in connection else ["IQEngine-Admin"], |
| 47 | readers=connection["readers"] if "readers" in connection else [], |
| 48 | ) |
| 49 | await datasource_repo.create(datasource=datasource, user=None) |
| 50 | asyncio.create_task( |
| 51 | datasource_repo.sync( |
| 52 | connection["accountName"], connection["containerName"] |
| 53 | ) |
| 54 | ) |
| 55 | except Exception as e: |
| 56 | print(f"Failed to import datasource {connection['name']}", e) |
| 57 | continue |
no test coverage detected