gnetclisdk 1.0.55__py3-none-any.whl → 1.0.57__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
gnetclisdk/client.py CHANGED
@@ -2,6 +2,7 @@ import asyncio
2
2
  import logging
3
3
  import os.path
4
4
  import uuid
5
+ import re
5
6
  from abc import ABC, abstractmethod
6
7
  from contextlib import asynccontextmanager
7
8
  from dataclasses import dataclass, field
@@ -190,7 +191,7 @@ class Gnetcli:
190
191
  _logger.debug("connect to %s", self._server)
191
192
  async with self._grpc_channel_fn(self._server, options=self._options) as channel:
192
193
  stub = server_pb2_grpc.GnetcliStub(channel)
193
- _logger.debug("executing netconf cmd: %r", pbcmd)
194
+ _logger.debug("executing netconf cmd: %r", mask_password(repr(pbcmd)))
194
195
  try:
195
196
  response = await grpc_call_wrapper(stub.ExecNetconf, pbcmd)
196
197
  except Exception as e:
@@ -344,7 +345,7 @@ class GnetcliSession(ABC):
344
345
  if not self._stream:
345
346
  raise Exception("empty self._stream")
346
347
  try:
347
- _logger.debug("cmd %r on %r", str(cmdpb).replace("\n", ""), self._stream)
348
+ _logger.debug("cmd %r on %r", mask_password(str(cmdpb)).replace("\n", ""), self._stream)
348
349
  await self._stream.write(cmdpb)
349
350
  response: Message = await self._stream.read()
350
351
  except grpc.aio.AioRpcError as e:
@@ -420,7 +421,7 @@ async def grpc_call_wrapper(stub: grpc.UnaryUnaryMultiCallable, request: Any) ->
420
421
  metadata = [
421
422
  (HEADER_REQUEST_ID, req_id),
422
423
  ]
423
- _logger.debug("executing %s: %r, req_id=%s", type(request), repr(request), req_id)
424
+ _logger.debug("executing %s: %r, req_id=%s", type(request), mask_password(repr(request)), req_id)
424
425
  await asyncio.sleep(i * 2)
425
426
  try:
426
427
  response = await stub(request=request, metadata=metadata)
@@ -494,6 +495,10 @@ def make_cmd(
494
495
  return res
495
496
 
496
497
 
498
+ def mask_password(line: str) -> str:
499
+ return re.sub(r'password: ".+?"', "password: ...", line)
500
+
501
+
497
502
  def make_files_request(files: Dict[str, File]) -> List[server_pb2.FileData]:
498
503
  res: List[server_pb2.FileData] = []
499
504
  for path, file in files.items():
@@ -1,22 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
- # NO CHECKED-IN PROTOBUF GENCODE
4
3
  # source: server.proto
5
- # Protobuf Python Version: 5.27.2
4
+ # Protobuf Python Version: 4.25.1
6
5
  """Generated protocol buffer code."""
7
6
  from google.protobuf import descriptor as _descriptor
8
7
  from google.protobuf import descriptor_pool as _descriptor_pool
9
- from google.protobuf import runtime_version as _runtime_version
10
8
  from google.protobuf import symbol_database as _symbol_database
11
9
  from google.protobuf.internal import builder as _builder
12
- _runtime_version.ValidateProtobufRuntimeVersion(
13
- _runtime_version.Domain.PUBLIC,
14
- 5,
15
- 27,
16
- 2,
17
- '',
18
- 'server.proto'
19
- )
20
10
  # @@protoc_insertion_point(imports)
21
11
 
22
12
  _sym_db = _symbol_database.Default()
@@ -31,20 +21,20 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cserver.proto\x
31
21
  _globals = globals()
32
22
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
33
23
  _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'server_pb2', _globals)
34
- if not _descriptor._USE_C_DESCRIPTORS:
35
- _globals['DESCRIPTOR']._loaded_options = None
24
+ if _descriptor._USE_C_DESCRIPTORS == False:
25
+ _globals['DESCRIPTOR']._options = None
36
26
  _globals['DESCRIPTOR']._serialized_options = b'Z5github.com/annetutil/gnetcli/pkg/server/proto;gnetcli'
37
- _globals['_GNETCLI'].methods_by_name['SetupHostParams']._loaded_options = None
27
+ _globals['_GNETCLI'].methods_by_name['SetupHostParams']._options = None
38
28
  _globals['_GNETCLI'].methods_by_name['SetupHostParams']._serialized_options = b'\202\323\344\223\002\036\"\031/api/v1/setup_host_params:\001*'
