Refactor: Use Federation constants where possible

There was a couple of FIXME notes (from
If5857a6ee4c7c527929069b25beab40f4c5d87e2) asking
to use federation constants rather than hardcoded
string values.

This patch fixes those notes.

Change-Id: If000976d693b72fe184073568d0995c6c25846c7
This commit is contained in:
Samuel de Medeiros Queiroz 2015-12-03 09:40:31 -03:00
parent e64a1b5891
commit 846b4ce539
2 changed files with 9 additions and 8 deletions

View File

@ -29,6 +29,7 @@ from keystone.common import dependency
from keystone.common import utils
from keystone.common import wsgi
from keystone import exception
from keystone.federation import constants
from keystone.i18n import _, _LI, _LW
from keystone.resource import controllers as resource_controllers
@ -422,8 +423,7 @@ class Auth(controller.V3Controller):
return
# Skip scoping when unscoped federated token is being issued
# FIXME(stevemar): Use constants from keystone.federation.constants
if 'OS-FEDERATION:identity_provider' in auth_context:
if constants.IDENTITY_PROVIDER in auth_context:
return
# Do not scope if request is for explicitly unscoped token

View File

@ -18,10 +18,9 @@ from oslo_utils import timeutils
import six
from keystone import exception
from keystone.federation import constants
from keystone.i18n import _
# FIXME(stevemar): Use constants from keystone.federation.constants
OS_FEDERATION = 'OS-FEDERATION'
CONF = cfg.CONF
# supported token versions
V2 = 'v2.0'
@ -297,7 +296,8 @@ class KeystoneToken(dict):
@property
def is_federated_user(self):
try:
return (self.version is V3 and OS_FEDERATION in self['user'])
return (self.version is V3 and
constants.FEDERATION in self['user'])
except KeyError:
raise exception.UnexpectedError()
@ -306,7 +306,8 @@ class KeystoneToken(dict):
if self.is_federated_user:
if self.version is V3:
try:
groups = self['user'][OS_FEDERATION].get('groups', [])
groups = self['user'][constants.FEDERATION].get(
'groups', [])
return [g['id'] for g in groups]
except KeyError:
raise exception.UnexpectedError()
@ -316,12 +317,12 @@ class KeystoneToken(dict):
def federation_idp_id(self):
if self.version is not V3 or not self.is_federated_user:
return None
return self['user'][OS_FEDERATION]['identity_provider']['id']
return self['user'][constants.FEDERATION]['identity_provider']['id']
@property
def federation_protocol_id(self):
if self.version is V3 and self.is_federated_user:
return self['user'][OS_FEDERATION]['protocol']['id']
return self['user'][constants.FEDERATION]['protocol']['id']
return None
@property