Merge "Implemented api config module"

This commit is contained in:
Jenkins
2016-12-14 10:20:48 +00:00
committed by Gerrit Code Review
6 changed files with 82 additions and 54 deletions

View File

@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# #
# Copyright © 2012 New Dream Network, LLC (DreamHost) # Copyright © 2012 New Dream Network, LLC (DreamHost)
# Copyright (c) 2016 Intel Corp
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # 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.""" """Access Control Lists (ACL's) control access the API server."""
from oslo_config import cfg
from watcher.api.middleware import auth_token from watcher.api.middleware import auth_token
from watcher import conf
CONF = conf.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)
def install(app, conf, public_routes): def install(app, conf, public_routes):
@@ -42,7 +34,7 @@ def install(app, conf, public_routes):
:return: The same WSGI application with ACL installed. :return: The same WSGI application with ACL installed.
""" """
if not cfg.CONF.get('enable_authentication'): if not CONF.get('enable_authentication'):
return app return app
return auth_token.AuthTokenMiddleware(app, return auth_token.AuthTokenMiddleware(app,
conf=dict(conf), conf=dict(conf),

View File

@@ -2,6 +2,7 @@
# Copyright © 2012 New Dream Network, LLC (DreamHost) # Copyright © 2012 New Dream Network, LLC (DreamHost)
# All Rights Reserved. # All Rights Reserved.
# Copyright (c) 2016 Intel Corp
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
@@ -16,49 +17,14 @@
# under the License. # under the License.
from oslo_config import cfg
import pecan import pecan
from watcher._i18n import _
from watcher.api import acl from watcher.api import acl
from watcher.api import config as api_config from watcher.api import config as api_config
from watcher.api import middleware from watcher.api import middleware
from watcher import conf
# Register options for the service CONF = conf.CONF
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)
def get_pecan_config(): def get_pecan_config():

View File

@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>com # Copyright (c) 2016 b<>com
# Copyright (c) 2016 Intel Corp
# #
# Authors: Vincent FRANCOISE <vincent.francoise@b-com.com> # Authors: Vincent FRANCOISE <vincent.francoise@b-com.com>
# #
@@ -18,8 +19,10 @@
from oslo_config import cfg from oslo_config import cfg
from watcher.conf import api
from watcher.conf import service from watcher.conf import service
CONF = cfg.CONF CONF = cfg.CONF
service.register_opts(CONF) service.register_opts(CONF)
api.register_opts(CONF)

View File

@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# Copyright 2014 # Copyright 2014
# The Cloudscaling Group, Inc. # The Cloudscaling Group, Inc.
# Copyright (c) 2016 Intel Corp
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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 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.applier import manager as applier_manager
from watcher.common import clients from watcher.common import clients
from watcher.common import exception from watcher.common import exception
from watcher.common import paths from watcher.common import paths
from watcher.conf import api as conf_api
from watcher.db.sqlalchemy import models from watcher.db.sqlalchemy import models
from watcher.decision_engine.audit import continuous from watcher.decision_engine.audit import continuous
from watcher.decision_engine import manager as decision_engine_manager 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""" """Legacy aggregation of all the watcher config options"""
return [ return [
('DEFAULT', ('DEFAULT',
(api_app.API_SERVICE_OPTS + (conf_api.AUTH_OPTS +
api_acl.AUTH_OPTS +
exception.EXC_LOG_OPTS + exception.EXC_LOG_OPTS +
paths.PATH_OPTS)), paths.PATH_OPTS)),
('api', api_app.API_SERVICE_OPTS), ('api', conf_api.API_SERVICE_OPTS),
('database', models.SQL_OPTS), ('database', models.SQL_OPTS),
('watcher_decision_engine', ('watcher_decision_engine',
(decision_engine_manager.WATCHER_DECISION_ENGINE_OPTS + (decision_engine_manager.WATCHER_DECISION_ENGINE_OPTS +

67
watcher/conf/api.py Normal file
View File

@@ -0,0 +1,67 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 Intel Corp
#
# Authors: Prudhvi Rao Shedimbi <prudhvi.rao.shedimbi@intel.com>
#
# 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)]

View File

@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# Copyright (c) 2015 b<>com # Copyright (c) 2015 b<>com
# Copyright (c) 2016 Intel Corp
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.