def wrapper(*args, **kwargs): try: if kwargs['map_object'] is None: layer = kwargs['layer'] logging.debug('Getting layer ' + layer) kwargs["layer_obj"] = LayerService.get(layer) return func(*args, **kwargs) except LayerNotFound as e: return error(status=404, detail=e.message) except Exception as e: return error(detail='Generic error')
def wrapper(*args, **kwargs): try: layer = kwargs['layer'] logging.debug( "get_layer - loading layer {} from LayerService".format(layer)) kwargs["layer_obj"] = LayerService.get(layer) return func(*args, **kwargs) except LayerNotFound as e: logging.error("get_layer - LayerNotFound - {}".format(e.message)) return error(status=404, detail=e.message) except Exception as e: logging.error("get_layer - Exception - {}".format(e.message)) return error(detail='Generic error')
def get_tile(layer, z, x, y, map_object=None, layer_obj=None): """Get tile Endpoint""" logging.info('[ROUTER]: Get tile') logging.info(map_object) try: if map_object is None: logging.debug('Generating mapid') layer_config = layer_obj.get('layerConfig') style_type = layer_config.get('body').get('styleType') image = None if 'isImageCollection' not in layer_config or not layer_config.get( 'isImageCollection'): image = ee.Image(layer_config.get('assetId')) else: position = layer_config.get('position') image_col = ee.ImageCollection(layer_config.get('assetId')) if 'filterDates' in layer_config: dates = layer_config.get('filterDates') image_col = image_col.filterDate(dates[0], dates[1]) if position == 'first': logging.info('Obtaining first') image = ee.Image( image_col.sort('system:time_start', True).first()) else: logging.info('Obtaining last') image = ee.Image( image_col.sort('system:time_start', False).first()) if style_type == 'sld': style = layer_config.get('body').get('sldValue') map_object = image.sldStyle(style).getMapId() else: map_object = image.getMapId(layer_config.get('body')) logging.debug('Saving in cache') RedisService.set_layer_mapid(layer, map_object.get('mapid'), map_object.get('token')) except Exception as e: logging.error(str(e)) return error(status=500, detail='Error generating tile: ' + str(e)) try: url = ee.data.getTileUrl(map_object, int(x), int(y), int(z)) storage_url = StorageService.upload_file(url, layer, map_object.get('mapid'), z, x, y) except Exception as e: logging.error(str(e)) return error(status=404, detail='Tile Not Found') return redirect(storage_url)
def wrapper(*args, **kwargs): logging.debug("Checking microservice user") logged_user = json.loads(request.args.get("loggedUser", '{}')) if logged_user.get("id") == "microservice": logging.debug("is microservice") return func(*args, **kwargs) else: return error(status=403, detail="Not authorized")
def wrapper(*args, **kwargs): logging.debug("Checking microservice user") logged_user = request.json.get("loggedUser", None) if (logged_user.get("id") == "microservice") or (logged_user.get("role") == "ADMIN"): logging.debug("is microservice or admin") return func(*args, **kwargs) else: return error(status=403, detail="Not authorized")
def internal_server_error(e): return error(status=500, detail='Internal Server Error')
def gone(e): return error(status=410, detail='Gone')
def method_not_allowed(e): return error(status=405, detail='Method Not Allowed')
def page_not_found(e): return error(status=404, detail='Not Found (404)')
def forbidden(e): return error(status=403, detail='Forbidden')