diff --git a/docs/pages/usage/workspace_editor.md b/docs/pages/usage/workspace_editor.md index 803ea0c0..3674c415 100644 --- a/docs/pages/usage/workspace_editor.md +++ b/docs/pages/usage/workspace_editor.md @@ -113,6 +113,7 @@ There are two mechanisms to implement `Update` in azure-cli. There's three modes to control the generation of `Update` commands while add the resources. +- Default: If inherent from existing command models in aaz, it will follow the method used in the existing update command model, else it will follow the _Generic(Get&Put) First_ mode. - Generic(Get&Put) First: If the resource supports `Get` and `Put` methods, generate the _Generic Update_, else if it supports `Patch` method, it generate the _Patch Update_. - Patch First: If the resource supports `Patch` method, it generate the _Patch Update_, else if it supports `Get` and `Put` methods. - No update command: Never generate `Update` commands for the resource. diff --git a/src/aaz_dev/command/controller/workspace_cfg_editor.py b/src/aaz_dev/command/controller/workspace_cfg_editor.py index 274e691f..0b5f79ee 100644 --- a/src/aaz_dev/command/controller/workspace_cfg_editor.py +++ b/src/aaz_dev/command/controller/workspace_cfg_editor.py @@ -897,7 +897,7 @@ def inherit_modification(self, ref_cfg: CfgReader): update_cmd_info = self.get_update_cmd(resource_id) if not update_cmd_info: continue - update_cmd_names, update_cmd, update_by = update_cmd_info + _, update_cmd, update_by = update_cmd_info if update_by != "GenericOnly": continue @@ -1079,6 +1079,7 @@ def build_identity_subresource(self, resource_id, temp_generic_update_cmd=None): self._add_command(*cg_names, sub_command.name, command=sub_command) self.reformat() + return cg_names def build_subresource_commands_by_arg_var(self, resource_id, arg_var, cg_names, ref_args_options=None): """ diff --git a/src/aaz_dev/command/controller/workspace_manager.py b/src/aaz_dev/command/controller/workspace_manager.py index 841c75a4..fd5f955f 100644 --- a/src/aaz_dev/command/controller/workspace_manager.py +++ b/src/aaz_dev/command/controller/workspace_manager.py @@ -660,8 +660,8 @@ def _add_new_resources(self, command_generator, resources, resource_options): cfg_editors = [] aaz_ref = {} for resource, options in zip(resources, resource_options): - cfg_editor = self._build_draft_cfg_editor(command_generator, resource, options) # inherit modification from cfg in aaz + aaz_cfg_reader = None aaz_version = options.get('aaz_version', None) if aaz_version: try: @@ -669,6 +669,13 @@ def _add_new_resources(self, command_generator, resources, resource_options): self.ws.plane, resource.id, aaz_version) except ValueError as err: raise exceptions.InvalidAPIUsage(message=str(err)) from err + # inherit update_by from existing cfg in aaz + if "update_by" not in options: + aaz_update_cmd_info = aaz_cfg_reader.get_update_cmd(resource.id) + if aaz_update_cmd_info: + options["update_by"] = aaz_update_cmd_info[2] + cfg_editor = self._build_draft_cfg_editor(command_generator, resource, options) + if aaz_cfg_reader: cfg_editor.inherit_modification(aaz_cfg_reader) for cmd_names, _ in cfg_editor.iter_commands(): aaz_ref[' '.join(cmd_names)] = aaz_version @@ -676,7 +683,7 @@ def _add_new_resources(self, command_generator, resources, resource_options): update_cmd_info = cfg_editor.get_update_cmd(resource.id) temp_generic_update_cmd = None if update_cmd_info and options.get('update_by', None) == "PatchOnly": - temp_cfg_editor = self._build_draft_cfg_editor(command_generator, resource, {"update_by": "GenericOnly"}) + temp_cfg_editor = self._build_draft_cfg_editor(command_generator, resource, {"update_by": "GenericOnly", "methods": ('get', 'put')}) temp_update_cmd_info = temp_cfg_editor.get_update_cmd(resource.id) if temp_update_cmd_info: _, temp_generic_update_cmd, _ = temp_update_cmd_info @@ -819,7 +826,7 @@ def _reload_resources(self, command_generator, reload_resource_map): new_cfg_editor.inherit_modification(cfg_editor) temp_generic_update_cmd = None if update_cmd_info and update_by == "PatchOnly": - temp_cfg_editor = self._build_draft_cfg_editor(command_generator, resource, {"update_by": "GenericOnly"}) + temp_cfg_editor = self._build_draft_cfg_editor(command_generator, resource, {"update_by": "GenericOnly", "methods": ('get', 'put')}) temp_update_cmd_info = temp_cfg_editor.get_update_cmd(resource_id) if temp_update_cmd_info: _, temp_generic_update_cmd, _ = temp_update_cmd_info diff --git a/src/web/src/views/workspace/WSEditorSwaggerPicker.tsx b/src/web/src/views/workspace/WSEditorSwaggerPicker.tsx index b04413de..a2e25e1d 100644 --- a/src/web/src/views/workspace/WSEditorSwaggerPicker.tsx +++ b/src/web/src/views/workspace/WSEditorSwaggerPicker.tsx @@ -93,7 +93,7 @@ const MiddlePadding2 = styled(Box)(() => ({ height: '8vh' })); -const UpdateOptions = ["Generic(Get&Put) First", "Patch First", "No update command"]; +const UpdateOptions = ["Default", "Generic(Get&Put) First", "Patch First", "No update command"]; class WSEditorSwaggerPicker extends React.Component { @@ -366,6 +366,24 @@ class WSEditorSwaggerPicker extends React.Component v.version === selectedVersion)?.operations; + if (operations) { + let hasGet = false; + let hasPut = false; + for (const opName in operations) { + if (operations[opName].toLowerCase() === "put") { + hasPut = true; + } else if (operations[opName].toLowerCase() === "get") { + hasGet = true; + } + } + if (hasGet && hasPut) { + res.options.update_by = "GenericOnly" + } + } + } else if (updateOption === UpdateOptions[2]) { // patch first const resource = resourceMap[resourceId]; const operations = resource.versions.find(v => v.version === selectedVersion)?.operations; @@ -377,7 +395,7 @@ class WSEditorSwaggerPicker extends React.Component