2727
2828
2929class PolicyBasedControllerMixin (object ):
30-
3130 __policy_service_name__ = ""
3231 __policy_name__ = None
3332 _otp_mandatory = set ()
3433
3534 def __init__ (self , * args , ** kwargs ):
3635 super ().__init__ (* args , ** kwargs )
37- self ._introspection = (
38- contexts .get_context ().iam_context .introspection_info ()
39- )
36+ self ._introspection = contexts .get_context ().iam_context .introspection_info ()
4037
4138 self ._ctx_project_id = self ._introspection .get ("project_id" , None )
4239 if isinstance (self ._ctx_project_id , str ):
@@ -74,23 +71,17 @@ def _enforce_and_override_project_id_in_kwargs(self, method, kwargs):
7471 if "project_id" in kwargs :
7572 self ._force_project_id (kwargs ["project_id" ])
7673 else :
77- kwargs ["project_id" ] = types .UUID ().from_simple_type (
78- self ._ctx_project_id
79- )
74+ kwargs ["project_id" ] = types .UUID ().from_simple_type (self ._ctx_project_id )
8075
8176 def _check_otp (self , method ):
82- if (
83- self ._introspection .get ("otp_enabled" )
84- or method in self ._otp_mandatory
85- ):
77+ if self ._introspection .get ("otp_enabled" ) or method in self ._otp_mandatory :
8678 if not self ._introspection .get ("otp_verified" ):
8779 raise exceptions .OTPInvalidCodeError ()
8880
8981
9082class PolicyBasedController (
9183 PolicyBasedControllerMixin , controllers .BaseResourceController
9284):
93-
9485 def create (self , ** kwargs ):
9586 self ._enforce_and_override_project_id_in_kwargs ("create" , kwargs )
9687
@@ -103,9 +94,7 @@ def get(self, **kwargs):
10394
10495 def filter (self , filters , order_by = None ):
10596 self ._enforce_and_override_project_id_in_kwargs ("read" , filters )
106- return super (PolicyBasedController , self ).filter (
107- filters , order_by = order_by
108- )
97+ return super (PolicyBasedController , self ).filter (filters , order_by = order_by )
10998
11099 def delete (self , uuid ):
111100 filters = {}
@@ -127,7 +116,6 @@ def update(self, uuid, **kwargs):
127116class NestedPolicyBasedController (
128117 PolicyBasedControllerMixin , controllers .BaseNestedResourceController
129118):
130-
131119 # Nested resources may not have projects, so it will be checked via parent
132120 def create (self , parent_resource , ** kwargs ):
133121 if "project_id" in self .model .properties :
@@ -165,7 +153,6 @@ def update(self, parent_resource, uuid, **kwargs):
165153class PolicyBasedWithoutProjectController (
166154 PolicyBasedControllerMixin , controllers .BaseResourceController
167155):
168-
169156 def create (self , ** kwargs ):
170157 self ._enforce ("create" )
171158 return super ().create (** kwargs )
0 commit comments