gnetclisdk 1.0.57__tar.gz → 1.0.59__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: gnetclisdk
3
- Version: 1.0.57
3
+ Version: 1.0.59
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
@@ -7,7 +7,7 @@ from abc import ABC, abstractmethod
7
7
  from contextlib import asynccontextmanager
8
8
  from dataclasses import dataclass, field
9
9
  from functools import partial
10
- from typing import Any, AsyncIterator, List, Optional, Tuple, Dict
10
+ from typing import Any, AsyncIterator, List, Optional, Tuple, Dict, Callable
11
11
 
12
12
  import grpc
13
13
  from google.protobuf.message import Message
@@ -200,14 +200,18 @@ class Gnetcli:
200
200
  return response
201
201
 
202
202
  @asynccontextmanager
203
- async def cmd_session(self, hostname: str) -> AsyncIterator["GnetcliSessionCmd"]:
203
+ async def cmd_session(
204
+ self,
205
+ hostname: str,
206
+ host_params: Optional[HostParams] = None) -> AsyncIterator["GnetcliSessionCmd"]:
204
207
  sess = GnetcliSessionCmd(
205
208
  hostname,
206
209
  server=self._server,
210
+ host_params=host_params,
207
211
  channel=self._channel,
208
212
  target_name_override=self._target_name_override,
209
213
  user_agent=self._user_agent,
210
- insecure_grpc=self._insecure_grpc,
214
+ _grpc_channel_fn=self._grpc_channel_fn,
211
215
  )
212
216
  await sess.connect()
213
217
  try:
@@ -286,6 +290,7 @@ class GnetcliSession(ABC):
286
290
  insecure_grpc: bool = False,
287
291
  channel: Optional[grpc.aio.Channel] = None,
288
292
  credentials: Optional[Credentials] = None,
293
+ _grpc_channel_fn: Optional[Callable] = None,
289
294
  ):
290
295
  self._hostname = hostname
291
296
  self._credentials = credentials
@@ -300,25 +305,28 @@ class GnetcliSession(ABC):
300
305
  ("grpc.max_send_message_length", GRPC_MAX_MESSAGE_LENGTH),
301
306
  ("grpc.max_receive_message_length", GRPC_MAX_MESSAGE_LENGTH),
302
307
  ]
303
- if target_name_override:
304
- options.append(("grpc.ssl_target_name_override", target_name_override))
305
- cert = get_cert(cert_file=cert_file)
306
- channel_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
307
- authentication: ClientAuthentication
308
- interceptors: [grpc.aio.ClientInterceptor] = list()
309
- if not token:
310
- pass
311
- elif token.startswith("OAuth"):
312
- authentication = OAuthClientAuthentication(token.split(" ")[1])
313
- interceptors.append(get_auth_client_interceptors(authentication))
314
- elif token.startswith("Basic"):
315
- authentication = BasicClientAuthentication(token.split(" ")[1])
316
- interceptors.append(get_auth_client_interceptors(authentication))
308
+ if _grpc_channel_fn:
309
+ grpc_channel_fn = _grpc_channel_fn
317
310
  else:
318
- raise Exception("unknown token type")
319
- grpc_channel_fn = partial(grpc.aio.secure_channel, credentials=channel_credentials, interceptors=interceptors)
320
- if insecure_grpc:
321
- grpc_channel_fn = partial(grpc.aio.insecure_channel, interceptors=interceptors)
311
+ if target_name_override:
312
+ options.append(("grpc.ssl_target_name_override", target_name_override))
313
+ cert = get_cert(cert_file=cert_file)
314
+ channel_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
315
+ authentication: ClientAuthentication
316
+ interceptors: list[grpc.aio.ClientInterceptor] = list()
317
+ if not token:
318
+ pass
319
+ elif token.startswith("OAuth"):
320
+ authentication = OAuthClientAuthentication(token.split(" ")[1])
321
+ interceptors.append(get_auth_client_interceptors(authentication))
322
+ elif token.startswith("Basic"):
323
+ authentication = BasicClientAuthentication(token.split(" ")[1])
324
+ interceptors.append(get_auth_client_interceptors(authentication))
325
+ else:
326
+ raise Exception("unknown token type")
327
+ grpc_channel_fn = partial(grpc.aio.secure_channel, credentials=channel_credentials, interceptors=interceptors)
328
+ if insecure_grpc:
329
+ grpc_channel_fn = partial(grpc.aio.insecure_channel, interceptors=interceptors)
322
330
  self._grpc_channel_fn = grpc_channel_fn
323
331
  self._options = options
324
332
  self._req_id: Optional[Any] = None
@@ -370,6 +378,34 @@ class GnetcliSession(ABC):
370
378
 
371
379
 
372
380
  class GnetcliSessionCmd(GnetcliSession):
381
+ def __init__(
382
+ self,
383
+ hostname: str,
384
+ token: str | None = None,
385
+ server: str = DEFAULT_SERVER,
386
+ target_name_override: Optional[str] = None,
387
+ cert_file: Optional[str] = None,
388
+ user_agent: str = DEFAULT_USER_AGENT,
389
+ insecure_grpc: bool = False,
390
+ channel: Optional[grpc.aio.Channel] = None,
391
+ credentials: Optional[Credentials] = None,
392
+ host_params: Optional[HostParams] = None,
393
+ _grpc_channel_fn: Optional[Callable] = None,
394
+ ):
395
+ super(GnetcliSessionCmd, self).__init__(
396
+ hostname,
397
+ token,
398
+ server,
399
+ target_name_override,
400
+ cert_file,
401
+ user_agent,
402
+ insecure_grpc,
403
+ channel,
404
+ credentials,
405
+ _grpc_channel_fn,
406
+ )
407
+ self.host_params = host_params
408
+
373
409
  async def cmd(
374
410
  self,
375
411
  cmd: str,
@@ -387,7 +423,7 @@ class GnetcliSessionCmd(GnetcliSession):
387
423
  qa=qa,
388
424
  read_timeout=read_timeout,
389
425
  cmd_timeout=cmd_timeout,
390
- host_params=host_params,
426
+ host_params=host_params if host_params else self.host_params,
391
427
  )
392
428
  return await self._cmd(pbcmd)
393
429
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: gnetclisdk
3
- Version: 1.0.57
3
+ Version: 1.0.59
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
File without changes
File without changes
File without changes
File without changes
File without changes