Coverage for watcher/api/app.py: 86%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-17 12:22 +0000

1# -*- encoding: utf-8 -*- 

2 

3# Copyright © 2012 New Dream Network, LLC (DreamHost) 

4# All Rights Reserved. 

5# Copyright (c) 2016 Intel Corp 

6# 

7# Licensed under the Apache License, Version 2.0 (the "License"); you may 

8# not use this file except in compliance with the License. You may obtain 

9# a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

16# License for the specific language governing permissions and limitations 

17# under the License. 

18 

19 

20import pecan 

21 

22from watcher.api import acl 

23from watcher.api import config as api_config 

24from watcher.api.middleware import parsable_error 

25from watcher import conf 

26 

27CONF = conf.CONF 

28 

29 

30def get_pecan_config(): 

31 # Set up the pecan configuration 

32 return pecan.configuration.conf_from_dict(api_config.PECAN_CONFIG) 

33 

34 

35def setup_app(config=None): 

36 if not config: 36 ↛ 37line 36 didn't jump to line 37 because the condition on line 36 was never true

37 config = get_pecan_config() 

38 

39 app_conf = dict(config.app) 

40 

41 app = pecan.make_app( 

42 app_conf.pop('root'), 

43 logging=getattr(config, 'logging', {}), 

44 debug=CONF.debug, 

45 wrap_app=parsable_error.ParsableErrorMiddleware, 

46 **app_conf 

47 ) 

48 

49 return acl.install(app, CONF, config.app.acl_public_routes) 

50 

51 

52class VersionSelectorApplication(object): 

53 def __init__(self): 

54 pc = get_pecan_config() 

55 self.v1 = setup_app(config=pc) 

56 

57 def __call__(self, environ, start_response): 

58 return self.v1(environ, start_response)