def dss_isa_callback(id): ''' This is the call back end point that other USSes in the DSS network call once a subscription is updated ''' if requires_scope('dss.write.identification_service_areas'): new_flights_url = request.args.get('flights_url', 0) try: assert new_flights_url != 0 redis = redis.Redis(host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT']) # Get the flights URL from the DSS and put it in flights_dict = redis.hgetall("all_uss_flights") all_flights_url = flights_dict['all_flights_url'] all_flights_url = all_flights_url.append(new_flights_url) flights_dict["all_uss_flights"] = all_flights_url redis.hmset("all_uss_flights", flights_dict) except AssertionError as ae: return Response("Incorrect data in the POST URL", status=400, mimetype='application/json') else: # All OK return a empty response return Response("", status=204, mimetype='application/json') raise AuthError( { "code": "Unauthorized", "description": "You don't have access to this resource" }, 403)
def post_flight_declaration(): if requires_scope('blender.write'): try: assert request.headers['Content-Type'] == 'application/json' except AssertionError as ae: msg = {"message": "Unsupported Media Type"} return Response(json.dumps(msg), status=415, mimetype='application/json') else: req = json.loads(request.data) try: flight_declaration_data = req["flight_declaration"] except KeyError as ke: msg = json.dumps({ "message": "One parameter are required: observations with a list of observation objects. One or more of these were not found in your JSON request. For sample data see: https://github.com/openskies-sh/airtraffic-data-protocol-development/blob/master/Airtraffic-Data-Protocol.md#sample-traffic-object" }) return Response(msg, status=400, mimetype='application/json') else: task = tasks.write_flight_declaration.delay( flight_declaration_data ) # Send a job to the task queuervation) # Send a job to the task queue op = json.dumps({"message": "Submitted Flight Declaration"}) return Response(op, status=200, mimetype='application/json') raise AuthError( { "code": "Unauthorized", "description": "You don't have access to this resource" }, 403)
def set_air_traffic(): if requires_scope('blender.write'): ''' This is the main POST method that takes in a request for Air traffic observation and processes the input data ''' try: assert request.headers['Content-Type'] == 'application/json' except AssertionError as ae: msg = {"message": "Unsupported Media Type"} return Response(json.dumps(msg), status=415, mimetype='application/json') else: req = json.loads(request.data) try: observations = req['observations'] except KeyError as ke: msg = json.dumps({ "message": "One parameter are required: observations with a list of observation objects. One or more of these were not found in your JSON request. For sample data see: https://github.com/openskies-sh/airtraffic-data-protocol-development/blob/master/Airtraffic-Data-Protocol.md#sample-traffic-object" }) return Response(msg, status=400, mimetype='application/json') else: for observation in observations: lat_dd = observation['lat_dd'] lon_dd = observation['lon_dd'] altitude_mm = observation['altitude_mm'] traffic_source = observation['traffic_source'] source_type = observation['source_type'] icao_address = observation['icao_address'] single_observation = { 'lat_dd': lat_dd, 'lon_dd': lon_dd, 'altitude_mm': altitude_mm, 'traffic_source': traffic_source, 'source_type': source_type, 'icao_address': icao_address } task = tasks.write_incoming_data.delay( single_observation) # Send a job to the task queue op = json.dumps({"message": "OK"}) return Response(op, status=200, mimetype='application/json') raise AuthError( { "code": "Unauthorized", "description": "You don't have access to this resource" }, 403)
def create_dss_subscription(): ''' This module takes a lat, lng box from Flight Spotlight and puts in a subscription to the DSS for the ISA ''' if requires_scope('blender.write'): try: view = request.args.get('view') # view is a bbox list view = [float(i) for i in view.split(",")] except Exception as ke: incorrect_parameters = { "message": "A view bbox is necessary with four values: minx, miny, maxx and maxy" } return Response(json.dumps(incorrect_parameters), status=400, mimetype='application/json') else: b = box(view[0], view[1], view[2], view[3]) co_ordinates = list(zip(*b.exterior.coords.xy)) # Convert bounds vertex list vertex_list = [] for cur_co_ordinate in co_ordinates: lat_lng = {"lng": 0, "lat": 0} lat_lng["lng"] = cur_co_ordinate[0] lat_lng["lat"] = cur_co_ordinate[1] vertex_list.append(lat_lng) # remove the final point vertex_list.pop() # TODO: Make this a asnyc call #tasks.submit_dss_subscription(vertex_list = vertex_list, view_port = view) myDSSubscriber = rid_dss_operations.RemoteIDOperations() subscription_respone = myDSSubscriber.create_dss_subscription( vertex_list=vertex_list, view_port=view) if subscription_respone['created']: msg = {"message": "DSS Subscription created"} else: msg = { "message": "Error in creating DSS Subscription, please check the log or contact your administrator." } return Response(json.dumps(msg), status=200, mimetype='application/json') raise AuthError( { "code": "Unauthorized", "description": "You don't have access to this resource" }, 403)
def post_geo_fence(): if requires_scope('blender.write'): try: assert request.headers['Content-Type'] == 'application/json' except AssertionError as ae: msg = {"message": "Unsupported Media Type"} return Response(json.dumps(msg), status=415, mimetype='application/json') else: geo_fence = json.loads(request.data) task = tasks.write_geo_fence.delay( geo_fence) # Send a job to the task queue op = json.dumps({"message": "Geofence submitted successfully"}) return Response(op, status=200, mimetype='application/json') raise AuthError( { "code": "Unauthorized", "description": "You don't have access to this resource" }, 403)