Cleanup for resource-specific options
This patch adds in the missing helper function in the sql_model for user to get an option out of _resource_option_mapper by the ID eliminating the need to access a "private" attribute directly outside of the model itself (in most cases). This also cleans up the USER_OPTIONS_REGISTRY list allowing direct access to the option constants in keystone.identity.backends.resouce_options. Change-Id: I385871499da191ea58acc4ddcafebbd94b10a489
This commit is contained in:
parent
9f4fbd88f8
commit
85e8a7bc5e
@ -14,20 +14,21 @@ from keystone.common import resource_options
|
||||
|
||||
|
||||
USER_OPTIONS_REGISTRY = resource_options.ResourceOptionRegistry('USER')
|
||||
USER_OPTIONS_LIST = [
|
||||
# NOTE(notmorgan): This placeholder options can be removed once more
|
||||
# options are populated. This forces iteration on possible options for
|
||||
# complete test purposes in unit/functional/gate tests outside of the
|
||||
# explicit test cases that test resource options. This option is never
|
||||
# expected to be set.
|
||||
resource_options.ResourceOption('_TST', '__PLACEHOLDER__'),
|
||||
]
|
||||
|
||||
# NOTE(notmorgan): This placeholder options can be removed once more
|
||||
# options are populated. This forces iteration on possible options for
|
||||
# complete test purposes in unit/functional/gate tests outside of the
|
||||
# explicit test cases that test resource options. This option is never
|
||||
# expected to be set.
|
||||
_placeholder_opt = resource_options.ResourceOption('_TST', '__PLACEHOLDER__')
|
||||
|
||||
|
||||
# NOTE(notmorgan): wrap this in a function for testing purposes.
|
||||
# This is called on import by design.
|
||||
def register_user_options():
|
||||
for opt in USER_OPTIONS_LIST:
|
||||
for opt in [
|
||||
_placeholder_opt,
|
||||
]:
|
||||
USER_OPTIONS_REGISTRY.register_option(opt)
|
||||
|
||||
|
||||
|
@ -191,6 +191,11 @@ class User(sql.ModelBase, sql.DictBase):
|
||||
def enabled(cls):
|
||||
return User._enabled
|
||||
|
||||
def get_resource_option(self, option_id):
|
||||
if option_id in self._resource_option_mapper.keys():
|
||||
return self._resource_option_mapper[option_id]
|
||||
return None
|
||||
|
||||
def to_dict(self, include_extra_dict=False):
|
||||
d = super(User, self).to_dict(include_extra_dict=include_extra_dict)
|
||||
if 'default_project_id' in d and d['default_project_id'] is None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user