def show(self): validate_creds_exists(self.app) db = DBWrapper(self.app.creds) application_id = self.app.pargs.application_id application_client = APIClient( db.get_configure()).get_application_api_client() enterprise_id = db.get_enterprise_id() try: response = application_client.get_application( application_id, enterprise_id) except ApiException as e: self.app.log.error( f"[application-show] Failed to show details of an application: {e}" ) self.app.render(f"ERROR: {parse_error_message(self.app, e)}") return if self.app.pargs.active: db.set_application({'id': application_id}) if not self.app.pargs.json: renderable = self._application_basic_response(response) self.app.render(renderable, format=OutputFormat.TABULATED.value, headers="keys", tablefmt="plain") else: renderable = self._application_basic_response( response, OutputFormat.JSON) self.app.render(renderable, format=OutputFormat.JSON.value)
def set_active(self): validate_creds_exists(self.app) db = DBWrapper(self.app.creds) application_client = APIClient( db.get_configure()).get_application_api_client() enterprise_id = db.get_enterprise_id() if self.app.pargs.id: application_id = self.app.pargs.id try: response = application_client.get_application( application_id, enterprise_id) db.set_application({'id': application_id}) except ApiException as e: self.app.log.error( f"[application-active] Failed to show active application: {e}" ) self.app.render(f"ERROR: {parse_error_message(self.app, e)}") return else: application = db.get_application() if application is None or application.get('id') is None: self.app.log.debug( '[application-active] There is no active application.') self.app.render('There is no active application.') return application_id = application.get('id') try: response = application_client.get_application( application_id, enterprise_id) db.set_application({'id': application_id}) except ApiException as e: self.app.log.error( f"[application-active] Failed to show active application: {e}" ) self.app.render(f"ERROR: {parse_error_message(self.app, e)}") return if not self.app.pargs.json: renderable = self._application_basic_response(response) self.app.render(renderable, format=OutputFormat.TABULATED.value, headers="keys", tablefmt="plain") else: renderable = self._application_basic_response( response, OutputFormat.JSON) self.app.render(renderable, format=OutputFormat.JSON.value)