X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fauthconn_keystone.py;h=685773b80e73037967751beb752f12a72edccce1;hp=115de7c8b8a15e5aee1ed0736494d09d624490ba;hb=b2e48bdecec7cd57f303becf40c5d469b8fdadff;hpb=1546f2a46d99a4741b23857e6ceb4b813223e297 diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index 115de7c..685773b 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -25,10 +25,11 @@ it for OSM. """ -__author__ = "Eduardo Sousa " +__author__ = "Eduardo Sousa , " \ + "Pedro de la Cruz Ramos " __date__ = "$27-jul-2018 23:59:59$" -from authconn import Authconn, AuthException, AuthconnOperationException, AuthconnNotFoundException, \ +from osm_nbi.authconn import Authconn, AuthException, AuthconnOperationException, AuthconnNotFoundException, \ AuthconnConflictException import logging @@ -40,12 +41,12 @@ from keystoneauth1.exceptions.base import ClientException from keystoneauth1.exceptions.http import Conflict from keystoneclient.v3 import client from http import HTTPStatus -from validation import is_valid_uuid +from osm_nbi.validation import is_valid_uuid class AuthconnKeystone(Authconn): - def __init__(self, config, db, token_cache): - Authconn.__init__(self, config, db, token_cache) + def __init__(self, config, db): + Authconn.__init__(self, config, db) self.logger = logging.getLogger("nbi.authenticator.keystone") @@ -250,8 +251,9 @@ class AuthconnKeystone(Authconn): user_id = user_obj.id if user_info.get("password") or user_info.get("username") \ or user_info.get("add_project_role_mappings") or user_info.get("remove_project_role_mappings"): + ctime = user_obj._admin.get("created", 0) if hasattr(user_obj, "_admin") else 0 self.keystone.users.update(user_id, password=user_info.get("password"), name=user_info.get("username"), - _admin={"created": user_obj._admin["created"], "modified": time.time()}) + _admin={"created": ctime, "modified": time.time()}) for mapping in user_info.get("remove_project_role_mappings", []): self.remove_role_from_user(user_id, mapping["project"], mapping["role"]) for mapping in user_info.get("add_project_role_mappings", []): @@ -419,7 +421,8 @@ class AuthconnKeystone(Authconn): projects = [{ "name": project.name, "_id": project.id, - "_admin": project.to_dict().get("_admin", {}) # TODO: REVISE + "_admin": project.to_dict().get("_admin", {}), # TODO: REVISE + "quotas": project.to_dict().get("quotas", {}), # TODO: REVISE } for project in projects] if filter_q and filter_q.get("_id"): @@ -442,7 +445,9 @@ class AuthconnKeystone(Authconn): """ try: result = self.keystone.projects.create(project_info["name"], self.project_domain_name, - _admin=project_info["_admin"]) + _admin=project_info["_admin"], + quotas=project_info.get("quotas", {}) + ) return result.id except ClientException as e: # self.logger.exception("Error during project creation using keystone: {}".format(e)) @@ -477,7 +482,10 @@ class AuthconnKeystone(Authconn): :return: None """ try: - self.keystone.projects.update(project_id, name=project_info["name"], _admin=project_info["_admin"]) + self.keystone.projects.update(project_id, name=project_info["name"], + _admin=project_info["_admin"], + quotas=project_info.get("quotas", {}) + ) except ClientException as e: # self.logger.exception("Error during project update using keystone: {}".format(e)) raise AuthconnOperationException("Error during project update using Keystone: {}".format(e))