osi-dump 0.1.3.3.2.5__py3-none-any.whl → 0.1.3.3.2.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,9 +15,28 @@ from osi_dump.api.keystone import get_role_assignments
15
15
  logger = logging.getLogger(__name__)
16
16
 
17
17
 
18
- class OpenStackRoleAssignmentImporter(RoleAssignmentImporter):
18
+ class OpenStackRoleAssignmentImporter(RoleAssignmentImporter):
19
19
  def __init__(self, connection: Connection):
20
20
  self.connection = connection
21
+
22
+ self.users = {}
23
+ self.roles = {}
24
+
25
+ def _get_users(self):
26
+ os_users = self.connection.identity.users()
27
+
28
+ for os_user in os_users:
29
+ print(os_user)
30
+ self.users[os_user.id] = os_user.name
31
+
32
+ def _get_roles(self):
33
+ os_roles = self.connection.identity.roles()
34
+
35
+ for os_role in os_roles:
36
+
37
+ print(os_role)
38
+ self.roles[os_role.id] = os_role.name
39
+
21
40
 
22
41
  def import_role_assignments(self) -> list[RoleAssignment]:
23
42
  """Import role_assignments information from Openstack
@@ -32,11 +51,22 @@ class OpenStackRoleAssignmentImporter(RoleAssignmentImporter):
32
51
  logger.info(
33
52
  f"Importing role_assignments for {self.connection.auth['auth_url']}"
34
53
  )
54
+
55
+ try:
56
+ self._get_users()
57
+ except Exception as e:
58
+ logger.info(f"Getting user list failed {e}")
59
+
60
+ try:
61
+ self._get_roles()
62
+ except Exception as e:
63
+ logger.info(f"Getting role list failed {e}")
35
64
 
36
65
  try:
37
66
  osrole_assignments: list[OSRoleAssignment] = list(
38
67
  self.connection.identity.role_assignments()
39
68
  )
69
+
40
70
  except Exception as e:
41
71
  raise Exception(
42
72
  f"Can not fetch role_assignments for {self.connection.auth['auth_url']} {e}"
@@ -53,7 +83,7 @@ class OpenStackRoleAssignmentImporter(RoleAssignmentImporter):
53
83
  role_assignments.append(future.result())
54
84
 
55
85
  logger.info(f"Imported role_assignments for {self.connection.auth['auth_url']}")
56
-
86
+
57
87
  return role_assignments
58
88
 
59
89
  def _get_role_assignment_info(
@@ -76,20 +106,15 @@ class OpenStackRoleAssignmentImporter(RoleAssignmentImporter):
76
106
  user_name = None
77
107
  role_name = None
78
108
 
79
- try:
80
- role_name = self.connection.identity.get_role(
81
- role_assignment.role["id"]
82
- ).name
83
-
109
+ try:
110
+ user_name = self.users[user_id]
84
111
  except Exception as e:
85
- logger.warning(f"Can not get role name: {e}")
112
+ logger.warning(f"Can not get user name: {e}")
86
113
 
87
114
  try:
88
- user_name = self.connection.identity.get_user(
89
- role_assignment.user["id"]
90
- ).name
115
+ role_name = self.roles[role_id]
91
116
  except Exception as e:
92
- logger.warning(f"Can not get user name: {e}")
117
+ logger.warning(f"Can not get role name: {e}")
93
118
 
94
119
  role_assignment_ret = RoleAssignment(
95
120
  user_id=user_id,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osi-dump
3
- Version: 0.1.3.3.2.5
3
+ Version: 0.1.3.3.2.7
4
4
  Summary: OpenStack information dump tool
5
5
  Author: TVKain
6
6
  License: Apache-2.0
@@ -77,7 +77,7 @@ osi_dump/importer/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
77
77
  osi_dump/importer/project/openstack_project_importer.py,sha256=ylcm3jEFqh4gW8vhzhIaBq5v4A-PV3BaaogC8uHlSkg,3295
78
78
  osi_dump/importer/project/project_importer.py,sha256=jwEvxteFbSwyWMV8hKAtf5Lo2bZysWkQ1L_NVUE8XOQ,191
79
79
  osi_dump/importer/role_assignment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
80
- osi_dump/importer/role_assignment/openstack_role_assignment_importer.py,sha256=abEpuWfEH0lV0DLuDhxzH0QEQ83dFqNanyzPlS_LD8A,3084
80
+ osi_dump/importer/role_assignment/openstack_role_assignment_importer.py,sha256=iJYSY8VWNZ8K7xz8wotGOqbvS5fjJsA6WQcmyPLh3mU,3720
81
81
  osi_dump/importer/role_assignment/role_assignment_importer.py,sha256=Faorx0qsgdXjv5y2t-7obpV3wFfbmByx_-8b9yBr7L8,228
82
82
  osi_dump/importer/router/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
83
  osi_dump/importer/router/openstack_router_importer.py,sha256=T_Wr45nJrCcp2OOdRawmdQkNBDzczA-3DPx9dlewd4g,2781
@@ -109,8 +109,8 @@ osi_dump/util/extract_hostname.py,sha256=IpdklGHevmtRu67xeSRE_5n2mvWGI1sDsnJwExo
109
109
  osi_dump/util/openstack_util.py,sha256=_o8LiRmQKtxQ8hU3rbrMNwIAxt0-aWD2rjq-NvVdK9E,1299
110
110
  osi_dump/util/panda_excel.py,sha256=owr8AffIxqN3yY8kIv55Ox4j2dRz7kXZvSZFZeft8dw,734
111
111
  osi_dump/util/validate_dir_path.py,sha256=pL_OrY8JnNwk3vj6Zp6bsZtgHXhszSGRoqIt-1G5S90,507
112
- osi_dump-0.1.3.3.2.5.dist-info/METADATA,sha256=BqjYTuDziPPlgaGAusdxSWD5IOWlYOd98yjk-M3flzE,679
113
- osi_dump-0.1.3.3.2.5.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
114
- osi_dump-0.1.3.3.2.5.dist-info/entry_points.txt,sha256=ozm5sIBtXzLv6_FiUe26v1BgA3_xUReGLPhKQKZ56wQ,46
115
- osi_dump-0.1.3.3.2.5.dist-info/top_level.txt,sha256=OtAAwmJfcoPvlw_Cemo_H1aXIGV_7w0O2941KQt6faQ,9
116
- osi_dump-0.1.3.3.2.5.dist-info/RECORD,,
112
+ osi_dump-0.1.3.3.2.7.dist-info/METADATA,sha256=CUVP1f6ORCJHciEIYPowNy2OOXEVNiFQp4aFc42-NDo,679
113
+ osi_dump-0.1.3.3.2.7.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
114
+ osi_dump-0.1.3.3.2.7.dist-info/entry_points.txt,sha256=ozm5sIBtXzLv6_FiUe26v1BgA3_xUReGLPhKQKZ56wQ,46
115
+ osi_dump-0.1.3.3.2.7.dist-info/top_level.txt,sha256=OtAAwmJfcoPvlw_Cemo_H1aXIGV_7w0O2941KQt6faQ,9
116
+ osi_dump-0.1.3.3.2.7.dist-info/RECORD,,