gnetclisdk 1.0.32__py3-none-any.whl → 1.0.33__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- gnetclisdk/client.py +33 -20
- {gnetclisdk-1.0.32.dist-info → gnetclisdk-1.0.33.dist-info}/METADATA +1 -1
- {gnetclisdk-1.0.32.dist-info → gnetclisdk-1.0.33.dist-info}/RECORD +5 -5
- {gnetclisdk-1.0.32.dist-info → gnetclisdk-1.0.33.dist-info}/WHEEL +1 -1
- {gnetclisdk-1.0.32.dist-info → gnetclisdk-1.0.33.dist-info}/top_level.txt +0 -0
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) ->
|
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) ->
|
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=
|
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
|
-
) ->
|
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
|
-
|
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
|
-
) ->
|
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
|
-
) ->
|
458
|
-
qa_cmd: List[
|
470
|
+
) -> server_pb2.CMD:
|
471
|
+
qa_cmd: List[server_pb2.QA] = []
|
459
472
|
if qa:
|
460
473
|
for item in qa:
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
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=
|
485
|
+
host_params=host_params_pb,
|
473
486
|
)
|
474
|
-
return res
|
487
|
+
return res
|
475
488
|
|
476
489
|
|
477
490
|
def make_files_request(files: Dict[str, File]) -> List[server_pb2.FileData]:
|
@@ -1,11 +1,11 @@
|
|
1
1
|
gnetclisdk/auth.py,sha256=GwM7H7Ecb-gwqUTkQorifNB_mtnZfgeS46gOW2Vx1U4,1246
|
2
|
-
gnetclisdk/client.py,sha256=
|
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.
|
9
|
-
gnetclisdk-1.0.
|
10
|
-
gnetclisdk-1.0.
|
11
|
-
gnetclisdk-1.0.
|
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,,
|
File without changes
|