|
| 1 | +from dataclasses import asdict |
| 2 | + |
| 3 | +from flask.typing import ResponseReturnValue |
| 4 | +from flask_apispec import MethodResource |
| 5 | + |
| 6 | +from api.apispec import FlaskApiSpecDecorators |
| 7 | +from api.plugins.app_group_lifecycle import ( |
| 8 | + get_app_group_lifecycle_plugin_app_config_properties, |
| 9 | + get_app_group_lifecycle_plugin_app_status_properties, |
| 10 | + get_app_group_lifecycle_plugin_group_config_properties, |
| 11 | + get_app_group_lifecycle_plugin_group_status_properties, |
| 12 | + get_app_group_lifecycle_plugins, |
| 13 | +) |
| 14 | +from api.views.schemas import ( |
| 15 | + AppGroupLifecyclePluginConfigPropertySchema, |
| 16 | + AppGroupLifecyclePluginMetadataSchema, |
| 17 | + AppGroupLifecyclePluginStatusPropertySchema, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +class AppGroupLifecyclePluginList(MethodResource): |
| 22 | + """Resource for listing available app group lifecycle plugins.""" |
| 23 | + |
| 24 | + @FlaskApiSpecDecorators.response_schema(AppGroupLifecyclePluginMetadataSchema) |
| 25 | + def get(self) -> ResponseReturnValue: |
| 26 | + """ |
| 27 | + Get a list of all available app group lifecycle plugins. |
| 28 | +
|
| 29 | + Returns: |
| 30 | + A list of plugin metadata objects. |
| 31 | + """ |
| 32 | + plugins = get_app_group_lifecycle_plugins() |
| 33 | + # Sort by display name alphabetically (ascending) |
| 34 | + plugins = sorted(plugins, key=lambda p: p.display_name.lower()) |
| 35 | + return [asdict(plugin) for plugin in plugins], 200 |
| 36 | + |
| 37 | + |
| 38 | +class AppGroupLifecyclePluginAppConfigProperties(MethodResource): |
| 39 | + """Resource for getting app-level configuration properties for a specific plugin.""" |
| 40 | + |
| 41 | + @FlaskApiSpecDecorators.response_schema(AppGroupLifecyclePluginConfigPropertySchema) |
| 42 | + def get(self, plugin_id: str) -> ResponseReturnValue: |
| 43 | + """ |
| 44 | + Get app-level configuration properties for a specific plugin. |
| 45 | +
|
| 46 | + Args: |
| 47 | + plugin_id: The ID of the plugin |
| 48 | +
|
| 49 | + Returns: |
| 50 | + Dictionary mapping property names to property schemas |
| 51 | + """ |
| 52 | + # Verify the plugin is registered |
| 53 | + plugins = [plugin.id for plugin in get_app_group_lifecycle_plugins()] |
| 54 | + if plugin_id not in plugins: |
| 55 | + return {"error": f"Plugin '{plugin_id}' not found"}, 404 |
| 56 | + |
| 57 | + config_properties = get_app_group_lifecycle_plugin_app_config_properties(plugin_id) |
| 58 | + return {name: asdict(schema) for name, schema in config_properties.items()}, 200 |
| 59 | + |
| 60 | + |
| 61 | +class AppGroupLifecyclePluginGroupConfigProperties(MethodResource): |
| 62 | + """Resource for getting group-level configuration properties for a specific plugin.""" |
| 63 | + |
| 64 | + @FlaskApiSpecDecorators.response_schema(AppGroupLifecyclePluginConfigPropertySchema) |
| 65 | + def get(self, plugin_id: str) -> ResponseReturnValue: |
| 66 | + """ |
| 67 | + Get group-level configuration properties for a specific plugin. |
| 68 | +
|
| 69 | + Args: |
| 70 | + plugin_id: The ID of the plugin |
| 71 | +
|
| 72 | + Returns: |
| 73 | + Dictionary mapping property names to property schemas |
| 74 | + """ |
| 75 | + # Verify the plugin is registered |
| 76 | + plugins = [plugin.id for plugin in get_app_group_lifecycle_plugins()] |
| 77 | + if plugin_id not in plugins: |
| 78 | + return {"error": f"Plugin '{plugin_id}' not found"}, 404 |
| 79 | + |
| 80 | + config_properties = get_app_group_lifecycle_plugin_group_config_properties(plugin_id) |
| 81 | + return {name: asdict(schema) for name, schema in config_properties.items()}, 200 |
| 82 | + |
| 83 | + |
| 84 | +class AppGroupLifecyclePluginAppStatusProperties(MethodResource): |
| 85 | + """Resource for getting app-level status properties for a specific plugin.""" |
| 86 | + |
| 87 | + @FlaskApiSpecDecorators.response_schema(AppGroupLifecyclePluginStatusPropertySchema) |
| 88 | + def get(self, plugin_id: str) -> ResponseReturnValue: |
| 89 | + """ |
| 90 | + Get app-level status properties for a specific plugin. |
| 91 | +
|
| 92 | + Args: |
| 93 | + plugin_id: The ID of the plugin |
| 94 | +
|
| 95 | + Returns: |
| 96 | + Dictionary mapping property names to property schemas |
| 97 | + """ |
| 98 | + # Verify the plugin is registered |
| 99 | + plugins = [plugin.id for plugin in get_app_group_lifecycle_plugins()] |
| 100 | + if plugin_id not in plugins: |
| 101 | + return {"error": f"Plugin '{plugin_id}' not found"}, 404 |
| 102 | + |
| 103 | + status_properties = get_app_group_lifecycle_plugin_app_status_properties(plugin_id) |
| 104 | + return {name: asdict(schema) for name, schema in status_properties.items()}, 200 |
| 105 | + |
| 106 | + |
| 107 | +class AppGroupLifecyclePluginGroupStatusProperties(MethodResource): |
| 108 | + """Resource for getting group-level status properties for a specific plugin.""" |
| 109 | + |
| 110 | + @FlaskApiSpecDecorators.response_schema(AppGroupLifecyclePluginStatusPropertySchema) |
| 111 | + def get(self, plugin_id: str) -> ResponseReturnValue: |
| 112 | + """ |
| 113 | + Get group-level status properties for a specific plugin. |
| 114 | +
|
| 115 | + Args: |
| 116 | + plugin_id: The ID of the plugin |
| 117 | +
|
| 118 | + Returns: |
| 119 | + Dictionary mapping property names to property schemas |
| 120 | + """ |
| 121 | + # Verify the plugin is registered |
| 122 | + plugins = [plugin.id for plugin in get_app_group_lifecycle_plugins()] |
| 123 | + if plugin_id not in plugins: |
| 124 | + return {"error": f"Plugin '{plugin_id}' not found"}, 404 |
| 125 | + |
| 126 | + status_properties = get_app_group_lifecycle_plugin_group_status_properties(plugin_id) |
| 127 | + return {name: asdict(schema) for name, schema in status_properties.items()}, 200 |
0 commit comments