From 8e7ba3c44ad25b38e034a770a6acf62b651b2769 Mon Sep 17 00:00:00 2001 From: Prudhvi Rao Shedimbi Date: Mon, 21 Nov 2016 18:08:01 +0000 Subject: [PATCH] Implemented api config module Implemented api config module Partially Implements: blueprint centralise-config-opts Change-Id: I055618e546bb1bfa2c1764bcff1a1f94e5adea96 --- watcher/api/acl.py | 16 ++----- watcher/api/app.py | 40 ++--------------- watcher/conf/__init__.py | 3 ++ watcher/conf/_opts.py | 9 ++-- watcher/conf/api.py | 67 ++++++++++++++++++++++++++++ watcher/tests/conf/test_list_opts.py | 1 + 6 files changed, 82 insertions(+), 54 deletions(-) create mode 100644 watcher/conf/api.py diff --git a/watcher/api/acl.py b/watcher/api/acl.py index 82a0f236b..75b8019b2 100644 --- a/watcher/api/acl.py +++ b/watcher/api/acl.py @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- # # Copyright © 2012 New Dream Network, LLC (DreamHost) +# Copyright (c) 2016 Intel Corp # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -17,19 +18,10 @@ """Access Control Lists (ACL's) control access the API server.""" -from oslo_config import cfg from watcher.api.middleware import auth_token +from watcher import conf - -AUTH_OPTS = [ - cfg.BoolOpt('enable_authentication', - default=True, - help='This option enables or disables user authentication ' - 'via keystone. Default value is True.'), -] - -CONF = cfg.CONF -CONF.register_opts(AUTH_OPTS) +CONF = conf.CONF def install(app, conf, public_routes): @@ -42,7 +34,7 @@ def install(app, conf, public_routes): :return: The same WSGI application with ACL installed. """ - if not cfg.CONF.get('enable_authentication'): + if not CONF.get('enable_authentication'): return app return auth_token.AuthTokenMiddleware(app, conf=dict(conf), diff --git a/watcher/api/app.py b/watcher/api/app.py index 1cd03a823..7926eda4a 100644 --- a/watcher/api/app.py +++ b/watcher/api/app.py @@ -2,6 +2,7 @@ # Copyright © 2012 New Dream Network, LLC (DreamHost) # All Rights Reserved. +# Copyright (c) 2016 Intel Corp # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -16,49 +17,14 @@ # under the License. -from oslo_config import cfg import pecan -from watcher._i18n import _ from watcher.api import acl from watcher.api import config as api_config from watcher.api import middleware +from watcher import conf -# Register options for the service -API_SERVICE_OPTS = [ - cfg.PortOpt('port', - default=9322, - help=_('The port for the watcher API server')), - cfg.StrOpt('host', - default='127.0.0.1', - help=_('The listen IP for the watcher API server')), - cfg.IntOpt('max_limit', - default=1000, - help=_('The maximum number of items returned in a single ' - 'response from a collection resource')), - cfg.IntOpt('workers', - min=1, - help=_('Number of workers for Watcher API service. ' - 'The default is equal to the number of CPUs available ' - 'if that can be determined, else a default worker ' - 'count of 1 is returned.')), - - cfg.BoolOpt('enable_ssl_api', - default=False, - help=_("Enable the integrated stand-alone API to service " - "requests via HTTPS instead of HTTP. If there is a " - "front-end service performing HTTPS offloading from " - "the service, this option should be False; note, you " - "will want to change public API endpoint to represent " - "SSL termination URL with 'public_endpoint' option.")), -] - -CONF = cfg.CONF -opt_group = cfg.OptGroup(name='api', - title='Options for the watcher-api service') - -CONF.register_group(opt_group) -CONF.register_opts(API_SERVICE_OPTS, opt_group) +CONF = conf.CONF def get_pecan_config(): diff --git a/watcher/conf/__init__.py b/watcher/conf/__init__.py index a1414fc97..818ec6abb 100644 --- a/watcher/conf/__init__.py +++ b/watcher/conf/__init__.py @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- # Copyright (c) 2016 b<>com +# Copyright (c) 2016 Intel Corp # # Authors: Vincent FRANCOISE # @@ -18,8 +19,10 @@ from oslo_config import cfg +from watcher.conf import api from watcher.conf import service CONF = cfg.CONF service.register_opts(CONF) +api.register_opts(CONF) diff --git a/watcher/conf/_opts.py b/watcher/conf/_opts.py index 2d5f10d0e..6f996a59b 100644 --- a/watcher/conf/_opts.py +++ b/watcher/conf/_opts.py @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- # Copyright 2014 # The Cloudscaling Group, Inc. +# Copyright (c) 2016 Intel Corp # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +18,11 @@ from keystoneauth1 import loading as ka_loading -from watcher.api import acl as api_acl -from watcher.api import app as api_app from watcher.applier import manager as applier_manager from watcher.common import clients from watcher.common import exception from watcher.common import paths +from watcher.conf import api as conf_api from watcher.db.sqlalchemy import models from watcher.decision_engine.audit import continuous from watcher.decision_engine import manager as decision_engine_manager @@ -33,11 +33,10 @@ def list_opts(): """Legacy aggregation of all the watcher config options""" return [ ('DEFAULT', - (api_app.API_SERVICE_OPTS + - api_acl.AUTH_OPTS + + (conf_api.AUTH_OPTS + exception.EXC_LOG_OPTS + paths.PATH_OPTS)), - ('api', api_app.API_SERVICE_OPTS), + ('api', conf_api.API_SERVICE_OPTS), ('database', models.SQL_OPTS), ('watcher_decision_engine', (decision_engine_manager.WATCHER_DECISION_ENGINE_OPTS + diff --git a/watcher/conf/api.py b/watcher/conf/api.py new file mode 100644 index 000000000..ad8fa38c6 --- /dev/null +++ b/watcher/conf/api.py @@ -0,0 +1,67 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2016 Intel Corp +# +# Authors: Prudhvi Rao Shedimbi +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from oslo_config import cfg + +api = cfg.OptGroup(name='api', + title='Options for the Watcher API service') + +AUTH_OPTS = [ + cfg.BoolOpt('enable_authentication', + default=True, + help='This option enables or disables user authentication ' + 'via keystone. Default value is True.'), +] + +API_SERVICE_OPTS = [ + cfg.PortOpt('port', + default=9322, + help='The port for the watcher API server'), + cfg.StrOpt('host', + default='127.0.0.1', + help='The listen IP address for the watcher API server'), + cfg.IntOpt('max_limit', + default=1000, + help='The maximum number of items returned in a single ' + 'response from a collection resource'), + cfg.IntOpt('workers', + min=1, + help='Number of workers for Watcher API service. ' + 'The default is equal to the number of CPUs available ' + 'if that can be determined, else a default worker ' + 'count of 1 is returned.'), + + cfg.BoolOpt('enable_ssl_api', + default=False, + help="Enable the integrated stand-alone API to service " + "requests via HTTPS instead of HTTP. If there is a " + "front-end service performing HTTPS offloading from " + "the service, this option should be False; note, you " + "will want to change public API endpoint to represent " + "SSL termination URL with 'public_endpoint' option."), +] + + +def register_opts(conf): + conf.register_group(api) + conf.register_opts(API_SERVICE_OPTS, group=api) + conf.register_opts(AUTH_OPTS) + + +def list_opts(): + return [('api', API_SERVICE_OPTS), ('DEFAULT', AUTH_OPTS)] diff --git a/watcher/tests/conf/test_list_opts.py b/watcher/tests/conf/test_list_opts.py index b6c144389..3bd54138e 100644 --- a/watcher/tests/conf/test_list_opts.py +++ b/watcher/tests/conf/test_list_opts.py @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- # Copyright (c) 2015 b<>com +# Copyright (c) 2016 Intel Corp # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.