add noauth api pipeline

Change-Id: Ib12fa4270c6780338cb9eba486833c32f3809c27
This commit is contained in:
gord chung 2017-05-25 17:42:42 +00:00
parent 4d21a8d943
commit 36da6822c5
8 changed files with 53 additions and 95 deletions

View File

@ -1,14 +1,29 @@
# Panko API WSGI Pipeline
# Define the filters that make up the pipeline for processing WSGI requests
# Note: This pipeline is PasteDeploy's term rather than Panko's pipeline
# used for processing samples
[composite:panko+noauth]
use = egg:Paste#urlmap
/ = pankoversions_pipeline
/v2 = pankov2_noauth_pipeline
# Remove authtoken from the pipeline if you don't want to use keystone authentication
[pipeline:main]
pipeline = cors http_proxy_to_wsgi request_id authtoken api-server
[composite:panko+keystone]
use = egg:Paste#urlmap
/ = pankoversions_pipeline
/v2 = pankov2_keystone_pipeline
[app:api-server]
[pipeline:pankoversions_pipeline]
pipeline = cors http_proxy_to_wsgi pankoversions
[app:pankoversions]
paste.app_factory = panko.api.app:app_factory
root = panko.api.controllers.root.VersionsController
[pipeline:pankov2_keystone_pipeline]
pipeline = cors http_proxy_to_wsgi request_id authtoken pankov2
[pipeline:pankov2_noauth_pipeline]
pipeline = cors http_proxy_to_wsgi request_id pankov2
[app:pankov2]
paste.app_factory = panko.api.app:app_factory
root = panko.api.controllers.v2.root.V2Controller
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory

View File

