Skip to content

Commit

Permalink
fix(project): fixes project update with vpn state (#246)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pallabpain authored Dec 15, 2023
1 parent 06bbf7f commit 82709f6
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions riocli/project/features/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 82709f6

Please sign in to comment.