Browse Source

feature:新增llnw的证书列表获取接口

YuXinLong 1 year ago
parent
commit
8eb8503d3a
7 changed files with 206 additions and 68 deletions
  1. 1 1
      proto
  2. 31 23
      src/llnwCERT_pb2.py
  3. 30 1
      src/llnwCERT_pb2.pyi
  4. 33 0
      src/llnwCERT_pb2_grpc.py
  5. 15 0
      src/main.py
  6. 2 1
      src/test.py
  7. 94 42
      测试.ipynb

+ 1 - 1
proto

@@ -1 +1 @@
-Subproject commit 820cb9578345c76cbb5c0cd94c90af5b3920d013
+Subproject commit fd50462f6a8a6773c39cb1e6aeee94eeb5392038

File diff suppressed because it is too large
+ 31 - 23
src/llnwCERT_pb2.py


+ 30 - 1
src/llnwCERT_pb2.pyi

@@ -1,6 +1,7 @@
+from google.protobuf.internal import containers as _containers
 from google.protobuf import descriptor as _descriptor
 from google.protobuf import message as _message
-from typing import ClassVar as _ClassVar, Mapping as _Mapping, Optional as _Optional, Union as _Union
+from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
 
 DESCRIPTOR: _descriptor.FileDescriptor
 
@@ -12,6 +13,20 @@ class Base(_message.Message):
     username: str
     def __init__(self, username: _Optional[str] = ..., key: _Optional[str] = ...) -> None: ...
 
+class Cert(_message.Message):
+    __slots__ = ["certName", "certStatus"]
+    CERTNAME_FIELD_NUMBER: _ClassVar[int]
+    CERTSTATUS_FIELD_NUMBER: _ClassVar[int]
+    certName: str
+    certStatus: str
+    def __init__(self, certName: _Optional[str] = ..., certStatus: _Optional[str] = ...) -> None: ...
+
+class CertList(_message.Message):
+    __slots__ = ["cert"]
+    CERT_FIELD_NUMBER: _ClassVar[int]
+    cert: _containers.RepeatedCompositeFieldContainer[Cert]
+    def __init__(self, cert: _Optional[_Iterable[_Union[Cert, _Mapping]]] = ...) -> None: ...
+
 class CreateSSLCertRequest(_message.Message):
     __slots__ = ["base", "cert", "certKey", "certName", "shortname"]
     BASE_FIELD_NUMBER: _ClassVar[int]
@@ -46,6 +61,20 @@ class DeleteSSLCertResponse(_message.Message):
     isSuccess: bool
     def __init__(self, isSuccess: bool = ...) -> None: ...
 
+class ListSSLCertRequest(_message.Message):
+    __slots__ = ["base", "shortname"]
+    BASE_FIELD_NUMBER: _ClassVar[int]
+    SHORTNAME_FIELD_NUMBER: _ClassVar[int]
+    base: Base
+    shortname: str
+    def __init__(self, base: _Optional[_Union[Base, _Mapping]] = ..., shortname: _Optional[str] = ...) -> None: ...
+
+class ListSSLCertResponse(_message.Message):
+    __slots__ = ["certList"]
+    CERTLIST_FIELD_NUMBER: _ClassVar[int]
+    certList: CertList
+    def __init__(self, certList: _Optional[_Union[CertList, _Mapping]] = ...) -> None: ...
+
 class PublishSSLCertRequest(_message.Message):
     __slots__ = ["base", "uuid"]
     BASE_FIELD_NUMBER: _ClassVar[int]

+ 33 - 0
src/llnwCERT_pb2_grpc.py

@@ -39,6 +39,11 @@ class CertDeliveryServiceStub(object):
                 request_serializer=llnwCERT__pb2.WithdrawSSLCertRequest.SerializeToString,
                 response_deserializer=llnwCERT__pb2.WithdrawSSLCertResponse.FromString,
                 )
