Exemplo n.º 1
0
    def delete(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)
        group_client = APIClient(db.get_configure()).get_group_api_client()
        enterprise_id = db.get_enterprise_id()

        group_name = self.app.pargs.name
        kwargs = {'name': group_name}
        try:
            search_response = group_client.get_all_groups(enterprise_id, limit=1, offset=0, **kwargs)
            if not search_response.results or len(search_response.results) == 0:
                self.app.log.debug(f'[group-delete] Group does not exist with name {group_name}')
                self.app.render(f'Group does not exist with name {group_name}')
                return
            response = search_response.results[0]
            group_id = response.id
        except ApiException as e:
            self.app.log.error(f"[group-update] Failed to list groups: {e}")
            self.app.render(f"ERROR: {parse_error_message(self.app, e)}")
            return

        try:
            group_client.delete_group(group_id, enterprise_id)
            self.app.log.debug(f"[group-update] Group with name {group_name} deleted successfully")
            self.app.render(f"Group with name {group_name} deleted successfully")

            # Unset current group if matching
            group = db.get_group()
            if group and group.get('id') and group_id == group.get('id'):
                db.unset_group()
                self.app.log.debug(f'[group-update] Unset the active group {group_name}')
        except ApiException as e:
            self.app.log.error(f"[group-update] Failed to delete group: {e}")
            self.app.render(f"ERROR: {parse_error_message(self.app, e)}")
            return
Exemplo n.º 2
0
    def unset_active(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)

        group = db.get_group()
        if group is None or group.get('name') is None:
            self.app.log.debug('[group-active] There is no active group.')
            self.app.render('There is no active group.')
            return

        db.unset_group()
        self.app.log.debug(f"[group-active] Unset the active group {group.get('name')}")
        self.app.render(f"Unset the active group {group.get('name')}\n")