From 981dc3afd0670e61976651e6177d85269085b01a Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Wed, 22 Mar 2023 15:00:02 +0530 Subject: [PATCH] feat(project): adds project features sub-command The features subcommand will allow toggling features on a project Usage: rio project features [OPTIONS] COMMAND [ARGS]... Toggle features on a project Options: --help Show this message and exit. Commands: vpn Enable or disable VPN on a project VPN is the first feature included in this commmit. --- riocli/project/__init__.py | 2 ++ riocli/project/features/__init__.py | 33 +++++++++++++++++++ riocli/project/features/vpn.py | 49 +++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 riocli/project/features/__init__.py create mode 100644 riocli/project/features/vpn.py diff --git a/riocli/project/__init__.py b/riocli/project/__init__.py index 0d94fc21..ba71f34e 100644 --- a/riocli/project/__init__.py +++ b/riocli/project/__init__.py @@ -16,6 +16,7 @@ from riocli.project.create import create_project from riocli.project.delete import delete_project +from riocli.project.features import features from riocli.project.inspect import inspect_project from riocli.project.list import list_project from riocli.project.select import select_project @@ -39,3 +40,4 @@ def project() -> None: project.add_command(delete_project) project.add_command(select_project) project.add_command(inspect_project) +project.add_command(features) diff --git a/riocli/project/features/__init__.py b/riocli/project/features/__init__.py new file mode 100644 index 00000000..d6147e5e --- /dev/null +++ b/riocli/project/features/__init__.py @@ -0,0 +1,33 @@ +# Copyright 2023 Rapyuta Robotics +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import click +from click_help_colors import HelpColorsGroup + +from riocli.project.features.vpn import vpn + + +@click.group( + invoke_without_command=False, + cls=HelpColorsGroup, + help_headers_color='yellow', + help_options_color='green', +) +def features(): + """ + Toggle features on a project + """ + pass + + +features.add_command(vpn) diff --git a/riocli/project/features/vpn.py b/riocli/project/features/vpn.py new file mode 100644 index 00000000..07cd7447 --- /dev/null +++ b/riocli/project/features/vpn.py @@ -0,0 +1,49 @@ +# Copyright 2023 Rapyuta Robotics +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import click + +from riocli.config import new_v2_client +from riocli.project.util import name_to_guid + + +@click.command('vpn') +@click.argument('project-name', type=str) +@click.argument('enable', type=bool) +@name_to_guid +def vpn(project_name: str, project_guid: str, enable: bool) -> None: + """ + Enable or disable VPN on a project + + Example: rio project features vpn "my-project" true + """ + client = new_v2_client(with_project=False) + + body = { + "metadata": { + "projectGUID": project_guid + }, + "spec": { + "features": { + "vpn": enable + } + } + } + + try: + r = client.update_project(project_guid, body) + except Exception as e: + click.secho("❌ Failed: {}".format(e), fg='red') + raise SystemExit(1) from e + + click.secho("✅ VPN has been {}".format("enabled" if enable else "disabled"), fg='green')