+        self.ListSSLCert = channel.unary_unary(
+                '/llnwApi.Delivery.CERT.CertDeliveryService/ListSSLCert',
+                request_serializer=llnwCERT__pb2.ListSSLCertRequest.SerializeToString,
+                response_deserializer=llnwCERT__pb2.ListSSLCertResponse.FromString,
+                )
 
 
 class CertDeliveryServiceServicer(object):
@@ -74,6 +79,12 @@ class CertDeliveryServiceServicer(object):
         context.set_details('Method not implemented!')
         raise NotImplementedError('Method not implemented!')
 
+    def ListSSLCert(self, request, context):
+        """Missing associated documentation comment in .proto file."""
+        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+        context.set_details('Method not implemented!')
+        raise NotImplementedError('Method not implemented!')
+
 
 def add_CertDeliveryServiceServicer_to_server(servicer, server):
     rpc_method_handlers = {
@@ -102,6 +113,11 @@ def add_CertDeliveryServiceServicer_to_server(servicer, server):
                     request_deserializer=llnwCERT__pb2.WithdrawSSLCertRequest.FromString,
                     response_serializer=llnwCERT__pb2.WithdrawSSLCertResponse.SerializeToString,
             ),
+            'ListSSLCert': grpc.unary_unary_rpc_method_handler(
+                    servicer.ListSSLCert,
+                    request_deserializer=llnwCERT__pb2.ListSSLCertRequest.FromString,
+                    response_serializer=llnwCERT__pb2.ListSSLCertResponse.SerializeToString,
+            ),
     }
     generic_handler = grpc.method_handlers_generic_handler(
             'llnwApi.Delivery.CERT.CertDeliveryService', rpc_method_handlers)
@@ -196,3 +212,20 @@ class CertDeliveryService(object):
             llnwCERT__pb2.WithdrawSSLCertResponse.FromString,
             options, channel_credentials,
             insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
+
+    @staticmethod
+    def ListSSLCert(request,
+            target,
+            options=(),
+            channel_credentials=None,
+            call_credentials=None,
+            insecure=False,
+            compression=None,
+            wait_for_ready=None,
+            timeout=None,
+            metadata=None):
+        return grpc.experimental.unary_unary(request, target, '/llnwApi.Delivery.CERT.CertDeliveryService/ListSSLCert',
+            llnwCERT__pb2.ListSSLCertRequest.SerializeToString,
+            llnwCERT__pb2.ListSSLCertResponse.FromString,
+            options, channel_credentials,
+            insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

+ 15 - 0
src/main.py

@@ -39,6 +39,13 @@ def delivery_to_grpc(delivery):
     )
 
 
+def cert_list_to_grpc(cert):
+    return Cert(
+        certName=cert.get('certName', None),
+        certStatus=cert.get('certStatus', None)
+    )
+
+
 def delivery_from_grpc(delivery_entity: DeliveryEntity):
     return {
         "uuid": delivery_entity.uuid,
@@ -356,6 +363,14 @@ class CertDeliveryServiceServicer(llnwCERT_pb2_grpc.CertDeliveryServiceServicer)
         else:
             return check_cert_withdraw_error(res)
 
+    def GetCertList(self, request, context):
+        print("GetCertList")
+        print("请求:", request)
+        res = get_cl(request.base).list_customer_certificates(shortname=request.shortname).json()
+        print("响应:", res)
+        check_error(res, context)
+        return ListSSLCertResponse(certList=CertList([cert_list_to_grpc(results) for results in res['results']]))
+
 
 if __name__ == '__main__':
     server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

+ 2 - 1
src/test.py

@@ -12,10 +12,11 @@ if __name__ == '__main__':
     e = stub.ListDeliveryServiceInstances(ShortNameRequest(base=Base(username=username, key=shared_key), shortName=short_name))
     print(str(e))
 
-    #
+
     # cl = ConfigApiClient('apis.llnw.com', username, shared_key)
     # res = cl.list_delivery_service_instances("centtest")
     # print(res.json())
     # print(cl.get_status().json())
     # print(cl.get_health_check().json())
     # exit(0)
+

File diff suppressed because it is too large
+ 94 - 42
测试.ipynb