Skip to content

Commit

Permalink
feat(organization): adds inspect command to check org details
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Aug 30, 2023
1 parent 5a0facc commit f9cd3ae
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions riocli/organization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from click_help_colors import HelpColorsGroup

from riocli.constants import Colors
from riocli.organization.inspect import inspect_organization
from riocli.organization.list import list_organizations
from riocli.organization.select import select_organization
from riocli.organization.users import list_users
Expand All @@ -36,3 +37,4 @@ def organization() -> None:
organization.add_command(list_users)
organization.add_command(list_organizations)
organization.add_command(select_organization)
organization.add_command(inspect_organization)
65 changes: 65 additions & 0 deletions riocli/organization/inspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 typing

import click
from click_help_colors import HelpColorsCommand

from riocli.constants import Colors
from riocli.organization.utils import get_organization_details
from riocli.project.util import name_to_organization_guid
from riocli.utils import inspect_with_format


@click.command(
'inspect',
cls=HelpColorsCommand,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.option('--format', '-f', 'format_type', default='yaml',
type=click.Choice(['json', 'yaml'], case_sensitive=False))
@click.argument('organization-name', type=str)
@name_to_organization_guid
def inspect_organization(format_type: str, organization_name: str, organization_guid: str) -> None:
"""
Inspect an organization
"""
try:
organization = get_organization_details(organization_guid)
inspect_with_format(make_organization_inspectable(organization), format_type)
except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e


def make_organization_inspectable(organization: typing.Dict) -> typing.Dict:
creator = None
for user in organization['users']:
if user['guid'] == organization['creator']:
creator = user['emailID']
break

return {
'name': organization['name'],
'created_at': organization['CreatedAt'],
'updated_at': organization['UpdatedAt'],
'guid': organization['guid'],
'url': organization['url'],
'creator': creator,
'short_guid': organization['shortGUID'],
'state': organization['state'],
'users': len(organization['users']),
'country': organization['country']['code'],
}

0 comments on commit f9cd3ae

Please sign in to comment.