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)
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 delete(self): version_id = self.app.pargs.version_id 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.application: application_id = self.app.pargs.application else: application = db.get_application() if not application or not application.get('id'): self.app.log.debug('[version-delete] There is no active application.') self.app.render('There is no active application.\n') return application_id = application.get('id') try: application_client.delete_app_version(version_id, application_id, enterprise_id) self.app.log.debug(f"[version-delete] Version with id : {version_id} deleted successfully") self.app.render(f"Version with id {version_id} deleted successfully\n") except ApiException as e: self.app.log.error(f"[version-delete] Failed to delete a version: {e}") self.app.render(f"ERROR: {parse_error_message(self.app, e)}\n") return # Unset current application if matching try: application_client.get_application(application_id, enterprise_id) except ApiException as e: if e.status == HTTPStatus.NOT_FOUND: application = db.get_application() if application and application.get('id') and application_id == application.get('id'): db.unset_application() self.app.log.debug(f'[version-delete] Unset the active application {application_id}') else: self.app.log.debug(f"[version-delete] Failed to get an application when deleting a version: {e}") self.app.render(f"ERROR: {parse_error_message(self.app, e)}\n")