Skip to content

Commit

Permalink
feat(project): adds project features sub-command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pallabpain committed May 9, 2023
1 parent b5ca2b4 commit 981dc3a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions riocli/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
33 changes: 33 additions & 0 deletions riocli/project/features/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
49 changes: 49 additions & 0 deletions riocli/project/features/vpn.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 981dc3a

Please sign in to comment.