diff options
author | asteroide <thomas.duval@orange.com> | 2016-04-25 11:25:28 +0200 |
---|---|---|
committer | asteroide <thomas.duval@orange.com> | 2016-04-25 11:25:28 +0200 |
commit | 8d291f5a3de6fdffea6144b4c0f5ed44411285f5 (patch) | |
tree | f9edcf68d61cbe2cf0eb9807403964cdbf9d3730 /keystone-moon/keystone/contrib | |
parent | 8c6291c915bd9f806600642b188f2bbb5fc716bc (diff) |
Add the /moon/auth/tokens API
Change-Id: I4c0dd7c0e3f4dcae8d122c466cf93ac28d7c37f6
Diffstat (limited to 'keystone-moon/keystone/contrib')
-rw-r--r-- | keystone-moon/keystone/contrib/moon/controllers.py | 40 | ||||
-rw-r--r-- | keystone-moon/keystone/contrib/moon/routers.py | 8 |
2 files changed, 47 insertions, 1 deletions
diff --git a/keystone-moon/keystone/contrib/moon/controllers.py b/keystone-moon/keystone/contrib/moon/controllers.py index 0abe31be..248aea34 100644 --- a/keystone-moon/keystone/contrib/moon/controllers.py +++ b/keystone-moon/keystone/contrib/moon/controllers.py @@ -4,12 +4,13 @@ # or at 'http://www.apache.org/licenses/LICENSE-2.0'. from keystone.common import controller -from keystone.common import dependency from keystone import config from keystone.models import token_model from keystone.contrib.moon.exception import * from oslo_log import log from uuid import uuid4 +import requests + CONF = config.CONF LOG = log.getLogger(__name__) @@ -831,3 +832,40 @@ class Logs(controller.V3Controller): options = kw.get('options', '') return self.moonlog_api.get_logs(user_id, options) + +class MoonAuth(controller.V3Controller): + + def __init__(self): + super(MoonAuth, self).__init__() + + def get_token(self, context, **kw): + data_auth = { + "auth": { + "identity": { + "methods": [ + "password" + ], + "password": { + "user": { + "domain": { + "id": "Default" + }, + "name": kw['username'], + "password": kw['password'] + } + } + } + } + } + + req = requests.post("http://localhost:5000/v3/auth/tokens", + json=data_auth, + headers={"Content-Type": "application/json"} + ) + if req.status_code not in (200, 201): + LOG.error(req.text) + else: + TOKEN = req.headers['X-Subject-Token'] + return {"token": TOKEN, 'message': ""} + return {"token": None, 'message': req.text} + diff --git a/keystone-moon/keystone/contrib/moon/routers.py b/keystone-moon/keystone/contrib/moon/routers.py index fd821a49..c3bb7df0 100644 --- a/keystone-moon/keystone/contrib/moon/routers.py +++ b/keystone-moon/keystone/contrib/moon/routers.py @@ -36,6 +36,7 @@ class Routers(wsgi.ComposableRouter): intra_ext_controller = controllers.IntraExtensions() tenants_controller = controllers.Tenants() logs_controller = controllers.Logs() + auth_controller = controllers.MoonAuth() inter_ext_controller = controllers.InterExtensions() # Configuration route @@ -480,6 +481,13 @@ class Routers(wsgi.ComposableRouter): action='get_logs', conditions=dict(method=['GET'])) + # Auth route + mapper.connect( + self.PATH_PREFIX+'/auth/tokens', + controller=auth_controller, + action='get_token', + conditions=dict(method=['POST'])) + # InterExtensions route # mapper.connect( # controller=inter_ext_controller, |