def Authenticate(): # Check params if not request.is_json: common.json_abort(401, {'error': "expecting json input"}) params = request.get_json(force=True) apiKey = params.get(API_KEY_PARAMETER) if not apiKey: common.json_abort( 400, {'error': f"Missing json value: {API_KEY_PARAMETER}"}) # Check Authorization __checkAuthorization(apiKey) response = {'message': "Authentication success: api-key OK !"} return jsonify(response)
def __checkAuthorization(submittedApiKey=None): apiKey = None # Check api-key in header if submittedApiKey: apiKey = submittedApiKey else: apiKey = request.headers.get(API_KEY_PARAMETER_HEADER) expectedApiKey = os.environ['API_KEY'].strip() if not apiKey: common.json_abort( 401, {'error': f"Missing header: {API_KEY_PARAMETER_HEADER}"}) elif not apiKey == expectedApiKey: common.json_abort(401, {'error': f"Invalid credentials !"})
def getNetcoupeFlight(flightId): flight = None filename = f"NetCoupe{datetime.now().year}_{flightId}.igc" filename_last_year = f"NetCoupe{datetime.now().year - 1}_{flightId}.igc" storageService = StorageService(None) bucket_name, fullFilePath = storageService.GetFileFullpathFromName(filename, filename_last_year) if (fullFilePath is None): common.json_abort(404, {'error': f"Cannot find flight: {flightId}"}) file_as_bytesio = storageService.GetFileAsStringFromBucket(bucket_name, fullFilePath) flight = igc_lib.Flight.create_from_bytesio(file_as_bytesio) file_as_bytesio.close del file_as_bytesio return flight
def __checkFile(): # check if the post request has the file part if 'file' not in request.files: common.json_abort(400, {'error': "file cannot be found in request"}) file = request.files['file'] # if user does not select file, browser also submit an empty part without filename if file.filename == '': common.json_abort(400, {'error': "No filename in request"}) if not file or not allowed_file(file.filename): common.json_abort(400, {'error': "The IGC file is not valid"}) return file
def GetAirspaceAsZip(): try: filename = os.path.join(common.STATIC_FOLDER, "airspace.zip") return send_file(filename, mimetype='application/zip') except Exception as e: common.json_abort(500, {'error': str(e)})
def GetAirspaceAsGeojson(): try: filename = common.getAirspaceFullFilename() return send_file(filename, mimetype='application/json') except Exception as e: common.json_abort(500, {'error': str(e)})