From c033e6ad88bea27296e64c4f6cc545c53dc79f87 Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Tue, 2 Apr 2024 15:12:24 +0900 Subject: [PATCH] feat: add metadata for init repsonse --- src/plugin/main.py | 20 ++++++++++++++++++-- src/plugin/manager/resource_manager.py | 10 ++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/plugin/main.py b/src/plugin/main.py index 8744de1..6dc5fac 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -22,7 +22,23 @@ def account_collector_init(params: dict) -> dict: } """ - return {"metadata": {}} + metadata = { + "options_schema": { + "type": "object", + "properties": { + "exclude_tenant_root_group": { + "title": "Exclude Tenant Root Group", + "type": "boolean", + "default": False, + }, + }, + } + } + + if options := params.get("options"): + pass + + return {"metadata": metadata} @app.route("AccountCollector.sync") @@ -59,7 +75,7 @@ def account_collector_sync(params: dict) -> dict: domain_id = params["domain_id"] results = [] - for account_collector_manager in AzureBaseManager.get_all_managers(options={}): + for account_collector_manager in AzureBaseManager.get_all_managers(options=options): ac_mgr = account_collector_manager() results.extend( ac_mgr.sync( diff --git a/src/plugin/manager/resource_manager.py b/src/plugin/manager/resource_manager.py index df63df3..d2d5da1 100644 --- a/src/plugin/manager/resource_manager.py +++ b/src/plugin/manager/resource_manager.py @@ -48,7 +48,9 @@ def sync( name = entity_info["display_name"] tenant_id = entity_info["tenant_id"] subscription_id = entity_info["name"] - location = self._create_location_from_entity_info(entity_info) + location = self._create_location_from_entity_info( + entity_info, options + ) result = { "name": name, @@ -69,11 +71,15 @@ def sync( return results @staticmethod - def _create_location_from_entity_info(entity_info: dict) -> List[dict]: + def _create_location_from_entity_info( + entity_info: dict, options: dict + ) -> List[dict]: location = [] parent_display_name_chain = entity_info.get("parent_display_name_chain", []) parent_name_chain = entity_info.get("parent_name_chain", []) for idx, name in enumerate(parent_display_name_chain): + if options.get("exclude_tenant_root_group") and idx == 0: + continue location.append( { "name": name,