11import datetime
22import typing
33
4- import aserto .authorizer .v2 as authorizer
5- import aserto .authorizer .v2 .api as api
64import grpc .aio as grpc
5+ from grpc import ssl_channel_credentials
6+
7+ import aserto .authorizer .v2 as authorizer
78from aserto .authorizer .v2 import (
89 CompileResponse ,
910 GetPolicyResponse ,
1011 ListPoliciesResponse ,
1112 QueryOptions ,
1213 QueryResponse ,
1314)
15+
16+ import aserto .authorizer .v2 .api as api
1417from aserto .authorizer .v2 .api import IdentityContext , IdentityType
15- from grpc import ssl_channel_credentials
1618
1719import aserto .client ._deadline as timeout
18- import aserto .client .authorizer .helpers as helpers
1920import aserto .client .resource_context as res_ctx
21+ from aserto .client .authorizer import helpers
2022from aserto .client .authorizer .helpers import DecisionTree
2123from aserto .client .identity import Identity
2224from aserto .client .options import AuthorizerOptions
2325from aserto .client .resource_context import ResourceContext
2426
27+ if typing .TYPE_CHECKING :
28+ AuthorizerAsyncStub = authorizer .AuthorizerAsyncStub
29+ else :
30+ AuthorizerAsyncStub = authorizer .AuthorizerStub
31+
2532
2633class AuthorizerClient :
2734 def __init__ (
@@ -41,7 +48,7 @@ def __init__(
4148 target = self ._options .url ,
4249 credentials = ssl_channel_credentials (self ._options .cert ),
4350 )
44- self .client = authorizer .AuthorizerStub (self ._channel )
51+ self .client = typing . cast ( AuthorizerAsyncStub , authorizer .AuthorizerStub (self ._channel ) )
4552
4653 @property
4754 def _headers (self ) -> typing .Mapping [str , str ]:
@@ -56,8 +63,8 @@ async def decision_tree(
5663 * ,
5764 policy_path_root : str ,
5865 decisions : typing .Sequence [str ],
59- policy_instance_name : typing . Optional [ str ] = None ,
60- policy_instance_label : typing . Optional [ str ] = None ,
66+ policy_instance_name : str = "" ,
67+ policy_instance_label : str = "" ,
6168 resource_context : typing .Optional [ResourceContext ] = None ,
6269 policy_path_separator : typing .Optional [typing .Literal ["DOT" , "SLASH" ]] = None ,
6370 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
@@ -93,8 +100,8 @@ async def decisions(
93100 * ,
94101 policy_path : str ,
95102 decisions : typing .Sequence [str ],
96- policy_instance_name : typing . Optional [ str ] ,
97- policy_instance_label : typing . Optional [ str ] = None ,
103+ policy_instance_name : str = "" ,
104+ policy_instance_label : str = "" ,
98105 resource_context : typing .Optional [ResourceContext ] = None ,
99106 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
100107 ) -> typing .Dict [str , bool ]:
@@ -129,8 +136,8 @@ async def query(
129136 input : str ,
130137 policy_path : str ,
131138 decisions : typing .Sequence [str ],
132- policy_instance_name : typing . Optional [ str ] ,
133- policy_instance_label : typing . Optional [ str ] = None ,
139+ policy_instance_name : str = "" ,
140+ policy_instance_label : str = "" ,
134141 resource_context : typing .Optional [ResourceContext ] = None ,
135142 options : typing .Optional [QueryOptions ] = None ,
136143 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
@@ -168,8 +175,8 @@ async def compile(
168175 disable_inlining : typing .Sequence [str ],
169176 policy_path : str ,
170177 decisions : typing .Sequence [str ],
171- policy_instance_name : typing . Optional [ str ] ,
172- policy_instance_label : typing . Optional [ str ] = None ,
178+ policy_instance_name : str = "" ,
179+ policy_instance_label : str = "" ,
173180 resource_context : typing .Optional [ResourceContext ] = None ,
174181 options : typing .Optional [QueryOptions ] = None ,
175182 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
@@ -203,8 +210,8 @@ async def compile(
203210 async def list_policies (
204211 self ,
205212 * ,
206- policy_instance_name : typing . Optional [ str ] ,
207- policy_instance_label : typing . Optional [ str ] = None ,
213+ policy_instance_name : str = "" ,
214+ policy_instance_label : str = "" ,
208215 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
209216 ) -> ListPoliciesResponse :
210217 response = await self .client .ListPolicies (
@@ -226,8 +233,8 @@ async def get_policy(
226233 self ,
227234 * ,
228235 id : str ,
229- policy_instance_name : typing . Optional [ str ] ,
230- policy_instance_label : typing . Optional [ str ] = None ,
236+ policy_instance_name : str = "" ,
237+ policy_instance_label : str = "" ,
231238 deadline : typing .Optional [typing .Union [datetime .datetime , datetime .timedelta ]] = None ,
232239 ) -> GetPolicyResponse :
233240 return await self .client .GetPolicy (
@@ -244,7 +251,13 @@ async def get_policy(
244251 ),
245252 )
246253
247- async def close (self ) -> None :
248- """Closes the gRPC channel"""
254+ async def close (self , grace : typing . Optional [ float ] = None ) -> None :
255+ """Closes the authorizer client's connection to the server.
249256
250- await self ._channel .close ()
257+ If a grace period is specified, this method waits until all active
258+ requests are finished or until the grace period is reached. Requests that haven't
259+ been terminated within the grace period are aborted.
260+ If a grace period is not specified (by passing None for grace),
261+ all existing requests are cancelled immediately.
262+ """
263+ await self ._channel .close (grace )
0 commit comments