def get_all(self, requester_user=None, limit=None, **raw_filters): """Retrieve multiple Inquiries Handles requests: GET /inquiries/ """ raw_inquiries = super(InquiriesController, self)._get_all( limit=limit, raw_filters={ 'status': action_constants.LIVEACTION_STATUS_PENDING, 'runner': INQUIRY_RUNNER }, requester_user=requester_user) # Since "model" is set to InquiryAPI (for good reasons), _get_all returns a list of # InquiryAPI instances, already converted to JSON. So in order to convert these to # InquiryResponseAPI instances, we first have to convert raw_inquiries.body back to # a list of dicts, and then individually convert these to InquiryResponseAPI instances inquiries = [ inqy_api_models.InquiryResponseAPI.from_model(raw_inquiry, skip_db=True) for raw_inquiry in json.loads(raw_inquiries.body) ] # Repackage into Response with correct headers resp = api_router.Response(json=inquiries) resp.headers['X-Total-Count'] = raw_inquiries.headers['X-Total-Count'] if limit: resp.headers['X-Limit'] = str(limit) return resp
def get(self, referer): try: response = router.Response(status=http_client.TEMPORARY_REDIRECT) response.location = SSO_BACKEND.get_request_redirect_url(referer) return response except NotImplementedError as e: return process_failure_response(http_client.INTERNAL_SERVER_ERROR, e) except Exception as e: raise e
def post(self, wf_def): # Load workflow definition into workflow spec model. spec_module = specs_loader.get_spec_module('native') wf_spec = spec_module.instantiate(wf_def) # Mock the st2 context that is typically passed to the workflow engine. st2_ctx = self.mock_st2_ctx() # Inspect the workflow spec and return the errors instead of raising exception. errors = workflow_service.inspect(wf_spec, st2_ctx, raise_exception=False) # Return the result of the inspection. return router.Response(json=errors)
def get_all( self, exclude_attributes=None, include_attributes=None, requester_user=None, limit=None, **raw_filters, ): """Retrieve multiple Inquiries Handles requests: GET /inquiries/ """ # NOTE: This controller retrieves execution objects and returns a new model composed of # execution.result fields and that's why we pass empty value for include_fields and # exclude_fields. # We only need to retrieve "id" and "result" from database and perform actual field # filtering before returning the response. raw_inquiries = super(InquiriesController, self)._get_all( exclude_fields=[], include_fields=["id", "result"], limit=limit, raw_filters={ "status": action_constants.LIVEACTION_STATUS_PENDING, "runner": INQUIRY_RUNNER, }, requester_user=requester_user, ) # Since "model" is set to InquiryAPI (for good reasons), _get_all returns a list of # InquiryAPI instances, already converted to JSON. So in order to convert these to # InquiryResponseAPI instances, we first have to convert raw_inquiries.body back to # a list of dicts, and then individually convert these to InquiryResponseAPI instances inquiries = [ inqy_api_models.InquiryResponseAPI.from_model(raw_inquiry, skip_db=True) for raw_inquiry in json_decode(raw_inquiries.body) ] # Repackage into Response with correct headers resp = api_router.Response(json=inquiries) resp.headers["X-Total-Count"] = raw_inquiries.headers["X-Total-Count"] if limit: resp.headers["X-Limit"] = str(limit) return resp
def process_successful_authn_response(referer, token): token_json = { "id": str(token.id), "user": token.user, "token": token.token, "expiry": str(token.expiry), "service": False, "metadata": {}, } body = CALLBACK_SUCCESS_RESPONSE_BODY % referer resp = router.Response(body=body) resp.headers["Content-Type"] = "text/html" resp.set_cookie( "st2-auth-token", value=urllib.parse.quote(json.dumps(token_json)), expires=datetime.timedelta(seconds=60), overwrite=True, ) return resp
def process_successful_authn_response(referer, token): token_json = { 'id': str(token.id), 'user': token.user, 'token': token.token, 'expiry': str(token.expiry), 'service': False, 'metadata': {} } body = CALLBACK_SUCCESS_RESPONSE_BODY % referer resp = router.Response(body=body) resp.headers['Content-Type'] = 'text/html' resp.set_cookie( 'st2-auth-token', value=urllib.parse.quote(json.dumps(token_json)), expires=datetime.timedelta(seconds=60), overwrite=True ) return resp
def process_failure_response(status_code, exception): LOG.error(str(exception)) json_body = {"faultstring": str(exception)} return router.Response(status_code=status_code, json_body=json_body)
def process_successful_response(status_code, json_body): return router.Response(status_code=status_code, json_body=json_body)