1
1
"""Functions to expand wilcard actions into a full list of actions."""
2
+ from __future__ import annotations
3
+
2
4
import logging
3
5
import copy
4
6
import fnmatch
8
10
logger = logging .getLogger (__name__ )
9
11
10
12
11
- def expand (action ) :
13
+ def expand (action : str | list [ str ]) -> list [ str ] :
12
14
"""
13
15
expand the action wildcards into a full action
14
16
@@ -26,10 +28,11 @@ def expand(action):
26
28
expanded_actions .extend (expand (item ))
27
29
return expanded_actions
28
30
29
- if "*" in action :
31
+ if action == "*" :
32
+ return all_actions .copy ()
33
+ elif "*" in action :
30
34
expanded = [
31
35
expanded_action
32
- # for expanded_action in all_permissions
33
36
for expanded_action in all_actions
34
37
if fnmatch .fnmatchcase (expanded_action .lower (), action .lower ())
35
38
]
@@ -47,7 +50,7 @@ def expand(action):
47
50
return [action ]
48
51
49
52
50
- def determine_actions_to_expand (action_list ) :
53
+ def determine_actions_to_expand (action_list : list [ str ]) -> list [ str ] :
51
54
"""
52
55
Determine if an action needs to get expanded from its wildcard
53
56
@@ -57,13 +60,13 @@ def determine_actions_to_expand(action_list):
57
60
List: A list of actions
58
61
"""
59
62
new_action_list = []
60
- for action in range ( len ( action_list )) :
61
- if "*" in action_list [ action ] :
62
- expanded_action = expand (action_list [ action ] )
63
+ for action in action_list :
64
+ if "*" in action :
65
+ expanded_action = expand (action )
63
66
new_action_list .extend (expanded_action )
64
67
else :
65
68
# If there is no wildcard, copy that action name over to the new_action_list
66
- new_action_list .append (action_list [ action ] )
69
+ new_action_list .append (action )
67
70
new_action_list .sort ()
68
71
return new_action_list
69
72
0 commit comments