import json from flask import request, Response from flask_lambda import FlaskLambda from vacinacao.service_layer.searcher import search_name from vacinacao import settings from flask_cors import CORS app = FlaskLambda(__name__) CORS(app) @app.route("/", methods=["GET"]) def home(): html_template = open(f"{settings.ROOT_DIR}/templates/search.html").read() html_content = html_template.replace(r"{{ BASE_URL }}", settings.BASE_URL) return html_content, 200 @app.route("/search", methods=["POST"]) def search(): found = search_name(json.loads(request.data)["name"]) return Response(json.dumps(found), headers={"Content-Type": "application/json"}) if __name__ == "__main__": app.run(debug=True)
# delete existing URL, assuming the current user is the owner if "linkid" not in request.json: raise BadRequestException("When action is 'delete' the 'linkid' field must be present") link = Link.get_link_by_id( env = os.environ.get('environment_name'), linkid = request.json["linkid"], id = g.username ) link.delete_record(env = os.environ.get('environment_name')) return success_json_response({ "status": "deleted" }) # use state to manage keeping a record of the url being saved @lambda_handler.route('/_triggerlogin', methods=["GET"]) def login(): response = make_response("", 301) response.headers["Location"] = "https://{cog_domain}.auth.{region}.amazoncognito.com/login?response_type=token&client_id={client_id}&redirect_uri={redirect}&scope=openid+email".format( cog_domain = os.environ["cog_domain"], region = os.environ["region"], client_id = os.environ["cog_client_id"], redirect = request.args.get("redirect_uri") ) return response if __name__ == '__main__': if not os.environ.get('environment_name'): print("We need the ENV environment variable to be set, exiting") exit(1) lambda_handler.run(debug=True)
audience=aud) return decoded except ExpiredSignatureError as e: raise SignatureExpiredException("Signature not valid") else: # could not find the key, probably an issue with keycloak raise SystemFailureException("Key could not be found in key set") @lambda_handler.route("/", methods=["POST"]) @error_handler def root(): if not request.json: raise BadRequestException("Request should be JSON") if "keys" not in request.json: raise BadRequestException("Expecting 'keys' field, but not found") if "token" not in request.json: raise BadRequestException("Expecting 'token' field, but not found") if "aud" not in request.json: raise BadRequestException("Expecting 'aud', but not found") logger.info("Validating...") d = validate_jwt(token=request.json["token"], key_set=request.json["keys"], aud=request.json["aud"]) logger.info("Validated") return success_json_response(d) if __name__ == '__main__': lambda_handler.run(debug=True, port=5001, host="0.0.0.0", threaded=True)
) # Function for get_parameters def get_parameters(param_key): ssm = boto3.client('ssm', region_name=region) response = ssm.get_parameters(Names=[ param_key, ], WithDecryption=True) return response['Parameters'][0]['Value'] @app.route('/', methods=['GET', 'POST']) def env(): #app = request.args.get('appname') # parameter name param_key = request.args.get('appname') # get parameter value param_value = get_parameters(param_key) return param_value @app.route('/healthz', methods=['GET', 'POST']) def starting_url(): status_code = flask.Response(status=200) return status_code if __name__ == '__main__': app.run(host='0.0.0.0', port=80)
# # 'AttributeType': 'N' # # }, # # { # # 'AttributeName': 'title', # # 'AttributeType': 'S' # # }, # # # # ], # # ProvisionedThroughput={ # # 'ReadCapacityUnits': 10, # # 'WriteCapacityUnits': 10 # # } # # ) # for federal_tax_dict in federal_tax_dict_list: # table.put_item(Item=federal_tax_dict) # # # table.put_item(Item={'year': 2002, 'title': 'hello'}) # except ClientError as e: # print(e.response['Error']['Message']) # return json_response({"message": "1234Hello, world!"}) def json_response(data, response_code=200): return json.dumps(data), response_code, { 'Content-Type': 'application/json' } if __name__ == "__main__": app.run(port=5000, debug=True)
body = '' status = 204 elif request.method == 'GET': try: app.logger.info('Getting \"{}\"'.format(key)) obj = s3_client.Object(bucket, 'cache/' + key) body = obj.get()['Body'].read().decode('utf-8') xray_recorder.begin_subsegment('decryption') body = codecs.decode(body, 'rot_13') xray_recorder.end_subsegment() status = 200 except ClientError as ex: app.logger.exception('Error', ex) if ex.response['Error']['Code'] == 'NoSuchKey': status = 204 body = '' else: raise ex else: body = json.dumps({'status': 'Method Not Supported'}) status = 406 app.logger.info('Status {}, Body \"{}\"'.format(status, body)) return make_response(body, status) if __name__ == '__main__': if HOST and PORT: app.run(host=HOST, port=PORT, debug=True) else: app.run(debug=True)
}) uploaded_file = request.files[filekey] if uploaded_file.filename != '': if uploaded_file and allowed_file(uploaded_file.filename): process_upload(uploaded_file, project) return (json.dumps('File Uploaded successfully'), 200, { 'Content-Type': 'application/json' }) else: return (json.dumps( 'That file extension is not allowed. JSON only'), 403, { 'Content-Type': 'application/json' }) else: return (json.dumps('No file uploaded'), 400, { 'Content-Type': 'application/json' }) else: return (json.dumps('Method not allowed'), 405, { 'Content-Type': 'application/json' }) if __name__ == '__main__': app.run()
@app.route("/", methods=['GET']) def main(): return "Welcome to CG Frontend Web Page" @app.route("/postnumbers", methods=['POST']) @expects_json(schema) def postNumbers(): if request.json: numberone = request.json.get('numberone', '') numbertwo = request.json.get('numbertwo', '') resp = { "statusCode": 200, "body": { "total": sendNumbers(numberone, numbertwo) } } return (resp) def sendNumbers(numberone, numbertwo): url = os.environ['BACKEND_URL'] jsonObject = {'numberone': numberone, 'numbertwo': numbertwo} resp = requests.post(url, json=jsonObject) return (resp.text) if __name__ == '__main__': app.run(use_reloader=True, host='0.0.0.0', port=80)