gnetclisdk 1.0.54__py3-none-any.whl → 1.0.56__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 +8 -3
- {gnetclisdk-1.0.54.dist-info → gnetclisdk-1.0.56.dist-info}/METADATA +14 -4
- {gnetclisdk-1.0.54.dist-info → gnetclisdk-1.0.56.dist-info}/RECORD +5 -5
- {gnetclisdk-1.0.54.dist-info → gnetclisdk-1.0.56.dist-info}/WHEEL +1 -1
- {gnetclisdk-1.0.54.dist-info → gnetclisdk-1.0.56.dist-info}/top_level.txt +0 -0
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,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: gnetclisdk
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.56
|
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",
|
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())
|
@@ -1,11 +1,11 @@
|
|
1
1
|
gnetclisdk/auth.py,sha256=GwM7H7Ecb-gwqUTkQorifNB_mtnZfgeS46gOW2Vx1U4,1246
|
2
|
-
gnetclisdk/client.py,sha256=
|
2
|
+
gnetclisdk/client.py,sha256=sqmqNas7NU1Q24SQjiA_8PCW47XqxP7pJyyzhL1mL0w,18486
|
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.
|
9
|
-
gnetclisdk-1.0.
|
10
|
-
gnetclisdk-1.0.
|
11
|
-
gnetclisdk-1.0.
|
8
|
+
gnetclisdk-1.0.56.dist-info/METADATA,sha256=YZa8pUMCg2EU7l84hq2Pk6gns0bnEM8lr2BU5g4rt8k,1793
|
9
|
+
gnetclisdk-1.0.56.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
gnetclisdk-1.0.56.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
|
11
|
+
gnetclisdk-1.0.56.dist-info/RECORD,,
|
File without changes
|