From f31f3f3f2ebf9e3429ce515c3c9b80800b79b444 Mon Sep 17 00:00:00 2001 From: Paul Farault Date: Wed, 2 Jul 2025 14:57:00 +0200 Subject: [PATCH] feat: remove tdp vars edit command --- tdp/cli/commands/vars/__init__.py | 2 - tdp/cli/commands/vars/edit.py | 148 ------------------------------ 2 files changed, 150 deletions(-) delete mode 100644 tdp/cli/commands/vars/edit.py diff --git a/tdp/cli/commands/vars/__init__.py b/tdp/cli/commands/vars/__init__.py index 69078cc1..9e959994 100644 --- a/tdp/cli/commands/vars/__init__.py +++ b/tdp/cli/commands/vars/__init__.py @@ -3,7 +3,6 @@ import click -from tdp.cli.commands.vars.edit import edit from tdp.cli.commands.vars.update import update from tdp.cli.commands.vars.validate import validate @@ -14,6 +13,5 @@ def vars(): pass -vars.add_command(edit) vars.add_command(validate) vars.add_command(update) diff --git a/tdp/cli/commands/vars/edit.py b/tdp/cli/commands/vars/edit.py deleted file mode 100644 index d1f1f65f..00000000 --- a/tdp/cli/commands/vars/edit.py +++ /dev/null @@ -1,148 +0,0 @@ -# Copyright 2022 TOSIT.IO -# SPDX-License-Identifier: Apache-2.0 - -import logging -from pathlib import Path -from typing import Optional - -import click -from sqlalchemy import Engine - -from tdp.cli.params import ( - collections_option, - database_dsn_option, - validate_option, - vars_option, -) -from tdp.core.collections import Collections -from tdp.core.constants import YML_EXTENSION -from tdp.core.entities.entity_name import ( - ServiceComponentName, - parse_entity_name, -) -from tdp.core.repository.repository import EmptyCommit -from tdp.core.variables import ClusterVariables -from tdp.core.variables.schema.exceptions import InvalidSchemaError -from tdp.dao import Dao - -logger = logging.getLogger(__name__) - - -@click.command() -@click.argument("service_name", nargs=1, required=True) -@click.argument("service_component_parameter", nargs=1, required=False) -@click.option( - "--commit_message", - "-c", - type=str, - default="updated from `tdp vars edit` command", - help="Validation message for the service repository.", -) -@collections_option -@database_dsn_option -@validate_option -@vars_option -def edit( - commit_message: str, - collections: Collections, - db_engine: Engine, - validate: bool, - vars: Path, - service_name: str, - service_component_parameter: Optional[str] = None, -): - """Edit a variables file. - - SERVICE_NAME: Name of the service to edit variables for. - SERVICE_COMPONENT_PARAMETER: Name or path of the component to edit variables for. If not specified, edit the service variables file. - - \b - Examples: - tdp vars edit hdfs - tdp vars edit hdfs datanode --commit_message "updated datanode variables" - tdp vars edit hdfs hdfs_datanode.yml - """ - cluster_variables = ClusterVariables.get_cluster_variables( - collections, vars, validate=validate - ) - - # Check if service exists - if service_name not in cluster_variables: - raise click.ClickException(f"Error unknown service '{service_name}'") - - service_variables = cluster_variables[service_name] - repo = service_variables.repository - - # Check if service is clean - if not service_variables.clean: - raise click.ClickException( - f"Error service '{service_name}' is not clean. Commit or stash your changes before editing variables." - ) - - # Get the variable file to edit - base_path = vars / service_name - if service_component_parameter is None: - # tdp vars edit service - variables_file = base_path / (service_name + YML_EXTENSION) - elif service_component_parameter.endswith(YML_EXTENSION): - # tdp vars edit service service.yml OR tdp vars edit service service_component.yml - variables_file = base_path / service_component_parameter - else: - # tdp vars edit service component - variables_file = base_path / ( - service_name + "_" + service_component_parameter + YML_EXTENSION - ) - - # Check if component exists - entity_name = parse_entity_name(variables_file.stem) - if isinstance(entity_name, ServiceComponentName): - if entity_name not in collections.entities[service_name]: - raise click.ClickException( - f"Error unknown component '{entity_name.component}' for service '{entity_name.service}'" - ) - - logger.debug(f"Editing {variables_file.name} for service {service_name}") - - # Loop until variables file format has no errors or user aborts editing file - while True: - click.edit( - filename=str(variables_file), - ) - - # Pause until user press any key - value: str = click.prompt( - "Press any key when done editing ('q' to cancel)", - type=str, - prompt_suffix="", - default="continue", - show_default=False, - ) - if value.lower() == "q": - repo.restore_file(str(variables_file)) - raise click.ClickException("Aborted changes") - - # Check schema - try: - service_variables.validate() - except InvalidSchemaError: - click.echo(f"Variables does not match '{service_name}' schema") - continue - - # Commit - try: - with repo.validate(commit_message): - repo.add_for_validation([str(variables_file)]) - except EmptyCommit: - raise click.ClickException("Nothing changed") - - click.echo(f"{variables_file.name} successfully updated") - - # Generate stale component list and save it to the database - with Dao(db_engine) as dao: - stale_status_logs = dao.get_cluster_status().generate_stale_sch_logs( - cluster_variables=cluster_variables, collections=collections - ) - dao.session.add_all(stale_status_logs) - dao.session.commit() - - break