39
- _globals['_GNETCLI'].methods_by_name['Exec']._loaded_options = None
29
+ _globals['_GNETCLI'].methods_by_name['Exec']._options = None
40
30
  _globals['_GNETCLI'].methods_by_name['Exec']._serialized_options = b'\202\323\344\223\002\021\"\014/api/v1/exec:\001*'
41
- _globals['_GNETCLI'].methods_by_name['AddDevice']._loaded_options = None
31
+ _globals['_GNETCLI'].methods_by_name['AddDevice']._options = None
42
32
  _globals['_GNETCLI'].methods_by_name['AddDevice']._serialized_options = b'\202\323\344\223\002\027\"\022/api/v1/add_device:\001*'
43
- _globals['_GNETCLI'].methods_by_name['ExecNetconf']._loaded_options = None
33
+ _globals['_GNETCLI'].methods_by_name['ExecNetconf']._options = None
44
34
  _globals['_GNETCLI'].methods_by_name['ExecNetconf']._serialized_options = b'\202\323\344\223\002\031\"\024/api/v1/exec_netconf:\001*'
45
- _globals['_GNETCLI'].methods_by_name['Download']._loaded_options = None
35
+ _globals['_GNETCLI'].methods_by_name['Download']._options = None
46
36
  _globals['_GNETCLI'].methods_by_name['Download']._serialized_options = b'\202\323\344\223\002\026\"\021/api/v1/downloads:\001*'
47
- _globals['_GNETCLI'].methods_by_name['Upload']._loaded_options = None
37
+ _globals['_GNETCLI'].methods_by_name['Upload']._options = None
48
38
  _globals['_GNETCLI'].methods_by_name['Upload']._serialized_options = b'\202\323\344\223\002\023\"\016/api/v1/upload:\001*'
49
39
  _globals['_TRACEOPERATION']._serialized_start=1311
50
40
  _globals['_TRACEOPERATION']._serialized_end=1413
@@ -1,30 +1,10 @@
1
1
  # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2
2
  """Client and server classes corresponding to protobuf-defined services."""
3
3
  import grpc
4
- import warnings
5
4
 
6
5
  from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
7
6
  from . import server_pb2 as server__pb2
8
7
 
9
- GRPC_GENERATED_VERSION = '1.66.1'
10
- GRPC_VERSION = grpc.__version__
11
- _version_not_supported = False
12
-
13
- try:
14
- from grpc._utilities import first_version_is_lower
15
- _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
16
- except ImportError:
17
- _version_not_supported = True
18
-
19
- if _version_not_supported:
20
- raise RuntimeError(
21
- f'The grpc package installed is at version {GRPC_VERSION},'
22
- + f' but the generated code in server_pb2_grpc.py depends on'
23
- + f' grpcio>={GRPC_GENERATED_VERSION}.'
24
- + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
25
- + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
26
- )
27
-
28
8
 
29
9
  class GnetcliStub(object):
30
10
  """Missing associated documentation comment in .proto file."""
@@ -39,42 +19,42 @@ class GnetcliStub(object):
39
19
  '/gnetcli.Gnetcli/SetupHostParams',
40
20
  request_serializer=server__pb2.HostParams.SerializeToString,
41
21
  response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
