Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(project): updates subnet when vpn is already enabled #324

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions riocli/project/features/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@click.option('--subnets', type=click.STRING, multiple=True, default=(),
help='Subnet ranges for the project. For example: 10.81.0.0/16')
@name_to_guid
@with_spinner()
@with_spinner(text="Updating VPN state...")
def vpn(
project_name: str,
project_guid: str,
Expand All @@ -59,20 +59,18 @@ def vpn(
spinner.red.fail(Symbols.ERROR)
raise SystemExit(1) from e

# Check the current state of VPN and avoid making the update call.
if project['spec']['features']['vpn'].get('enabled', False) == enable:
expected_state = "enabled" if enable else "disabled"
spinner.text = click.style('VPN is already {}.'.format(expected_state), fg=Colors.GREEN)
spinner.green.ok(Symbols.SUCCESS)
return

project["spec"]["features"]["vpn"] = {
"enabled": enable,
"subnets": (subnets or []) if enable else []
"subnets": subnets or []
}

state = 'Enabling' if enable else 'Disabling'
spinner.text = click.style('{} VPN...'.format(state), fg=Colors.YELLOW)
is_vpn_enabled = project["spec"]["features"]["vpn"].get("enabled", False)

status = 'Enabling VPN...' if enable else 'Disabling VPN...'
if is_vpn_enabled and subnets:
status = 'Updating the VPN subnet ranges for the project...'

spinner.text = status

try:
client.update_project(project_guid, project)
Expand Down
Loading