@ -14,10 +14,10 @@
# under the License.
import os
import uuid
from oslo_config import cfg
from oslo_log import log
from oslo_utils import uuidutils
from paste import deploy
import pecan
@ -28,32 +28,18 @@ from panko import service
LOG = log.getLogger(__name__)
def setup_app(pecan_config=None, conf=None):
if conf is None:
raise RuntimeError("No configuration passed")
# FIXME: Replace DBHook with a hooks.TransactionHook
def setup_app(root, conf):
app_hooks = [hooks.ConfigHook(conf),
hooks.DBHook(conf),
hooks.TranslationHook()]
pecan_config = pecan_config or {
"app": {
'root': 'panko.api.controllers.root.RootController',
'modules': ['panko.api'],
}
}
pecan.configuration.set_config(dict(pecan_config), overwrite=True)
app = pecan.make_app(
pecan_config['app']['root'],
return pecan.make_app(
root,
hooks=app_hooks,
wrap_app=middleware.ParsableErrorMiddleware,
guess_content_type_from_ext=False
)
return app
# NOTE(sileht): pastedeploy uses ConfigParser to handle
# global_conf, since python 3 ConfigParser doesn't
@ -65,25 +51,23 @@ global APPCONFIGS
APPCONFIGS = {}
def load_app(conf):
def load_app(conf, appname='panko+keystone'):
global APPCONFIGS
# Build the WSGI app
cfg_file = None
cfg_path = conf.api_paste_config
if not os.path.isabs(cfg_path):
cfg_file = conf.find_file(cfg_path)
elif os.path.exists(cfg_path):
cfg_file = cfg_path
cfg_path = conf.find_file(cfg_path)
if not cfg_file:
if cfg_path is None or not os.path.exists(cfg_path):
raise cfg.ConfigFilesNotFoundError([conf.api_paste_config])
configkey = uuidutils.generate_uuid()
APPCONFIGS[configkey] = conf
config = dict(conf=conf)
configkey = str(uuid.uuid4())
APPCONFIGS[configkey] = config
LOG.info("Full WSGI config used: %s" % cfg_file)
return deploy.loadapp("config:" + cfg_file,
LOG.info("Full WSGI config used: %s" % cfg_path)
return deploy.loadapp("config:" + cfg_path, name=appname,
global_conf={'configkey': configkey})
@ -94,4 +78,4 @@ def build_wsgi_app(argv=None):
def app_factory(global_config, **local_conf):
global APPCONFIGS
conf = APPCONFIGS.get(global_config.get('configkey'))
return setup_app(conf=conf)
return setup_app(root=local_conf.get('root'), **conf)

View File

@ -15,16 +15,11 @@
import pecan
from panko.api.controllers.v2 import root as v2
MEDIA_TYPE_JSON = 'application/vnd.openstack.telemetry-%s+json'
MEDIA_TYPE_XML = 'application/vnd.openstack.telemetry-%s+xml'
class RootController(object):
def __init__(self):
self.v2 = v2.V2Controller()
class VersionsController(object):
@pecan.expose('json')
def index(self):

View File

@ -16,9 +16,9 @@
"""
from oslo_policy import opts
import pecan
import pecan.testing
import webtest
from panko.api import app
from panko.api import rbac
from panko import service
from panko.tests import db as db_test_base
@ -41,27 +41,17 @@ class FunctionalTest(db_test_base.TestBase):
self.CONF.set_override("policy_file",
self.path_get('etc/panko/policy.json'),
group='oslo_policy')
self.CONF.set_override('api_paste_config',
self.path_get('etc/panko/api_paste.ini'))
self.app = self._make_app(self.CONF)
def _make_app(self, conf, enable_acl=False):
self.config = {
'app': {
'root': 'panko.api.controllers.root.RootController',
'modules': ['panko.api'],
'enable_acl': enable_acl,
},
'wsme': {
'debug': True,
},
}
return pecan.testing.load_test_app(self.config, conf=conf)
@staticmethod
def _make_app(conf):
return webtest.TestApp(app.load_app(conf, appname='panko+noauth'))
def tearDown(self):
super(FunctionalTest, self).tearDown()
rbac.reset()
pecan.set_config({}, overwrite=True)
def put_json(self, path, params, expect_errors=False, headers=None,
extra_environ=None, status=None):

View File

@ -63,10 +63,9 @@ class TestAPIACL(v2.FunctionalTest):
q=q or [],
**params)
def _make_app(self, conf):
file_name = self.path_get('etc/panko/api_paste.ini')
conf.set_override("api_paste_config", file_name)
return webtest.TestApp(app.load_app(conf=conf))
@staticmethod
def _make_app(conf):
return webtest.TestApp(app.load_app(conf, appname='panko+keystone'))
class TestAPIEventACL(TestAPIACL):
@ -128,7 +127,7 @@ class TestBaseApiEventRBAC(v2.FunctionalTest):
class TestApiEventAdminRBAC(TestBaseApiEventRBAC):
def _make_app(self, conf, enable_acl=False):
def _make_app(self, conf):
content = ('{"context_is_admin": "role:admin",'
'"telemetry:events:index": "rule:context_is_admin",'
'"telemetry:events:show": "rule:context_is_admin"}')
@ -138,9 +137,8 @@ class TestApiEventAdminRBAC(TestBaseApiEventRBAC):
prefix='policy',
suffix='.json')
self.CONF.set_override("policy_file", self.tempfile,
group='oslo_policy')
return super(TestApiEventAdminRBAC, self)._make_app(conf)
conf.set_override("policy_file", self.tempfile, group='oslo_policy')
return webtest.TestApp(app.load_app(conf, appname='panko+noauth'))
def tearDown(self):
os.remove(self.tempfile)

View File

@ -75,8 +75,7 @@ class ConfigFixture(fixture.GabbiFixture):
group='oslo_policy')
conf.set_override(
'api_paste_config',
os.path.abspath(
'panko/tests/functional/gabbi/gabbi_paste.ini')
os.path.abspath('etc/panko/api_paste.ini')
)
parsed_url = list(urlparse.urlparse(db_url))
@ -93,7 +92,7 @@ class ConfigFixture(fixture.GabbiFixture):
self.conn.upgrade()
LOAD_APP_KWARGS = {
'conf': conf,
'conf': conf, 'appname': 'panko+noauth',
}
def stop_fixture(self):

View File

@ -1,24 +0,0 @@
# Panko API WSGI Pipeline
# Define the filters that make up the pipeline for processing WSGI requests
# Note: This pipeline is PasteDeploy's term rather than Panko's pipeline
# used for processing samples
#
# This version is specific for gabbi. It removes support for keystone while
# keeping support for CORS.
# Remove authtoken from the pipeline if you don't want to use keystone authentication
[pipeline:main]
pipeline = cors api-server
[app:api-server]
paste.app_factory = panko.api.app:app_factory
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
[filter:request_id]
paste.filter_factory = oslo_middleware:RequestId.factory
[filter:cors]
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = panko

View File

@ -12,6 +12,7 @@ oslo.i18n>=2.1.0 # Apache-2.0
oslo.log>=1.14.0 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0
oslo.reports>=0.6.0 # Apache-2.0
Paste
PasteDeploy>=1.5.0 # MIT
pbr>=1.6 # Apache-2.0
pecan>=1.0.0 # BSD