Import plugins from environment variable Will not import if plugin already exists
(environment_variable_name="IQENGINE_PLUGINS")
| 5 | |
| 6 | |
| 7 | async def import_plugins_from_env(environment_variable_name="IQENGINE_PLUGINS"): |
| 8 | """ |
| 9 | Import plugins from environment variable |
| 10 | Will not import if plugin already exists |
| 11 | """ |
| 12 | try: |
| 13 | plugins_json = os.getenv(environment_variable_name, None) |
| 14 | if not plugins_json: |
| 15 | return None |
| 16 | plugins = json.loads(plugins_json) |
| 17 | |
| 18 | client = plugin_repo.collection() |
| 19 | for plugin in plugins: |
| 20 | if await client.find_one({"name": plugin["name"]}, {"_id": 1}): |
| 21 | continue |
| 22 | await client.insert_one(plugin) |
| 23 | except Exception as e: |
| 24 | # throw a custom plugin failed to load exception |
| 25 | raise Exception( |
| 26 | f"Failed to load plugins from environment variable {environment_variable_name}", |
| 27 | e, |
| 28 | ) |
no outgoing calls
no test coverage detected