Closed
Description
Describe the bug
As Splunk allows users to have non existent roles, calling role_entites on a user with roles assigned that are not existent leads to exceptions.
Defective code:
class User(Entity):
"""This class represents a Splunk user.
"""
@property
def role_entities(self):
"""Returns a list of roles assigned to this user.
:return: The list of roles.
:rtype:
"""
return [self.service.roles[name] for name in self.content.roles]
Possible solution:
class User(Entity):
"""This class represents a Splunk user.
"""
@property
def role_entities(self):
"""Returns a list of roles assigned to this user.
:return: The list of roles.
:rtype:
"""
all_role_names = [r.name for r in self.service.roles.list()]
return [self.service.roles[name] for name in self.content.roles if name in all_role_names]
Or with (I suppose more calls to the API)
return [self.service.roles[name] for name in self.content.roles if name in self.content.roles]
Splunk (please complete the following information):
- Version: 9.0.1
- OS: Ubuntu
- Deployment: all
SDK (please complete the following information):
- Version: 1.7.3
- Language Runtime Version: Python 3.7
- OS: Ubuntu
Metadata
Metadata
Assignees
Labels
No labels