-
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 dependency
during testing The identity provider used by `esi_leap` is now abstracted with a `BaseIDP` ABC, and implemented by two subclasses: A `KeystoneIDP` class which mostly copied the code from `common/keystone.py`, and `DummyIDP` which mocks a real IDP The IDP used by `esi_leap` can be set by overriding the `idp_type` CONF value like so: CONF.set_override( "idp_type", "dummy_idp", group="esi" ) As a consequence of abstracting the IDP, `common/keystone.py` has been removed. All references to `common/keystone.py` and the functions defined in it has been appropriately changed. New unit tests have been added for the keystone and dummy IDP clients
- Loading branch information
Showing
23 changed files
with
346 additions
and
173 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
Empty file.
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,23 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import abc | ||
|
||
|
||
class BaseIDP(abc.ABC): | ||
@abc.abstractmethod | ||
def get_projects(self, project_id): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def list_projects(self, **kwargs): | ||
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,40 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from keystoneclient.v3.projects import Project | ||
from keystoneclient.v3.projects import ProjectManager | ||
from keystoneclient.v3.users import User | ||
from keystoneclient.v3.users import UserManager | ||
|
||
from esi_leap.common.idp_clients import baseIDP | ||
|
||
|
||
class DummyIDP(baseIDP.BaseIDP): | ||
idp_type = "dummy_idp" | ||
dummy_project_dict = {} | ||
dummy_user_dict = {} | ||
|
||
def get_projects(self, project_id): | ||
return self.dummy_project_dict[project_id] | ||
|
||
def list_projects(self, **kwargs): | ||
return [project for project in self.dummy_project_dict.values()] | ||
|
||
def add_project(self, id, name, parent_id): | ||
self.dummy_project_dict[id] = Project( | ||
ProjectManager, {"id": id, "name": name, "parent_id": parent_id} | ||
) | ||
|
||
def add_user(self, id, name, project_id): | ||
self.dummy_user_dict[id] = User( | ||
UserManager, {"id": id, "name": name, "project_id": project_id} | ||
) |
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 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from keystoneauth1 import loading as ks_loading | ||
from keystoneclient import client as keystone_client | ||
|
||
from esi_leap.common.idp_clients import baseIDP | ||
import esi_leap.conf | ||
|
||
CONF = esi_leap.conf.CONF | ||
|
||
|
||
class KeystoneIDP(baseIDP.BaseIDP): | ||
idp_type = "keystone_idp" | ||
|
||
def __init__(self) -> None: | ||
auth_plugin = ks_loading.load_auth_from_conf_options(CONF, "keystone") | ||
sess = ks_loading.load_session_from_conf_options( | ||
CONF, "keystone", auth=auth_plugin | ||
) | ||
self.cli = keystone_client.Client(session=sess) | ||
|
||
def get_projects(self, project_id): | ||
return self.cli.projects.get(project_id) | ||
|
||
def list_projects(self, **kwargs): | ||
return self.cli.projects.list(**kwargs) |
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,23 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from oslo_config import cfg | ||
|
||
opts = [ | ||
cfg.StrOpt("idp_type", default="keystone_idp"), | ||
] | ||
|
||
api_group = cfg.OptGroup("esi", title="ESI Options") | ||
|
||
|
||
def register_opts(conf): | ||
conf.register_opts(opts, group=api_group) |
Oops, something went wrong.