Skip to content

Commit

Permalink
Merge pull request #39 from 2niknatan/master
Browse files Browse the repository at this point in the history
Adding comments about the 'or []'
  • Loading branch information
g3rzi committed Sep 6, 2022
2 parents 0788e20 + 2068158 commit 796a33c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def get_all_risky_subjects():
all_risky_rolebindings = get_all_risky_rolebinding()
passed_users = {}
for risky_rolebinding in all_risky_rolebindings:

# In case 'risky_rolebinding.subjects' is 'None', 'or []' will prevent an exception.
for user in risky_rolebinding.subjects or []:
# Removing duplicated users
if ''.join((user.kind, user.name, str(user.namespace))) not in passed_users:
Expand Down Expand Up @@ -415,6 +417,7 @@ def get_rolebindings_and_clusterrolebindings_associated_to_subject(subject_name,
associated_rolebindings = []

for rolebinding in rolebindings_all_namespaces.items:
# In case 'rolebinding.subjects' is 'None', 'or []' will prevent an exception.
for subject in rolebinding.subjects or []:
if subject.name.lower() == subject_name.lower() and subject.kind.lower() == kind.lower():
if kind == SERVICEACCOUNT_KIND:
Expand All @@ -425,6 +428,8 @@ def get_rolebindings_and_clusterrolebindings_associated_to_subject(subject_name,

associated_clusterrolebindings = []
for clusterrolebinding in cluster_rolebindings:

# In case 'clusterrolebinding.subjects' is 'None', 'or []' will prevent an exception.
for subject in clusterrolebinding.subjects or []:
if subject.name == subject_name.lower() and subject.kind.lower() == kind.lower():
if kind == SERVICEACCOUNT_KIND:
Expand Down

0 comments on commit 796a33c

Please sign in to comment.