42
- _registered_method=True)
22
+ )
43
23
  self.Exec = channel.unary_unary(
44
24
  '/gnetcli.Gnetcli/Exec',
45
25
  request_serializer=server__pb2.CMD.SerializeToString,
46
26
  response_deserializer=server__pb2.CMDResult.FromString,
47
- _registered_method=True)
27
+ )
48
28
  self.ExecChat = channel.stream_stream(
49
29
  '/gnetcli.Gnetcli/ExecChat',
50
30
  request_serializer=server__pb2.CMD.SerializeToString,
51
31
  response_deserializer=server__pb2.CMDResult.FromString,
52
- _registered_method=True)
32
+ )
53
33
  self.AddDevice = channel.unary_unary(
54
34
  '/gnetcli.Gnetcli/AddDevice',
55
35
  request_serializer=server__pb2.Device.SerializeToString,
56
36
  response_deserializer=server__pb2.DeviceResult.FromString,
57
- _registered_method=True)
37
+ )
58
38
  self.ExecNetconf = channel.unary_unary(
59
39
  '/gnetcli.Gnetcli/ExecNetconf',
60
40
  request_serializer=server__pb2.CMDNetconf.SerializeToString,
61
41
  response_deserializer=server__pb2.CMDResult.FromString,
62
- _registered_method=True)
42
+ )
63
43
  self.ExecNetconfChat = channel.stream_stream(
64
44
  '/gnetcli.Gnetcli/ExecNetconfChat',
65
45
  request_serializer=server__pb2.CMDNetconf.SerializeToString,
66
46
  response_deserializer=server__pb2.CMDResult.FromString,
67
- _registered_method=True)
47
+ )
68
48
  self.Download = channel.unary_unary(
69
49
  '/gnetcli.Gnetcli/Download',
70
50
  request_serializer=server__pb2.FileDownloadRequest.SerializeToString,
71
51
  response_deserializer=server__pb2.FilesResult.FromString,
72
- _registered_method=True)
52
+ )
73
53
  self.Upload = channel.unary_unary(
74
54
  '/gnetcli.Gnetcli/Upload',
75
55
  request_serializer=server__pb2.FileUploadRequest.SerializeToString,
76
56
  response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
77
- _registered_method=True)
57
+ )
78
58
 
79
59
 
80
60
  class GnetcliServicer(object):
@@ -175,7 +155,6 @@ def add_GnetcliServicer_to_server(servicer, server):
175
155
  generic_handler = grpc.method_handlers_generic_handler(
176
156
  'gnetcli.Gnetcli', rpc_method_handlers)
177
157
  server.add_generic_rpc_handlers((generic_handler,))
178
- server.add_registered_method_handlers('gnetcli.Gnetcli', rpc_method_handlers)
179
158
 
180
159
 
181
160
  # This class is part of an EXPERIMENTAL API.
@@ -193,21 +172,11 @@ class Gnetcli(object):
193
172
  wait_for_ready=None,
194
173
  timeout=None,
195
174
  metadata=None):
196
- return grpc.experimental.unary_unary(
197
- request,
198
- target,
199
- '/gnetcli.Gnetcli/SetupHostParams',
175
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/SetupHostParams',
200
176
  server__pb2.HostParams.SerializeToString,
201
177
  google_dot_protobuf_dot_empty__pb2.Empty.FromString,
202
- options,
203
- channel_credentials,
204
- insecure,
205
- call_credentials,
206
- compression,
207
- wait_for_ready,
208
- timeout,
209
- metadata,
210
- _registered_method=True)
178
+ options, channel_credentials,
179
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
211
180
 
212
181
  @staticmethod
213
182
  def Exec(request,
@@ -220,21 +189,11 @@ class Gnetcli(object):
220
189
  wait_for_ready=None,
221
190
  timeout=None,
222
191
  metadata=None):
223
- return grpc.experimental.unary_unary(
224
- request,
225
- target,
226
- '/gnetcli.Gnetcli/Exec',
192
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/Exec',
227
193
  server__pb2.CMD.SerializeToString,
228
194
  server__pb2.CMDResult.FromString,
229
- options,
230
- channel_credentials,
231
- insecure,
232
- call_credentials,
233
- compression,
234
- wait_for_ready,
235
- timeout,
236
- metadata,
237
- _registered_method=True)
195
+ options, channel_credentials,
196
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
238
197
 
239
198
  @staticmethod
240
199
  def ExecChat(request_iterator,
@@ -247,21 +206,11 @@ class Gnetcli(object):
247
206
  wait_for_ready=None,
248
207
  timeout=None,
249
208
  metadata=None):
