From 85e8a7bc5e991b4915fb37c4fdb0446e48a0229a Mon Sep 17 00:00:00 2001 From: Morgan Fainberg Date: Thu, 26 Jan 2017 14:28:10 -0800 Subject: [PATCH] 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 --- .../identity/backends/resource_options.py | 19 ++++++++++--------- keystone/identity/backends/sql_model.py | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/keystone/identity/backends/resource_options.py b/keystone/identity/backends/resource_options.py index 904a71e198..87283f77b7 100644 --- a/keystone/identity/backends/resource_options.py +++ b/keystone/identity/backends/resource_options.py @@ -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) diff --git a/keystone/identity/backends/sql_model.py b/keystone/identity/backends/sql_model.py index a8853486ef..f90fa9e0db 100644 --- a/keystone/identity/backends/sql_model.py +++ b/keystone/identity/backends/sql_model.py @@ -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: