gnetclisdk 1.0.2__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.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
@@ -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,3 +1,4 @@
1
+ import os
1
2
  from setuptools import setup
2
3
 
3
4
  with open("README.md") as f:
@@ -8,7 +9,7 @@ with open("requirements.txt") as f:
8
9
 
9
10
  setup(
10
11
  name="gnetclisdk",
11
- version="1.0.2",
12
+ version=os.getenv("VERSION", "0.0").strip("v"),
12
13
  description="Client for Gnetcli GRPC-server",
13
14
  long_description=readme,
14
15
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes