Add fake Keystone V3 API handlers

Keystone V2 API is deprecated, V3 should be used instead. This
commit adds fake Keystone V3 API handlers which can be used by
Fuel UI and Fuel CLI for development and functional tests.

Change-Id: If201c247210131ce6ab192362eada250a4f51ce1
Partial-Bug: #1628445
(cherry picked from commit 5c8cbd26e3)
This commit is contained in:
Vitaly Kramskikh 2016-09-30 15:18:18 +03:00 committed by Georgy Kibardin
parent 648aedf38e
commit 12e0c97463
3 changed files with 129 additions and 8 deletions

View File

@ -16,16 +16,27 @@
import web
from nailgun.fake_keystone.handlers import EndpointsHandler
from nailgun.fake_keystone.handlers import ServicesHandler
from nailgun.fake_keystone.handlers import TokensHandler
from nailgun.fake_keystone.handlers import VersionHandler
from nailgun.fake_keystone.v2_handlers \
import EndpointsHandler as V2EndpointsHandler
from nailgun.fake_keystone.v2_handlers \
import ServicesHandler as V2ServicesHandler
from nailgun.fake_keystone.v2_handlers \
import TokensHandler as V2TokensHandler
from nailgun.fake_keystone.v2_handlers \
import VersionHandler as V2VersionHandler
from nailgun.fake_keystone.v3_handlers \
import TokensHandler as V3TokensHandler
from nailgun.fake_keystone.v3_handlers \
import VersionHandler as V3VersionHandler
urls = (
r"/v2.0/?$", VersionHandler.__name__,
r"/v2.0/tokens/?$", TokensHandler.__name__,
r"/v2.0/OS-KSADM/services/?$", ServicesHandler.__name__,
r"/v2.0/endpoints/?$", EndpointsHandler.__name__,
r"/v2.0/?$", V2VersionHandler,
r"/v2.0/tokens/?$", V2TokensHandler,
r"/v2.0/OS-KSADM/services/?$", V2ServicesHandler,
r"/v2.0/endpoints/?$", V2EndpointsHandler,
r"/v3/?$", V3VersionHandler,
r"/v3/auth/tokens/?$", V3TokensHandler,
)
_locals = locals()

View File

@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Mirantis, Inc.
#
# 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.
import web
from nailgun.api.v1.handlers.base import BaseHandler
from nailgun.api.v1.handlers.base import handle_errors
from nailgun.api.v1.handlers.base import serialize
from nailgun.api.v1.handlers.base import validate
from nailgun.fake_keystone import generate_token
from nailgun.fake_keystone import validate_password_credentials
from nailgun.fake_keystone import validate_token
from nailgun.settings import settings
class TokensHandler(BaseHandler):
@handle_errors
@validate
@serialize
def GET(self):
token = web.ctx.env.get('HTTP_X_SUBJECT_TOKEN', '')
if not validate_token(token):
raise self.http(401)
return self._get_token_info()
@handle_errors
@validate
@serialize
def POST(self):
data = self.checked_data()
try:
if 'password' in data['auth']['identity']['methods']:
if not validate_password_credentials(
data['auth']['identity']['password']['user']['name'],
data['auth']['identity']['password']['user']['password']
):
raise self.http(401)
elif 'token' in data['auth']['identity']['methods']:
if not validate_token(data['auth']['identity']['token']['id']):
raise self.http(401)
else:
raise self.http(400)
except (KeyError, TypeError):
raise self.http(400)
web.header('X-Subject-Token', generate_token())
return self._get_token_info()
def _get_token_info(self):
return {
"token": {
"methods": ["password"],
"issued_at": "2016-09-29T13:06:37.620739Z",
"expires_at": "2016-09-29T19:06:37.620687Z",
"roles": [{"name": settings.FAKE_KEYSTONE_ROLE}],
"project": {
"domain": {"id": "123", "name": "fuel"},
"id": "456",
"name": "admin"
},
"user": {
"domain": {"id": "123", "name": "fuel"},
"id": "789",
"name": "admin"
},
"catalog": [],
"audit_ids": ["CZGk7nPaRF-PzmokqvKcDQ"]
}
}
def DELETE(self):
raise self.http(204)
class VersionHandler(BaseHandler):
@handle_errors
@validate
@serialize
def GET(self):
keystone_href = 'http://{ip_addr}:{port}/keystone/v3/'.format(
ip_addr=settings.LISTEN_ADDRESS, port=settings.LISTEN_PORT)
return {
"version": {
"id": "v3.6",
"status": "stable",
"updated": "2016-04-04T00:00:00Z",
"media-types": [{
"base": "application/json",
"type": "application/vnd.openstack.identity-v3+json"
}],
"links": [{"href": keystone_href, "rel": "self"}]
}
}