"message": "stuff happened" }]) @auth.login_required def post(self): command = "update_crl" task = celery_runner.update_crl.delay(command) #result = task.wait(timeout=None, interval=0.2) #task_result = celery_runner.update_crl.AsyncResult(task.id) #task_result.get() #output = task_result['output'] task.get(timeout=1) aws_key = appconfig['aws_key'] aws_key_secret = appconfig['aws_key_secret'] aws_bucket_name = appconfig['aws_bucket_name'] aws_s3_host_name = appconfig['aws_s3_host_name'] flask_clr_path = appconfig['flask_clr_path'] util_functions.download_from_s3(access_key=aws_key, access_key_secret=aws_key_secret, bucket_name=aws_bucket_name, src_file_name="flauthority_clr.pem", dest_file_name="flauthority_clr.pem", dest_file_path=flask_clr_path, aws_s3_host_name=aws_s3_host_name) print(task) api.add_resource(UpdateCrl, '/api/updatecrl')
import os from flask_restful import Resource, Api from flask_restful_swagger import swagger from flask_restful import reqparse from flask import Flask, request, send_from_directory, send_file from flauthority import api, app, auth, appconfig, appconfig class SendCrl(Resource): @swagger.operation(notes='this is where the crl lives', nickname='crl', responseMessages=[{ "code": 200, "message": "you got the crl" }, { "code": 400, "message": "stuff happened" }]) def get(self): flask_clr_path = appconfig['flask_clr_path'] crl_file = os.path.join(flask_clr_path, "flauthority_clr.pem") return send_file( crl_file, mimetype="application/pkix-crl, application/x-pkcs7-crl") api.add_resource(SendCrl, '/api/crl')
"description": "The ID of the task/job to get status for", "required": True, "allowMultiple": False, "dataType": 'string', "paramType": "path" }]) @auth.login_required def get(self, task_id): task = celery_runner.generate_certificate.AsyncResult(task_id) if task.state == 'PENDING': result = "Task not found" resp = app.make_response((result, 404)) return resp if task.state == "PROGRESS": result = task.info['output'] else: if 'output' in task.info.keys(): result = task.info['output'] else: result = "" #result_out = task.info.replace('\n', "<br>") #result = result.replace('\n', '<br>') #return result, 200, {'Content-Type': 'text/html; charset=utf-8'} #resp = app.make_response((result, 200)) #resp.headers['content-type'] = 'text/plain' return task.info api.add_resource(TaskOutput, '/api/taskoutput/<string:task_id>')
} ]) @auth.login_required def get(self, task_id): task = celery_runner.generate_certificate.AsyncResult(task_id) if task.state == 'PENDING': result = "Task not found" resp = app.make_response((result, 404)) return resp elif task.state == 'PROGRESS': result_obj = {'Status': "PROGRESS", 'description': "Task is currently running", 'returncode': None} else: try: return_code = task.info['returncode'] description = task.info['description'] if return_code is 0: result_obj = {'Status': "SUCCESS", 'description': description} else: result_obj = {'Status': "FLAUTHORITY_TASK_FAILURE", 'description': description, 'returncode': return_code} except: result_obj = {'Status': "CELERY_FAILURE"} return result_obj api.add_resource(TaskStatus, '/api/taskstatus/<string:task_id>')
str(cert_lifetime_days), str(max_cert_lifetime)) logger.warning(msg) return make_response(msg, 400) curr_user = auth.username() task_timeout = appconfig['task_timeout'] task_obj = { 'subject_name': subject_name, 'cert_extension': cert_extension, 'validity_days': str(cert_lifetime_days) } allow_cert_extension = appconfig['allow_cert_extension'] allow = [ x for x in allow_cert_extension if x.strip() == cert_extension ] if len(allow) == 0: logger.warning( str.format("Template requested: {1}, allowed extension: {1}", cert_extension, str(allow_cert_extension))) return make_response("Invalid cert extension", 400) task_result = celery_runner.generate_certificate.apply_async( [task_obj], soft=task_timeout, hard=task_timeout) result = {'task_id': task_result.id} return result api.add_resource(GenerateCertificate, '/api/generatecertificate')