Create region with payload authentication
Change-Id: I237d1df49082801e24e4cc55b22074aed5809f19
This commit is contained in:
parent
265761babd
commit
cda08c8d59
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from orm.common.client.keystone.keystone_utils import tokens
|
from orm.common.client.keystone.keystone_utils import tokens
|
||||||
@ -23,14 +24,19 @@ def authorize(request, action, skip_auth=False):
|
|||||||
if not _is_authorization_enabled(conf) or skip_auth:
|
if not _is_authorization_enabled(conf) or skip_auth:
|
||||||
return
|
return
|
||||||
|
|
||||||
auth_region = request.headers.get('X-Auth-Region')
|
use_payload_url =\
|
||||||
|
action == 'region:create' or action == 'region:update'
|
||||||
|
keystone_ep = None
|
||||||
try:
|
try:
|
||||||
|
if use_payload_url:
|
||||||
|
keystone_ep = _get_request_keystone_ep(request)
|
||||||
|
if not keystone_ep:
|
||||||
|
auth_region = request.headers.get('X-Auth-Region')
|
||||||
keystone_ep = get_keystone_ep(auth_region)
|
keystone_ep = get_keystone_ep(auth_region)
|
||||||
except Exception:
|
except Exception:
|
||||||
# Failed to find Keystone EP - we'll set it to None instead of failing
|
# Failed to find Keystone EP - we'll set it to None instead of failing
|
||||||
# because the rule might be to let everyone pass
|
# because the rule might be to let everyone pass
|
||||||
keystone_ep = None
|
keystone_ep = None
|
||||||
|
|
||||||
policy.authorize(action, request, conf, keystone_ep=keystone_ep)
|
policy.authorize(action, request, conf, keystone_ep=keystone_ep)
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +54,22 @@ def get_token_conf(app_conf):
|
|||||||
user_domain_name = app_conf.authentication.user_domain_name
|
user_domain_name = app_conf.authentication.user_domain_name
|
||||||
project_domain_name = app_conf.authentication.project_domain_name
|
project_domain_name = app_conf.authentication.project_domain_name
|
||||||
conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name,
|
conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name,
|
||||||
keystone_version, user_domain_name, project_domain_name)
|
keystone_version, user_domain_name,
|
||||||
|
project_domain_name)
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
|
def _get_request_keystone_ep(request):
|
||||||
|
keystone_ep = None
|
||||||
|
try:
|
||||||
|
request_body = request.body if request.body else {}
|
||||||
|
endpoints = json.loads(request_body).get('endpoints')
|
||||||
|
endpoint_url = [endpoint.get('publicURL')
|
||||||
|
for endpoint in endpoints
|
||||||
|
if endpoint.get('type') == 'identity']
|
||||||
|
keystone_ep = endpoint_url[0] if endpoint_url else None
|
||||||
|
except Exception:
|
||||||
|
keystone_ep = None
|
||||||
|
|
||||||
|
return keystone_ep
|
||||||
|
Loading…
Reference in New Issue
Block a user