From 0daac833cbbd6a3083b3e34d8957f99203296f7e Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Thu, 14 Dec 2023 16:59:21 +0900 Subject: [PATCH] fix(project): fixes project update with vpn state Recently, the project update API was updated to reflect the state as sent in the request payload. The vpn command in project had the older implementation and we forgot to update it when the project update API was changed. This issue can lead to serious loss of project info if not fixed in time. This commit corrects that by first fetching the project and updating it with the new values before passing it as the payload for update. --- riocli/project/features/vpn.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/riocli/project/features/vpn.py b/riocli/project/features/vpn.py index a7ffb439..f4b239a5 100644 --- a/riocli/project/features/vpn.py +++ b/riocli/project/features/vpn.py @@ -52,27 +52,23 @@ def vpn( """ client = new_v2_client(with_project=False) - subnets = (subnets or []) if enable else [] + try: + project = client.get_project(project_guid) + except Exception as e: + spinner.text = click.style("Failed: {}".format(e), fg=Colors.RED) + spinner.red.fail(Symbols.ERROR) + raise SystemExit(1) from e - body = { - "metadata": { - "projectGUID": project_guid - }, - "spec": { - "features": { - "vpn": { - "enabled": enable, - "subnets": subnets - } - } - } + project["spec"]["features"]["vpn"] = { + "enabled": enable, + "subnets": (subnets or []) if enable else [] } state = 'Enabling' if enable else 'Disabling' spinner.text = click.style('{} VPN...'.format(state), fg=Colors.YELLOW) try: - client.update_project(project_guid, body) + client.update_project(project_guid, project) spinner.text = click.style('Done', fg=Colors.GREEN) spinner.green.ok(Symbols.SUCCESS) except Exception as e: