gnetclisdk 1.0.32__tar.gz → 1.0.33__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.1
2
2
  Name: gnetclisdk
3
- Version: 1.0.32
3
+ Version: 1.0.33
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
@@ -36,16 +36,22 @@ class QA:
36
36
  question: str
37
37
  answer: str
38
38
 
39
+ def make_pb(self) -> server_pb2.QA:
40
+ pb = server_pb2.QA()
41
+ pb.question = self.question
42
+ pb.answer = self.answer
43
+ return pb
44
+
39
45
 
40
46
  @dataclass
41
47
  class Credentials:
42
- login: str
43
- password: str
48
+ login: Optional[str] = None
49
+ password: Optional[str] = None
44
50
 
45
- def make_pb(self) -> Message:
51
+ def make_pb(self) -> server_pb2.Credentials:
46
52
  pb = server_pb2.Credentials()
47
- pb.login = self.login
48
- pb.password = self.password
53
+ pb.login = self.login or ""
54
+ pb.password = self.password or ""
49
55
  return pb
50
56
 
51
57
 
@@ -63,11 +69,14 @@ class HostParams:
63
69
  credentials: Optional[Credentials] = None
64
70
  ip: Optional[str] = None
65
71
 
66
- def make_pb(self) -> Message:
72
+ def make_pb(self) -> server_pb2.HostParams:
73
+ creds_pb: Optional[server_pb2.Credentials] = None
74
+ if self.credentials:
75
+ creds_pb = self.credentials.make_pb()
67
76
  pbcmd = server_pb2.HostParams(
68
77
  host=self.hostname,
69
78
  port=self.port,
70
- credentials=self.credentials.make_pb(),
79
+ credentials=creds_pb,
71
80
  device=self.device,
72
81
  ip=self.ip,
73
82
  )
@@ -132,7 +141,7 @@ class Gnetcli:
132
141
  read_timeout: float = 0.0,
133
142
  cmd_timeout: float = 0.0,
134
143
  host_params: Optional[HostParams] = None,
135
- ) -> Message:
144
+ ) -> server_pb2.CMDResult:
136
145
  pbcmd = make_cmd(
137
146
  hostname=hostname,
138
147
  cmd=cmd,
@@ -261,7 +270,7 @@ class GnetcliSession(ABC):
261
270
  def __init__(
262
271
  self,
263
272
  hostname: str,
264
- token: str,
273
+ token: str | None = None,
265
274
  server: str = DEFAULT_SERVER,
266
275
  target_name_override: Optional[str] = None,
267
276
  cert_file: Optional[str] = None,
@@ -288,13 +297,17 @@ class GnetcliSession(ABC):
288
297
  cert = get_cert(cert_file=cert_file)
289
298
  channel_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
290
299
  authentication: ClientAuthentication
291
- if token.startswith("OAuth"):
300
+ interceptors: [grpc.aio.ClientInterceptor] = list()
301
+ if not token:
302
+ pass
303
+ elif token.startswith("OAuth"):
292
304
  authentication = OAuthClientAuthentication(token.split(" ")[1])
305
+ interceptors.append(get_auth_client_interceptors(authentication))
293
306
  elif token.startswith("Basic"):
294
307
  authentication = BasicClientAuthentication(token.split(" ")[1])
308
+ interceptors.append(get_auth_client_interceptors(authentication))
295
309
  else:
296
310
  raise Exception("unknown token type")
297
- interceptors = get_auth_client_interceptors(authentication)
298
311
  grpc_channel_fn = partial(grpc.aio.secure_channel, credentials=channel_credentials, interceptors=interceptors)
299
312
  if insecure_grpc:
300
313
  grpc_channel_fn = partial(grpc.aio.insecure_channel, interceptors=interceptors)
@@ -357,7 +370,7 @@ class GnetcliSessionCmd(GnetcliSession):
357
370
  cmd_timeout: float = 0.0,
358
371
  read_timeout: float = 0.0,
359
372
  host_params: Optional[HostParams] = None,
360
- ) -> Message:
373
+ ) -> server_pb2.CMDResult:
361
374
  _logger.debug("session cmd %r", cmd)
362
375
  pbcmd = make_cmd(
363
376
  hostname=self._hostname,
@@ -454,14 +467,14 @@ def make_cmd(
454
467
  read_timeout: float = 0.0,
455
468
  cmd_timeout: float = 0.0,
456
469
  host_params: Optional[HostParams] = None,
457
- ) -> Message:
458
- qa_cmd: List[Message] = []
470
+ ) -> server_pb2.CMD:
471
+ qa_cmd: List[server_pb2.QA] = []
459
472
  if qa:
460
473
  for item in qa:
461
- qaitem = server_pb2.QA()
462
- qaitem.question = item.question
463
- qaitem.answer = item.answer
464
- qa_cmd.append(qaitem)
474
+ qa_cmd.append(item.make_pb())
475
+ host_params_pb: Optional[server_pb2.HostParams] = None
476
+ if host_params:
477
+ host_params_pb = host_params.make_pb()
465
478
  res = server_pb2.CMD(
466
479
  host=hostname,
467
480
  cmd=cmd,
@@ -469,9 +482,9 @@ def make_cmd(
469
482
  qa=qa_cmd,
470
483
  read_timeout=read_timeout,
471
484
  cmd_timeout=cmd_timeout,
472
- host_params=host_params.make_pb(),
485
+ host_params=host_params_pb,
473
486
  )
474
- return res # type: ignore
487
+ return res
475
488
 
476
489
 
477
490
  def make_files_request(files: Dict[str, File]) -> List[server_pb2.FileData]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gnetclisdk
3
- Version: 1.0.32
3
+ Version: 1.0.33
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