gnetclisdk 1.0.2__py3-none-any.whl → 1.0.33__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gnetclisdk/client.py CHANGED
@@ -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
 
@@ -59,7 +65,22 @@ class File:
59
65
  class HostParams:
60
66
  device: str
61
67
  port: Optional[int] = None
68
+ hostname: Optional[str] = None
62
69
  credentials: Optional[Credentials] = None
70
+ ip: Optional[str] = None
71
+
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()
76
+ pbcmd = server_pb2.HostParams(
77
+ host=self.hostname,
78
+ port=self.port,
79
+ credentials=creds_pb,
80
+ device=self.device,
81
+ ip=self.ip,
82
+ )
83
+ return pbcmd
63
84
 
64
85
 
65
86
  def make_auth(auth_token: str) -> ClientAuthentication:
@@ -119,7 +140,8 @@ class Gnetcli:
119
140
  qa: Optional[List[QA]] = None,
120
141
  read_timeout: float = 0.0,
121
142
  cmd_timeout: float = 0.0,
122
- ) -> Message:
143
+ host_params: Optional[HostParams] = None,
144
+ ) -> server_pb2.CMDResult:
123
145
  pbcmd = make_cmd(
124
146
  hostname=hostname,
125
147
  cmd=cmd,
@@ -127,6 +149,7 @@ class Gnetcli:
127
149
  qa=qa,
128
150
  read_timeout=read_timeout,
129
151
  cmd_timeout=cmd_timeout,
152
+ host_params=host_params,
130
153
  )
131
154
  if self._channel is None:
132
155
  _logger.debug("connect to %s", self._server)
@@ -247,7 +270,7 @@ class GnetcliSession(ABC):
247
270
  def __init__(
248
271
  self,
249
272
  hostname: str,
250
- token: str,
273
+ token: str | None = None,
251
274
  server: str = DEFAULT_SERVER,
252
275
  target_name_override: Optional[str] = None,
253
276
  cert_file: Optional[str] = None,
@@ -274,13 +297,17 @@ class GnetcliSession(ABC):
274
297
  cert = get_cert(cert_file=cert_file)
275
298
  channel_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
276
299
  authentication: ClientAuthentication
277
- if token.startswith("OAuth"):
300
+ interceptors: [grpc.aio.ClientInterceptor] = list()
301
+ if not token:
302
+ pass
303
+ elif token.startswith("OAuth"):
278
304
  authentication = OAuthClientAuthentication(token.split(" ")[1])
305
+ interceptors.append(get_auth_client_interceptors(authentication))
279
306
  elif token.startswith("Basic"):
280
307
  authentication = BasicClientAuthentication(token.split(" ")[1])
308
+ interceptors.append(get_auth_client_interceptors(authentication))
281
309
  else:
282
310
  raise Exception("unknown token type")
283
- interceptors = get_auth_client_interceptors(authentication)
284
311
  grpc_channel_fn = partial(grpc.aio.secure_channel, credentials=channel_credentials, interceptors=interceptors)
285
312
  if insecure_grpc:
286
313
  grpc_channel_fn = partial(grpc.aio.insecure_channel, interceptors=interceptors)
@@ -342,7 +369,8 @@ class GnetcliSessionCmd(GnetcliSession):
342
369
  qa: Optional[List[QA]] = None,
343
370
  cmd_timeout: float = 0.0,
344
371
  read_timeout: float = 0.0,
345
- ) -> Message:
372
+ host_params: Optional[HostParams] = None,
373
+ ) -> server_pb2.CMDResult:
346
374
  _logger.debug("session cmd %r", cmd)
347
375
  pbcmd = make_cmd(
348
376
  hostname=self._hostname,
@@ -351,6 +379,7 @@ class GnetcliSessionCmd(GnetcliSession):
351
379
  qa=qa,
352
380
  read_timeout=read_timeout,
353
381
  cmd_timeout=cmd_timeout,
382
+ host_params=host_params,
354
383
  )
355
384
  return await self._cmd(pbcmd)
356
385
 
@@ -437,14 +466,15 @@ def make_cmd(
437
466
  qa: Optional[List[QA]] = None,
438
467
  read_timeout: float = 0.0,
439
468
  cmd_timeout: float = 0.0,
440
- ) -> Message:
441
- qa_cmd: List[Message] = []
469
+ host_params: Optional[HostParams] = None,
470
+ ) -> server_pb2.CMD:
471
+ qa_cmd: List[server_pb2.QA] = []
442
472
  if qa:
443
473
  for item in qa:
444
- qaitem = server_pb2.QA()
445
- qaitem.question = item.question
446
- qaitem.answer = item.answer
447
- 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()
448
478
  res = server_pb2.CMD(
449
479
  host=hostname,
450
480
  cmd=cmd,
@@ -452,8 +482,9 @@ def make_cmd(
452
482
  qa=qa_cmd,
453
483
  read_timeout=read_timeout,
454
484
  cmd_timeout=cmd_timeout,
485
+ host_params=host_params_pb,
455
486
  )
456
- return res # type: ignore
487
+ return res
457
488
 
458
489
 
459
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.2
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
@@ -1,11 +1,11 @@
1
1
  gnetclisdk/auth.py,sha256=GwM7H7Ecb-gwqUTkQorifNB_mtnZfgeS46gOW2Vx1U4,1246
2
- gnetclisdk/client.py,sha256=5C3bU47B8MMcb40I3OSY5abN0pKR4oGyUXqkrV0JyKY,16717
2
+ gnetclisdk/client.py,sha256=xtDbGJ3voTadmR7lt8WC-LKcBzk1v_otnaqG3LzKZjE,17899
3
3
  gnetclisdk/exceptions.py,sha256=d0Bcq8tnAzemCuCCrGJEmL_A1IQxCCLFRCwDhr9zvkU,2683
4
4
  gnetclisdk/interceptors.py,sha256=apj3l4lnR2ZcsA49odptrBC0kTDmP6Mp0EzYkeEJz9Y,7010
5
5
  gnetclisdk/proto/server_pb2.py,sha256=YL1_7wubJbSp97OeRZ_L9qJjbM2U-PMcfOg-_QpkjWs,8360
6
6
  gnetclisdk/proto/server_pb2.pyi,sha256=th-HnFVkR1ZEY-XmFmk8VMfDj_4uFAoSAXH61mSlVec,8295
7
7
  gnetclisdk/proto/server_pb2_grpc.py,sha256=rjuNEIfeqwFw99oSiWUyvNKCKPgITJZKcL8pQPbUQvM,14967
8
- gnetclisdk-1.0.2.dist-info/METADATA,sha256=4P_ceii_0Qb7CbxIz44DHdqbj0aJwKZ_sGy2ba-ND5Q,1433
9
- gnetclisdk-1.0.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10
- gnetclisdk-1.0.2.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
11
- gnetclisdk-1.0.2.dist-info/RECORD,,
8
+ gnetclisdk-1.0.33.dist-info/METADATA,sha256=5Rai2VnXAZWcMFERi82GeXQp6-jMolVVwOJu62RgqDU,1434
9
+ gnetclisdk-1.0.33.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
10
+ gnetclisdk-1.0.33.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
11
+ gnetclisdk-1.0.33.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5