def update_host_tag_group(params): """Update a host tag group""" # TODO: ident verification mechanism with ParamDict replacement body = params['body'] ident = params['name'] if is_builtin(ident): return problem( status=405, title="Built-in cannot be modified", detail=f"The built-in host tag group {ident} cannot be modified", ) updated_details = {x: body[x] for x in body if x != "repair"} tag_group = _retrieve_group(ident) group_details = tag_group.get_dict_format() group_details.update(updated_details) try: edit_tag_group(ident, TagGroup(group_details), allow_repair=body['repair']) except RepairError: return problem( 401, f'Updating this host tag group "{ident}" requires additional authorization', 'The host tag group you intend to edit is used by other instances. You must authorize Checkmk ' 'to update the relevant instances using the repair parameter') updated_tag_group = _retrieve_group(ident) return _serve_host_tag_group(updated_tag_group.get_dict_format())
def delete_host_tag_group(params): """Delete a host tag group""" ident = params['name'] if is_builtin(ident): return problem( status=405, title="Built-in cannot be delete", detail=f"The built-in host tag group {ident} cannot be deleted", ) affected = change_host_tags_in_folders(OperationRemoveTagGroup(ident), TagCleanupMode.CHECK, watolib.Folder.root_folder()) if any(affected): if not params["repair"]: return problem( 401, f'Deleting this host tag group "{ident}" requires additional authorization', 'The host tag group you intend to delete is used by other instances. You must authorize Checkmk ' 'to update the relevant instances using the repair parameter') watolib.host_attributes.undeclare_host_tag_attribute(ident) _ = change_host_tags_in_folders(OperationRemoveTagGroup(ident), TagCleanupMode("delete"), watolib.Folder.root_folder()) tag_config = load_tag_config() tag_config.remove_tag_group(ident) update_tag_config(tag_config) return Response(status=204)
def update_host_tag_group(params): """Update a host tag group""" # TODO: ident verification mechanism with ParamDict replacement body = params["body"] ident = params["name"] if is_builtin(ident): return problem( status=405, title="Built-in cannot be modified", detail=f"The built-in host tag group {ident} cannot be modified", ) updated_details = {x: body[x] for x in body if x != "repair"} tag_group = _retrieve_group(ident) group_details = tag_group.get_dict_format() # This is an incremental update of the TaggroupSpec group_details.update(updated_details) # type: ignore[typeddict-item] try: edit_tag_group(ident, TagGroup.from_config(group_details), allow_repair=body["repair"]) except RepairError: return problem( 401, f'Updating this host tag group "{ident}" requires additional authorization', "The host tag group you intend to edit is used by other instances. You must authorize Checkmk " "to update the relevant instances using the repair parameter", ) updated_tag_group = _retrieve_group(ident) return _serve_host_tag_group(updated_tag_group.get_dict_format())