250
- return grpc.experimental.stream_stream(
251
- request_iterator,
252
- target,
253
- '/gnetcli.Gnetcli/ExecChat',
209
+ return grpc.experimental.stream_stream(request_iterator, target, '/gnetcli.Gnetcli/ExecChat',
254
210
  server__pb2.CMD.SerializeToString,
255
211
  server__pb2.CMDResult.FromString,
256
- options,
257
- channel_credentials,
258
- insecure,
259
- call_credentials,
260
- compression,
261
- wait_for_ready,
262
- timeout,
263
- metadata,
264
- _registered_method=True)
212
+ options, channel_credentials,
213
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
265
214
 
266
215
  @staticmethod
267
216
  def AddDevice(request,
@@ -274,21 +223,11 @@ class Gnetcli(object):
274
223
  wait_for_ready=None,
275
224
  timeout=None,
276
225
  metadata=None):
277
- return grpc.experimental.unary_unary(
278
- request,
279
- target,
280
- '/gnetcli.Gnetcli/AddDevice',
226
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/AddDevice',
281
227
  server__pb2.Device.SerializeToString,
282
228
  server__pb2.DeviceResult.FromString,
283
- options,
284
- channel_credentials,
285
- insecure,
286
- call_credentials,
287
- compression,
288
- wait_for_ready,
289
- timeout,
290
- metadata,
291
- _registered_method=True)
229
+ options, channel_credentials,
230
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
292
231
 
293
232
  @staticmethod
294
233
  def ExecNetconf(request,
@@ -301,21 +240,11 @@ class Gnetcli(object):
301
240
  wait_for_ready=None,
302
241
  timeout=None,
303
242
  metadata=None):
304
- return grpc.experimental.unary_unary(
305
- request,
306
- target,
307
- '/gnetcli.Gnetcli/ExecNetconf',
243
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/ExecNetconf',
308
244
  server__pb2.CMDNetconf.SerializeToString,
309
245
  server__pb2.CMDResult.FromString,
310
- options,
311
- channel_credentials,
312
- insecure,
313
- call_credentials,
314
- compression,
315
- wait_for_ready,
316
- timeout,
317
- metadata,
318
- _registered_method=True)
246
+ options, channel_credentials,
247
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
319
248
 
320
249
  @staticmethod
321
250
  def ExecNetconfChat(request_iterator,
@@ -328,21 +257,11 @@ class Gnetcli(object):
328
257
  wait_for_ready=None,
329
258
  timeout=None,
330
259
  metadata=None):
331
- return grpc.experimental.stream_stream(
332
- request_iterator,
333
- target,
334
- '/gnetcli.Gnetcli/ExecNetconfChat',
260
+ return grpc.experimental.stream_stream(request_iterator, target, '/gnetcli.Gnetcli/ExecNetconfChat',
335
261
  server__pb2.CMDNetconf.SerializeToString,
336
262
  server__pb2.CMDResult.FromString,
337
- options,
338
- channel_credentials,
339
- insecure,
340
- call_credentials,
341
- compression,
342
- wait_for_ready,
343
- timeout,
344
- metadata,
345
- _registered_method=True)
263
+ options, channel_credentials,
264
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
346
265
 
347
266
  @staticmethod
348
267
  def Download(request,
@@ -355,21 +274,11 @@ class Gnetcli(object):
355
274
  wait_for_ready=None,
356
275
  timeout=None,
357
276
  metadata=None):
358
- return grpc.experimental.unary_unary(
359
- request,
360
- target,
361
- '/gnetcli.Gnetcli/Download',
277
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/Download',
362
278
  server__pb2.FileDownloadRequest.SerializeToString,
363
279
  server__pb2.FilesResult.FromString,
364
- options,
365
- channel_credentials,
366
- insecure,
367
- call_credentials,
368
- compression,
369
- wait_for_ready,
370
- timeout,
371
- metadata,
372
- _registered_method=True)
280
+ options, channel_credentials,
281
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
373
282
 
374
283
  @staticmethod
375
284
  def Upload(request,
@@ -382,18 +291,8 @@ class Gnetcli(object):
382
291
  wait_for_ready=None,
383
292
  timeout=None,
384
293
  metadata=None):
385
- return grpc.experimental.unary_unary(
386
- request,
387
- target,
388
- '/gnetcli.Gnetcli/Upload',
294
+ return grpc.experimental.unary_unary(request, target, '/gnetcli.Gnetcli/Upload',
389
295
  server__pb2.FileUploadRequest.SerializeToString,
390
296
  google_dot_protobuf_dot_empty__pb2.Empty.FromString,
391
- options,
392
- channel_credentials,
393
- insecure,
394
- call_credentials,
395
- compression,
396
- wait_for_ready,
397
- timeout,
398
- metadata,
399
- _registered_method=True)
297
+ options, channel_credentials,
298
+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: gnetclisdk
3
- Version: 1.0.55
3
+ Version: 1.0.57
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
@@ -16,6 +16,15 @@ Description-Content-Type: text/markdown
16
16
  Requires-Dist: protobuf>=4.24.4
17
17
  Requires-Dist: grpcio>=1.59.2
18
18
  Requires-Dist: googleapis-common-protos>=1.61.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license
26
+ Dynamic: requires-dist
27
+ Dynamic: summary
19
28
 
20
29
  ## Python client for Gnetcli GRPC server
21
30
 
@@ -27,13 +36,14 @@ See documentation on [gnetcli server](https://annetutil.github.io/gnetcli/).
27
36
  Example:
28
37
 
29
38
  ```python
30
- from gnetclisdk.client import Credentials, Gnetcli
39
+ from gnetclisdk.client import Credentials, Gnetcli, HostParams
31
40
  import os, asyncio
32
41
 
33
42
  async def example():
34
43
  api = Gnetcli(insecure_grpc=True)
44
+ # api = Gnetcli(insecure_grpc=True, auth_token="Basic " + base64.b64encode(f"{username}:{password}".encode('utf-8')).decode("ascii")
35
45
  dev_creds = Credentials(os.environ.get("LOGIN"), os.environ.get("PASSWORD"))
36
- res = await api.cmd(hostname="myhost", device="huawei", cmd="dis clock", credentials=dev_creds)
46
+ res = await api.cmd(hostname="myhost", cmd="dis clock", host_params=HostParams(device="huawei", credentials=dev_creds))
37
47
  print("err=%s status=%s out=%s" % (res.error, res.status, res.out))
38
48
 
39
49
  asyncio.run(example())
@@ -0,0 +1,11 @@
1
+ gnetclisdk/auth.py,sha256=GwM7H7Ecb-gwqUTkQorifNB_mtnZfgeS46gOW2Vx1U4,1246
2
+ gnetclisdk/client.py,sha256=sqmqNas7NU1Q24SQjiA_8PCW47XqxP7pJyyzhL1mL0w,18486
3
+ gnetclisdk/exceptions.py,sha256=d0Bcq8tnAzemCuCCrGJEmL_A1IQxCCLFRCwDhr9zvkU,2683
4
+ gnetclisdk/interceptors.py,sha256=apj3l4lnR2ZcsA49odptrBC0kTDmP6Mp0EzYkeEJz9Y,7010
5
+ gnetclisdk/proto/server_pb2.py,sha256=OQsW6Oh38zf-h1ctcNyeOyxjl5wzWm_D9SRT2Usx5q4,8083
6
+ gnetclisdk/proto/server_pb2.pyi,sha256=th-HnFVkR1ZEY-XmFmk8VMfDj_4uFAoSAXH61mSlVec,8295
7
+ gnetclisdk/proto/server_pb2_grpc.py,sha256=H_CmevWcjvGTvp4TmzEV-TJRPq2SsQ6UgoCDc-hosyo,12805
8
+ gnetclisdk-1.0.57.dist-info/METADATA,sha256=IkhRQT42qLY_nZqtrfn26evXM6tpGTs2qKviAPy_p2I,1793
9
+ gnetclisdk-1.0.57.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ gnetclisdk-1.0.57.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
11
+ gnetclisdk-1.0.57.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- gnetclisdk/auth.py,sha256=GwM7H7Ecb-gwqUTkQorifNB_mtnZfgeS46gOW2Vx1U4,1246
2
- gnetclisdk/client.py,sha256=bT5lG7g3excrz39ZexCSNg4CBKGSlgMUGLrDC3hnUgM,18325
3
- gnetclisdk/exceptions.py,sha256=d0Bcq8tnAzemCuCCrGJEmL_A1IQxCCLFRCwDhr9zvkU,2683
4
- gnetclisdk/interceptors.py,sha256=apj3l4lnR2ZcsA49odptrBC0kTDmP6Mp0EzYkeEJz9Y,7010
5
- gnetclisdk/proto/server_pb2.py,sha256=YL1_7wubJbSp97OeRZ_L9qJjbM2U-PMcfOg-_QpkjWs,8360
6
- gnetclisdk/proto/server_pb2.pyi,sha256=th-HnFVkR1ZEY-XmFmk8VMfDj_4uFAoSAXH61mSlVec,8295
7
- gnetclisdk/proto/server_pb2_grpc.py,sha256=rjuNEIfeqwFw99oSiWUyvNKCKPgITJZKcL8pQPbUQvM,14967
8
- gnetclisdk-1.0.55.dist-info/METADATA,sha256=WdrhVtsMpXWn_blU_UM-eswKsP5herYMsNUZbevAdd0,1431
9
- gnetclisdk-1.0.55.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
10
- gnetclisdk-1.0.55.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
11
- gnetclisdk-1.0.55.dist-info/RECORD,,