Changeset f9321aa
- Timestamp:
- Apr 26, 2020, 5:02:25 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 62569d9
- Parents:
- 691c4ca
- Files:
-
- 14 added
- 14 edited
- 2 moved
-
VERSION (added)
-
buildhelpers/code_generator (modified) (1 diff)
-
buildhelpers/codegen/templates/__init__test.mustache (modified) (1 diff)
-
buildhelpers/codegen/templates/__main__.mustache (modified) (1 diff)
-
setup.py (modified) (1 diff)
-
src/gnuboat/common/device/__init__.py (added)
-
src/gnuboat/common/device/rrdschema.py (added)
-
src/gnuboat/common/tests/test_config.py (moved) (moved from src/gnuboat/mapservice_impl/tests/test_config.py ) (3 diffs)
-
src/gnuboat/common/webservice/Config.py (added)
-
src/gnuboat/common/webservice/HttpErrors.py (moved) (moved from src/gnuboat/mapservice_impl/HttpErrors.py ) (8 diffs)
-
src/gnuboat/common/webservice/__init__.py (added)
-
src/gnuboat/device/daemon/rrdhandler.py (modified) (3 diffs)
-
src/gnuboat/deviceservice.yaml (modified) (9 diffs)
-
src/gnuboat/deviceservice_impl/Config.py (added)
-
src/gnuboat/deviceservice_impl/__init__.py (added)
-
src/gnuboat/deviceservice_impl/controllers/DeviceController.py (added)
-
src/gnuboat/deviceservice_impl/controllers/DeviceLogsController.py (added)
-
src/gnuboat/deviceservice_impl/controllers/DeviceMapsController.py (added)
-
src/gnuboat/deviceservice_impl/controllers/MapserviceController.py (added)
-
src/gnuboat/deviceservice_impl/controllers/__init__.py (added)
-
src/gnuboat/deviceservice_impl/tests/__init__.py (added)
-
src/gnuboat/mapservice_impl/Config.py (modified) (1 diff)
-
src/gnuboat/mapservice_impl/__init__.py (modified) (1 diff)
-
src/gnuboat/mapservice_impl/controllers/DevicesController.py (modified) (6 diffs)
-
src/gnuboat/mapservice_impl/controllers/LogsController.py (modified) (12 diffs)
-
src/gnuboat/mapservice_impl/controllers/TilesController.py (modified) (5 diffs)
-
src/gnuboat/mapservice_impl/controllers/UsersController.py (modified) (5 diffs)
-
src/gnuboat/mapservice_impl/controllers/WatersController.py (modified) (11 diffs)
-
src/gnuboat/mapservice_impl/demo/DbSetup.py (modified) (2 diffs)
-
src/gnuboat/mapservice_impl/tests/__init__.py (added)
Legend:
- Unmodified
- Added
- Removed
-
buildhelpers/code_generator
r691c4ca rf9321aa 1 #!/ bin/bash1 #!/usr/bin/python 2 2 3 DIR=`dirname "$0"` 4 SRC="${DIR}/../src/gnuboat" 5 SRC_GEN="${DIR}/../src/gnuboat/" 6 PACKAGE_NAME="mapservice" 7 PACKAGE_NAME_GEN="gnuboat.${PACKAGE_NAME}" 8 PACKAGE_VERSION="0.5.90" 9 TARGET_TMP="${SRC_GEN}/${PACKAGE_NAME}_tmp/" 3 import os 4 from pathlib import Path 5 import subprocess 6 import re 7 import shutil 8 import yaml 10 9 11 echo "Cleaning directory" 12 if [ -d "${SRC_GEN}/${PACKAGE_NAME}" ]; then 13 rm -R "${SRC_GEN}/${PACKAGE_NAME}" 14 fi 15 if [ -d "${TARGET_TMP}" ]; then 16 rm -R "${TARGET_TMP}" 17 fi 10 CURRENT_DIR = Path(os.path.dirname(__file__)) 11 SRC = CURRENT_DIR.joinpath('../src/gnuboat') 12 SRC_GEN = CURRENT_DIR.joinpath('../src/gnuboat/') 13 version_file = open(CURRENT_DIR.joinpath('../VERSION').resolve(), 'r') 14 VERSION = version_file.read().strip() 15 version_file.close() 18 16 19 echo "Preparing symlinks" 20 mkdir -p "${TARGET_TMP}" 17 PACKAGES=["mapservice", "deviceservice"] 21 18 22 echo "Generating backend API code" 23 ${DIR}/codegen/openapi-generator-cli generate -i "${SRC}/mapservice.yaml" -g python-flask -t "${DIR}/codegen/templates/" --additional-properties=packageVersion=${PACKAGE_VERSION},packageName=${PACKAGE_NAME_GEN} -o "${TARGET_TMP}" 24 mv "${TARGET_TMP}/gnuboat/${PACKAGE_NAME}" "${SRC_GEN}/${PACKAGE_NAME}" 25 rm -R "${TARGET_TMP}" 19 print('Generating the {} services:'.format(len(PACKAGES))) 20 for package in PACKAGES: 21 print(' {}'.format(package)) 26 22 27 # running yapf 28 echo "Formatting the generated code accoring to style file" 29 yapf --style "python-style.yapf" -r -i "${SRC_GEN}/${PACKAGE_NAME}" 23 for package in PACKAGES: 24 package_name_gen = 'gnuboat.{}'.format(package) 25 target = SRC_GEN.joinpath(package) 26 target_tmp = SRC_GEN.joinpath('{}_tmp'.format(package)) 27 service_specification_file = SRC.joinpath('{}.yaml'.format(package)).resolve() 28 server_port = 8080 29 30 openapi_specification = yaml.safe_load(open(service_specification_file)) 31 if 'servers' in openapi_specification: 32 for entry in openapi_specification['servers']: 33 if 'description' in entry and 'development' in entry['description'].lower(): 34 result = re.search(r':([0-9]+)', entry['url']) 35 if result is not None: 36 server_port = result.group(1) 37 38 print('Preparing package {} version {} using port {}'.format(package, VERSION, server_port)) 39 print(' Cleaning directory') 40 if os.path.isdir(target): 41 shutil.rmtree(target.resolve()) 42 if os.path.isdir(target_tmp): 43 shutil.rmtree(target_tmp.resolve()) 44 os.mkdir(target_tmp) 45 46 print(' Generating backend API code') 47 try: 48 subprocess.run([ 49 CURRENT_DIR.joinpath('codegen/openapi-generator-cli').resolve(), 50 'generate', '-i', service_specification_file, 51 '-g', 'python-flask', '-t', 52 CURRENT_DIR.joinpath('codegen/templates').resolve(), 53 ('--additional-properties=packageVersion={},packageName={},' 54 'serverPort={}').format(VERSION, package_name_gen, server_port), 55 '-o', target_tmp.resolve() 56 ], 57 check=True, 58 stdout=subprocess.PIPE, 59 stderr=subprocess.PIPE) 60 except subprocess.CalledProcessError as e: 61 print(' openapi-generator-cli failed:') 62 print(' STDOUT: {}'.format(e.stdout)) 63 print(' STDERR: {}'.format(e.stderr)) 64 65 shutil.move(target_tmp.joinpath('gnuboat/{}'.format(package)).resolve(), target.resolve()) 66 shutil.rmtree(target_tmp.resolve()) 67 68 # running yapf 69 print(' Formatting the generated code accoring to style file') 70 subprocess.run(['yapf', '--style', 'python-style.yapf', '-r', '-i', 71 target.resolve()]) -
buildhelpers/codegen/templates/__init__test.mustache
r691c4ca rf9321aa 1 import logging 1 from flask_testing import TestCase 2 2 3 import flask 4 import connexion 5 from flask_cors import CORS 6 from flask_testing import TestCase 7 from flask_mail import Mail 8 from sqlalchemy.event import listen 9 from celery import Celery 10 import tempfile 11 import os 12 from PIL import Image 13 import shutil 14 15 from {{packageName}}.encoder import JSONEncoder 16 from {{packageName}}_impl.database.Model import ( 17 db, db_setup, load_spatialite 3 from {{packageName}}_impl.tests import ( 4 create_app as orig_create_app, 5 setUp as orig_setUp, 6 tearDown as orig_tearDown 18 7 ) 19 from {{packageName}}_impl.tests import db_test_setup20 8 21 9 class BaseTestCase(TestCase): 22 10 def create_app(self): 23 logging.getLogger('connexion.operation').setLevel('ERROR') 24 app = connexion.App(__name__, specification_dir='../openapi/') 25 application = app.app 26 CORS(application) 27 mail = Mail() 28 application.json_encoder = JSONEncoder 29 app.add_api('openapi.yaml') 30 31 application.config.from_object('{{packageName}}_impl.Config.TestingConfig') 32 application.template_folder = os.path.join(os.path.dirname(__file__), '../../mapservice_impl/templates') 33 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL']) 34 celery.config_from_object(application.config) 35 mail.init_app(application) 36 db.init_app(application) 37 application.app_context().push() 38 39 self._create_test_tile(application) 40 41 return application 11 return orig_create_app(self) 42 12 43 13 def setUp(self): 44 listen(db.engine, 'connect', load_spatialite) 45 db.drop_all() 46 # create the tables whether the database already exists or not 47 db_setup(True) 48 self.db_content = db_test_setup.DatabaseContent() 49 self.db_content.setup() 14 orig_setUp(self) 50 15 51 16 def tearDown(self): 52 db.session.remove() 53 db.drop_all() 54 shutil.rmtree(self.tiles_cache) 55 56 def _create_test_tile(self, application): 57 self.tiles_cache = tempfile.mkdtemp(prefix='gnuboat-tests') 58 application.config['TILES_CACHE_PATH'] = self.tiles_cache 59 60 tile_path = os.path.join(self.tiles_cache, '100_100/256/15/17298/') 61 os.makedirs(tile_path) 62 img = Image.new('RGBA', (100, 100), (255, 0, 0, 0)) 63 img.save(os.path.join(tile_path, "21435.png"), "PNG") 17 orig_tearDown(self) 64 18 65 19 def check_key(self, key, value, data): -
buildhelpers/codegen/templates/__main__.mustache
r691c4ca rf9321aa 9 9 10 10 from {{packageName}}_impl import ( 11 app, application, mail, celery,setup_app, config_object11 app, application, setup_app, config_object 12 12 ) 13 13 -
setup.py
r691c4ca rf9321aa 5 5 6 6 NAME = 'gnuboat' 7 VERSION = '0.5.99' 7 version = open('VERSION', 'r') 8 VERSION = version.read().strip() 9 version.close() 8 10 9 11 # shapely is required by geoalchemy2 -
src/gnuboat/common/tests/test_config.py
r691c4ca rf9321aa 21 21 import os 22 22 23 from gnuboat.mapservice_impl import Config 23 from gnuboat.common.webservice import Config as configure 24 25 26 class Config(object): 27 TEST = 'blabla' 24 28 25 29 … … 29 33 """ 30 34 new_config = {'TESTING': True, 'DOES_NOT_EXISTS': 1234} 31 32 config = Config.Config()33 assert config.TESTING is False34 35 35 36 config_file = tempfile.NamedTemporaryFile( … … 45 46 config_file = os.path.join(tempfile.gettempdir(), config_file.name) 46 47 47 config = Config.load_from_file(config_file) 48 config = configure.config_from_file(config_file, Config()) 49 assert config.TEST == 'blabla' 48 50 assert config.TESTING is True 49 51 assert config.DOES_NOT_EXISTS == 1234 -
src/gnuboat/common/webservice/HttpErrors.py
r691c4ca rf9321aa 22 22 23 23 24 class MapserviceBadRequest(ProblemException, BadRequest):24 class GnuboatBadRequest(ProblemException, BadRequest): 25 25 def __init__( 26 26 self, … … 31 31 **kwargs 32 32 ): 33 super( MapserviceBadRequest, self).__init__(33 super(GnuboatBadRequest, self).__init__( 34 34 status=400, 35 35 title="Bad Request", … … 41 41 42 42 43 class MapserviceUnauthorized(ProblemException, Unauthorized):43 class GnuboatUnauthorized(ProblemException, Unauthorized): 44 44 def __init__( 45 45 self, … … 50 50 **kwargs 51 51 ): 52 super( MapserviceUnauthorized, self).__init__(52 super(GnuboatUnauthorized, self).__init__( 53 53 status=401, 54 54 title=title, … … 60 60 61 61 62 class MapserviceNotFound(ProblemException, NotFound):62 class GnuboatNotFound(ProblemException, NotFound): 63 63 def __init__( 64 64 self, … … 69 69 **kwargs 70 70 ): 71 super( MapserviceNotFound, self).__init__(71 super(GnuboatNotFound, self).__init__( 72 72 status=404, 73 73 title=title, … … 79 79 80 80 81 class MapserviceInternalServerError(ProblemException, InternalServerError):81 class GnuboatInternalServerError(ProblemException, InternalServerError): 82 82 def __init__( 83 83 self, … … 88 88 **kwargs 89 89 ): 90 super( MapserviceInternalServerError, self).__init__(90 super(GnuboatInternalServerError, self).__init__( 91 91 status=500, 92 92 title="Internal Server Error", -
src/gnuboat/device/daemon/rrdhandler.py
r691c4ca rf9321aa 1 1 # -*- coding: utf-8 -*- 2 2 ''' 3 Copyright (C) 2016 - 20 17EngSaS - Langenbach. All rights reserved.3 Copyright (C) 2016 - 2020 EngSaS - Langenbach. All rights reserved. 4 4 5 5 This program is free software: you can redistribute it and/or modify … … 21 21 import traceback 22 22 23 import gnuboat.common.device.rrdschema as rrdschema 23 24 24 25 def rrd_create_database(database_file, logperiod, start_time='N'): … … 32 33 step = logperiod 33 34 # durations: each archive should contain values for in seconds 34 archives = [ 35 { 36 "duration": 240, 37 "resolution": 2 38 }, 39 { 40 "duration": 3600, 41 "resolution": 10 42 }, 43 { 44 "duration": 86400, 45 "resolution": 60 46 }, 47 ] 35 archives = rrdschema.archives 48 36 rrd_archives = [] 49 37 for i in range(0, len(archives)): 50 38 rrd_archives += [ 51 39 'RRA:AVERAGE:0.5:{:d}:{:d}'.format( 52 _steps(archives[i] ["resolution"], step),40 _steps(archives[i].resolution, step), 53 41 _rows( 54 archives[i] ["duration"], archives[i]["resolution"], step42 archives[i].duration, archives[i].resolution, step 55 43 ) 56 44 ) -
src/gnuboat/deviceservice.yaml
r691c4ca rf9321aa 12 12 description: API for GNUBoat devices 13 13 servers: 14 - url: 'http://gnuboat/ {version}'14 - url: 'http://gnuboat/deviceservice/{version}' 15 15 description: The production API server 16 16 variables: 17 17 version: 18 18 default: v1 19 - url: 'http://localhost:8090/device /{version}'19 - url: 'http://localhost:8090/deviceservice/{version}' 20 20 description: The local flask development url 21 21 variables: … … 60 60 operationId: shutdown 61 61 responses: 62 '200': 63 description: OK 64 content: 65 application/json: 66 schema: 67 type: boolean 62 '204': 63 description: Shutdown initiated 68 64 '500': 69 65 $ref: '#/components/responses/InternalServerError' … … 72 68 description: List of local logfiles 73 69 tags: 74 - device 70 - deviceLogs 75 71 operationId: logfilesGet 76 72 responses: … … 83 79 '500': 84 80 $ref: '#/components/responses/InternalServerError' 85 '/logfiles/{id *}':81 '/logfiles/{id}': 86 82 get: 87 83 description: Download local logfiles … … 90 86 operationId: logsGet 91 87 parameters: 92 - name: id *88 - name: id 93 89 in: path 94 90 description: Logfiles to download … … 96 92 schema: 97 93 type: string 94 style: simple 95 explode: true 98 96 example: 'nmea0183.log,replay-test.log' 99 97 responses: … … 181 179 '500': 182 180 $ref: '#/components/responses/InternalServerError' 183 '/maps/{map} [zoom}/{x_tile}/{y_tile}.png':181 '/maps/{map}/{zoom}/{x_tile}/{y_tile}.png': 184 182 get: 185 183 description: Get tiles of a map with help of it's tiles urls … … 413 411 items: 414 412 $ref: '#/components/schemas/Logfile' 415 Map:413 map: 416 414 title: Represents a Map 417 415 description: Following the tilejson specification https://github.com/mapbox Version 2.0.0 … … 494 492 type: array 495 493 items: 496 $ref: '#/components/schemas/ Map'494 $ref: '#/components/schemas/map' 497 495 itemName: 498 496 title: Item Name -
src/gnuboat/mapservice_impl/Config.py
r691c4ca rf9321aa 19 19 from pathlib import Path 20 20 import os 21 import yaml22 23 24 def load_from_file(config_file):25 config_from_file = yaml.safe_load(open(config_file))26 config = Config()27 28 for entry in config_from_file:29 setattr(config, entry, config_from_file[entry])30 31 return config32 21 33 22 -
src/gnuboat/mapservice_impl/__init__.py
r691c4ca rf9321aa 44 44 config_object = load_config_object(os.environ['FLASK_ENV'].title()) 45 45 elif os.path.isfile(config_file): 46 from . import Config as configure 47 config_object = configure.load_from_file(config_file) 46 from gnuboat.common.webservice import Config as configure 47 config_object = configure.config_from_file(config_file, 48 load_config_object('')) 48 49 else: 49 50 config_object = load_config_object('Production') -
src/gnuboat/mapservice_impl/controllers/DevicesController.py
r691c4ca rf9321aa 1 1 ''' 2 Copyright (C) 2019 EngSaS - Langenbach. All rights reserved.2 Copyright (C) 2019 - 2020 EngSaS - Langenbach. All rights reserved. 3 3 4 4 This program is free software: you can redistribute it and/or modify … … 18 18 19 19 from gnuboat.mapservice_impl.database.Model import User, Device, db 20 from gnuboat. mapservice_impl.HttpErrors import (21 MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound20 from gnuboat.common.webservice.HttpErrors import ( 21 GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound 22 22 ) 23 23 … … 28 28 user = User.loggedin_user() 29 29 if user is None: 30 raise MapserviceUnauthorized30 raise GnuboatUnauthorized 31 31 32 32 query = Device.query.filter_by(owner=user) … … 43 43 user = User.loggedin_user() 44 44 if user is None: 45 raise MapserviceUnauthorized45 raise GnuboatUnauthorized 46 46 47 47 device = Device.query.filter_by(owner=user).filter_by(id=id).all() 48 48 if len(device) != 1: 49 raise MapserviceNotFound49 raise GnuboatNotFound 50 50 return device[0].to_dict() 51 51 … … 54 54 user = User.loggedin_user() 55 55 if user is None: 56 raise MapserviceUnauthorized56 raise GnuboatUnauthorized 57 57 58 58 comment = "" … … 74 74 user = User.loggedin_user() 75 75 if user is None: 76 raise MapserviceUnauthorized76 raise GnuboatUnauthorized 77 77 78 78 if not Device.query.filter_by(owner=user).filter_by(id=id).delete(): 79 raise MapserviceBadRequest(79 raise GnuboatBadRequest( 80 80 detail="Could not delete device with id {}".format(id) 81 81 ) -
src/gnuboat/mapservice_impl/controllers/LogsController.py
r691c4ca rf9321aa 21 21 Water, Device, Gauge, ProcessingStatus, Queue, db 22 22 ) 23 from gnuboat. mapservice_impl.HttpErrors import (24 MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound23 from gnuboat.common.webservice.HttpErrors import ( 24 GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound 25 25 ) 26 26 from gnuboat.mapservice_impl.tasks.tasks import log_process … … 33 33 submitter = User.query.filter_by(username=submitter).all() 34 34 if len(submitter) != 1: 35 raise MapserviceNotFound(35 raise GnuboatNotFound( 36 36 detail="Could not find the submitter with id {}". 37 37 format(submitter) … … 55 55 log = Log.query.filter_by(id=id).all() 56 56 if len(log) != 1: 57 raise MapserviceNotFound57 raise GnuboatNotFound 58 58 if connexion.request.headers['Accept'] == "application/geo+json": 59 59 return log[0].to_geojson(), 200, { … … 66 66 user = User.loggedin_user() 67 67 if user is None: 68 raise MapserviceUnauthorized68 raise GnuboatUnauthorized 69 69 70 70 water = Water.query.filter_by(id=log_creation.water).all() 71 71 if len(water) != 1: 72 raise MapserviceBadRequest(72 raise GnuboatBadRequest( 73 73 detail='Water {} not found database'.format(log_creation.water) 74 74 ) … … 77 77 device = Device.query.filter_by(id=log_creation.device).all() 78 78 if len(device) != 1: 79 raise MapserviceBadRequest(79 raise GnuboatBadRequest( 80 80 detail='Device {} not found in database'. 81 81 format(log_creation.device) … … 85 85 gauge = Gauge.query.filter_by(id=log_creation.gauge).all() 86 86 if len(gauge) != 1: 87 raise MapserviceBadRequest(87 raise GnuboatBadRequest( 88 88 detail='Gauge {} not found in database'.format(log_creation.gauge) 89 89 ) … … 91 91 92 92 if log_creation.gauge_height is None: 93 raise MapserviceBadRequest(detail='Gauge Height (Stage) missing')93 raise GnuboatBadRequest(detail='Gauge Height (Stage) missing') 94 94 else: 95 95 try: 96 96 float(log_creation.gauge_height) 97 97 except ValueError: 98 raise MapserviceBadRequest(98 raise GnuboatBadRequest( 99 99 detail='Gauge Height (Stage) {} is no number'. 100 100 format(log_creation.gauge_height) … … 122 122 user = User.loggedin_user() 123 123 if user is None: 124 raise MapserviceUnauthorized124 raise GnuboatUnauthorized 125 125 126 126 if body is None or not body: 127 raise MapserviceBadRequest(detail='No log data')127 raise GnuboatBadRequest(detail='No log data') 128 128 129 129 processing_state = ProcessingStatus.query.filter_by( … … 131 131 ).all() 132 132 if len(processing_state) != 1: 133 raise MapserviceBadRequest(133 raise GnuboatBadRequest( 134 134 detail='Processing status Queued for Parsing not found database' 135 135 ) … … 138 138 log = Log.query.filter_by(id=log_id).all() 139 139 if len(log) != 1: 140 raise MapserviceBadRequest(140 raise GnuboatBadRequest( 141 141 detail='Log {} not found database'.format(log_id) 142 142 ) … … 145 145 # check if Log has already log entries 146 146 if LogEntry.query.filter_by(log=log).count() > 0: 147 raise MapserviceBadRequest(147 raise GnuboatBadRequest( 148 148 detail='Log {} has already log entries. Aborting'.format(log_id) 149 149 ) … … 164 164 user = User.loggedin_user() 165 165 if user is None: 166 raise MapserviceUnauthorized166 raise GnuboatUnauthorized 167 167 168 168 if not Log.query.filter_by(submitter=user).filter_by(id=id).delete(): 169 raise MapserviceBadRequest(169 raise GnuboatBadRequest( 170 170 detail="Could not delete log with id {}".format(id) 171 171 ) -
src/gnuboat/mapservice_impl/controllers/TilesController.py
r691c4ca rf9321aa 20 20 import os 21 21 22 from gnuboat. mapservice_impl.HttpErrors import (23 MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound22 from gnuboat.common.webservice.HttpErrors import ( 23 GnuboatInternalServerError, GnuboatBadRequest, GnuboatNotFound 24 24 ) 25 25 … … 29 29 flask.current_app.config['TILES_CACHE_PATH'], os.R_OK 30 30 ): 31 raise MapserviceInternalServerError(31 raise GnuboatInternalServerError( 32 32 detail='TILES_CACHE_PATH not configured or not accessible' 33 33 ) … … 35 35 36 36 if 'TILES_DENSITIES' not in flask.current_app.config: 37 raise MapserviceInternalServerError(38 detail s='TILES_DENSITIES not configured'37 raise GnuboatInternalServerError( 38 detail='TILES_DENSITIES not configured' 39 39 ) 40 40 tiles_densities = flask.current_app.config['TILES_DENSITIES'] 41 41 42 42 if 'TILES_DENSITY_BASEE' not in flask.current_app.config: 43 raise MapserviceInternalServerError(44 detail s='TILES_DENSITY_BASEE not configured'43 raise GnuboatInternalServerError( 44 detail='TILES_DENSITY_BASEE not configured' 45 45 ) 46 46 tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE'] 47 47 48 48 if 'TILES_SKIP_EMPTY' not in flask.current_app.config: 49 raise MapserviceInternalServerError(50 detail s='TILES_SKIP_EMPTY not configured'49 raise GnuboatInternalServerError( 50 detail='TILES_SKIP_EMPTY not configured' 51 51 ) 52 52 tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY'] … … 57 57 accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base) 58 58 else: 59 raise MapserviceBadRequest(60 detail s=('No valid accuracy requested. '59 raise GnuboatBadRequest( 60 detail=('No valid accuracy requested. ' 61 61 'Valid are high, low. Requested was: {}') 62 62 .format(accuracy) … … 73 73 if not os.path.isfile(tile_path): 74 74 if not tiles_skip_empty or not os.path.isfile(tile__empty_path): 75 raise MapserviceNotFound(75 raise GnuboatNotFound( 76 76 detail=('Tile ({}, {}) for accuracy {} with resolution {} ' 77 77 'at zoomlevel {} not found') -
src/gnuboat/mapservice_impl/controllers/UsersController.py
r691c4ca rf9321aa 26 26 from gnuboat.mapservice_impl import mail 27 27 from gnuboat.mapservice_impl.database.Model import User, ApiKey, db 28 from gnuboat. mapservice_impl.HttpErrors import (29 MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound28 from gnuboat.common.webservice.HttpErrors import ( 29 GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound 30 30 ) 31 31 … … 51 51 user = User.loggedin_user() 52 52 if user is None: 53 raise MapserviceUnauthorized53 raise GnuboatUnauthorized 54 54 55 55 api_key = hashlib.md5( … … 70 70 user = User.loggedin_user() 71 71 if user is None: 72 raise MapserviceUnauthorized72 raise GnuboatUnauthorized 73 73 74 74 if not ApiKey.query.filter_by(key=api_key).delete(): 75 raise MapserviceBadRequest(75 raise GnuboatBadRequest( 76 76 detail="Could not delete api key {}".format(api_key) 77 77 ) … … 87 87 user = User.loggedin_user() 88 88 if user is None: 89 raise MapserviceUnauthorized89 raise GnuboatUnauthorized 90 90 91 91 return user_to_dict(user) … … 94 94 def users_register(user_creation): 95 95 if user_creation is None: 96 raise MapserviceBadRequest(detail='No data specified')96 raise GnuboatBadRequest(detail='No data specified') 97 97 if user_creation.username is None or not user_creation.username: 98 raise MapserviceBadRequest(detail='No username given')98 raise GnuboatBadRequest(detail='No username given') 99 99 if user_creation.password is None or not user_creation.password: 100 raise MapserviceBadRequest(detail='No password given')100 raise GnuboatBadRequest(detail='No password given') 101 101 if user_creation.first_name is None or not user_creation.first_name: 102 raise MapserviceBadRequest(detail='No first name given')102 raise GnuboatBadRequest(detail='No first name given') 103 103 if user_creation.last_name is None or not user_creation.last_name: 104 raise MapserviceBadRequest(detail='No last name given')104 raise GnuboatBadRequest(detail='No last name given') 105 105 if user_creation.email is None or not user_creation.email: 106 raise MapserviceBadRequest(detail='No email given')106 raise GnuboatBadRequest(detail='No email given') 107 107 if not mail_regex.match(user_creation.email): 108 raise MapserviceBadRequest(108 raise GnuboatBadRequest( 109 109 detail='Email contains more than one @, no @ or no .' 110 110 ) 111 111 if (user_creation.license_accepted is None or 112 112 not user_creation.license_accepted): 113 raise MapserviceBadRequest(113 raise GnuboatBadRequest( 114 114 detail='You must accept the license to register an account' 115 115 ) -
src/gnuboat/mapservice_impl/controllers/WatersController.py
r691c4ca rf9321aa 1 1 ''' 2 Copyright (C) 2019 EngSaS - Langenbach. All rights reserved.2 Copyright (C) 2019 - 2020 EngSaS - Langenbach. All rights reserved. 3 3 4 4 This program is free software: you can redistribute it and/or modify … … 18 18 19 19 from gnuboat.mapservice_impl.database.Model import User, Water, Gauge, Log, db 20 from gnuboat. mapservice_impl.HttpErrors import (21 MapserviceBadRequest,22 MapserviceUnauthorized, MapserviceNotFound20 from gnuboat.common.webservice.HttpErrors import ( 21 GnuboatBadRequest, 22 GnuboatUnauthorized, GnuboatNotFound 23 23 ) 24 24 … … 37 37 manager = User.query.filter_by(username=manager).all() 38 38 if len(manager) != 1: 39 raise MapserviceNotFound(39 raise GnuboatNotFound( 40 40 detail="Could not find the manager with id {}".format(manager) 41 41 ) … … 56 56 stakeholder = User.query.filter_by(username=stakeholder).all() 57 57 if len(stakeholder) != 1: 58 raise MapserviceNotFound(details='Stakeholder not found')58 raise GnuboatNotFound(detail='Stakeholder not found') 59 59 stakeholder = stakeholder[0] 60 60 … … 91 91 water = Water.query.filter_by(id=id).all() 92 92 if len(water) != 1: 93 raise MapserviceNotFound93 raise GnuboatNotFound 94 94 return water[0].to_dict() 95 95 … … 98 98 user = User.loggedin_user() 99 99 if user is None: 100 raise MapserviceUnauthorized100 raise GnuboatUnauthorized 101 101 102 102 water = Water( … … 114 114 water = Water.query.filter_by(id=water_id).all() 115 115 if len(water) != 1: 116 raise MapserviceBadRequest(116 raise GnuboatBadRequest( 117 117 detail="Water with id {} not found".format(water_id) 118 118 ) … … 121 121 gauge = Gauge.query.filter_by(water=water).filter_by(id=gauge_id).all() 122 122 if len(gauge) != 1: 123 raise MapserviceNotFound(123 raise GnuboatNotFound( 124 124 detail="Did not find gauge with id {} for water {}". 125 125 format(gauge_id, water.name) … … 135 135 user = User.loggedin_user() 136 136 if user is None: 137 raise MapserviceUnauthorized137 raise GnuboatUnauthorized 138 138 139 139 water = Water.query.filter_by(id=water_id).all() 140 140 if len(water) != 1: 141 raise MapserviceBadRequest(141 raise GnuboatBadRequest( 142 142 detail="Did not find water with id {}".format(water_id) 143 143 ) … … 164 164 water = Water.query.filter_by(id=water_id).all() 165 165 if len(water) != 1: 166 raise MapserviceBadRequest(166 raise GnuboatBadRequest( 167 167 detail="Did not find water with id {}".format(water_id) 168 168 ) … … 173 173 manager = User.query.filter_by(username=manager).all() 174 174 if len(manager) != 1: 175 raise MapserviceNotFound(175 raise GnuboatNotFound( 176 176 detail="Could not find the manager with id {}".format(manager) 177 177 ) -
src/gnuboat/mapservice_impl/demo/DbSetup.py
r691c4ca rf9321aa 23 23 db, User, ApiKey, Water, 24 24 OsmType, Gauge, Device, Log, Queue, ProcessingStatus, db_setup 25 ) 26 from gnuboat.common.webservice.HttpErrors import ( 27 GnuboatBadRequest 25 28 ) 26 29 from gnuboat.mapservice_impl.tasks.tasks import log_process … … 200 203 ).all() 201 204 if len(processing_state) != 1: 202 raise MapserviceBadRequest(205 raise GnuboatBadRequest( 203 206 detail='Processing status Queued for Parsing not found database' 204 207 )
Note:
See TracChangeset
for help on using the changeset viewer.
