-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dummy identity provider to remove Keystone dependancy
during testing The dummy identity provider (idp) can be enabled by setting the environment variable ESI_DEBUG to True. For now, the dummy idp returns information about a dummy project Some functions from `api/controllers/v1/utils.py` have been moved into the only controllers that use them and turned into static class methods.
- Loading branch information
Showing
9 changed files
with
180 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
|
||
from esi_leap.common.idp import keystoneIDP, dummyIDP | ||
|
||
if os.environ.get('ESI_DEBUG', '') == 'True': | ||
idp = dummyIDP.DummyIDP() | ||
else: | ||
idp = keystoneIDP.KeystoneIDP() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import abc | ||
|
||
class BaseIDP(abc.ABC): | ||
|
||
def get_project_list(): | ||
pass | ||
|
||
def get_project_name(self, id, project_list=None): | ||
pass | ||
|
||
def get_parent_project_id_tree(project_id): | ||
pass | ||
|
||
def get_project_uuid_from_ident(project_ident): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from oslo_utils import uuidutils | ||
from keystoneclient.v3.projects import Project, ProjectManager | ||
|
||
from esi_leap.common import exception | ||
from esi_leap.common.idp import baseIDP | ||
|
||
dummy_project = Project(manager=ProjectManager, info={ | ||
'id' : 1, | ||
'name' : 'test' | ||
}) | ||
|
||
class DummyIDP(baseIDP.BaseIDP): | ||
|
||
def get_parent_project_id_tree(self, project_id): | ||
return [1] | ||
|
||
|
||
def get_project_uuid_from_ident(self, project_ident): | ||
if uuidutils.is_uuid_like(project_ident): | ||
return project_ident | ||
else: | ||
if project_ident == "test": | ||
return 1 | ||
raise exception.ProjectNoSuchName(name=project_ident) | ||
|
||
|
||
def get_project_list(self): | ||
|
||
return [dummy_project] | ||
|
||
|
||
def get_project_name(self, project_id, project_list=None): | ||
if project_id == 1: | ||
return 'test' | ||
else: | ||
return '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from keystoneauth1 import loading as ks_loading | ||
from keystoneclient import client as keystone_client | ||
from oslo_utils import uuidutils | ||
|
||
from esi_leap.common import exception | ||
import esi_leap.conf | ||
from esi_leap.common.idp import baseIDP | ||
|
||
CONF = esi_leap.conf.CONF | ||
_cached_keystone_client = None | ||
_cached_project_list = None | ||
|
||
class KeystoneIDP(baseIDP.BaseIDP): | ||
|
||
def get_keystone_client(self): | ||
global _cached_keystone_client | ||
if _cached_keystone_client is not None: | ||
return _cached_keystone_client | ||
|
||
auth_plugin = ks_loading.load_auth_from_conf_options(CONF, 'keystone') | ||
sess = ks_loading.load_session_from_conf_options(CONF, 'keystone', | ||
auth=auth_plugin) | ||
cli = keystone_client.Client(session=sess) | ||
_cached_keystone_client = cli | ||
|
||
return cli | ||
|
||
|
||
def get_parent_project_id_tree(self, project_id): | ||
ks_client = self.get_keystone_client() | ||
project = ks_client.projects.get(project_id) | ||
project_ids = [project.id] | ||
while project.parent_id is not None: | ||
project = ks_client.projects.get(project.parent_id) | ||
project_ids.append(project.id) | ||
return project_ids | ||
|
||
|
||
def get_project_uuid_from_ident(self, project_ident): | ||
if uuidutils.is_uuid_like(project_ident): | ||
return project_ident | ||
else: | ||
projects = self.get_keystone_client().projects.list(name=project_ident) | ||
if len(projects) > 0: | ||
# projects have unique names | ||
return projects[0].id | ||
raise exception.ProjectNoSuchName(name=project_ident) | ||
|
||
|
||
def get_project_list(self): | ||
return self.get_keystone_client().projects.list() | ||
|
||
|
||
def get_project_name(self, project_id, project_list=None): | ||
if project_id: | ||
if project_list is None: | ||
project = self.get_keystone_client().projects.get(project_id) | ||
else: | ||
project = next((p for p in project_list | ||
if getattr(p, 'id') == project_id), | ||
None) | ||
return project.name if project else '' | ||
else: | ||
return '' |