Skip to content

Commit 26689b7

Browse files
committed
Added Delete Cert features
1 parent ba93672 commit 26689b7

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

kepconfig/ua_gateway/client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
r"""`client` exposes an API to allow modifications (add, delete, modify) to
88
UA Gateway plug-in client connection objects within the Kepware Configuration API.
9-
Certificate read and trust functionality is also available for the client connections.
9+
Certificate store read, remove and trust functionality is also available for the
10+
client connections.
1011
"""
1112

1213
from typing import Union
1314
from ..connection import server
1415
from ..error import KepError, KepHTTPError
15-
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_client
16+
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_client, _delete_cert_truststore
1617

1718
def get_certificate(server: server, certificate: str) -> dict:
1819
'''Returns the properties of the UAG client connection certificate object in the UAG client connection
@@ -75,6 +76,19 @@ def reject_certificate(server: server, certificate: str) -> bool:
7576

7677
return _change_cert_trust(server, _INTER_TYPE.CLIENT, certificate, False)
7778

79+
def delete_certificate(server: server, certificate: str) -> bool:
80+
'''Deletes the certificate in the UAG client endpoint certificate store.
81+
82+
:param server: instance of the `server` class
83+
:param certificate: name of certificate
84+
85+
:return: True - If a "HTTP 200 - OK" is received from Kepware server
86+
87+
:raises KepHTTPError: If urllib provides an HTTPError
88+
:raises KepURLError: If urllib provides an URLError
89+
'''
90+
return _delete_cert_truststore(server, _INTER_TYPE.CLIENT, certificate)
91+
7892
def get_ua_client_connection(server: server, ua_client_connection: str) -> dict:
7993
'''Returns the properties of the UAG client connection object.
8094

kepconfig/ua_gateway/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class _INTER_TYPE(Enum):
2626
CLIENT = 1
2727
CERTS = 2
2828

29+
INSTANCE_CERTIFICATE = "Instance Certificate"
2930

3031
def _create_url_cert(interface, certificate = None):
3132
'''Creates url object for the "certificate" branch of Kepware's UA Gateway. Used
@@ -59,6 +60,12 @@ def _change_cert_trust(server: server, inter_type, certificate: str, trust: bool
5960
if r.code == 200: return True
6061
else:
6162
raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
63+
64+
def _delete_cert_truststore(server: server, inter_type, certificate: str):
65+
r = server._config_del(server.url + _create_url_cert(inter_type, certificate))
66+
if r.code == 200: return True
67+
else:
68+
raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
6269

6370
def _create_url_server(ua_server_endpoint = None):
6471
'''Creates url object for the "ua_server_endpoints" branch of Kepware's UA Gateway. Used

kepconfig/ua_gateway/server.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
r"""`server` exposes an API to allow modifications (add, delete, modify) to
88
UA Gateway plug-in server endpoint objects within the Kepware Configuration API.
9-
Certificate read and trust functionality is also available for the server endpoints.
9+
Certificate store read, remove and trust functionality is also available for the
10+
server endpoints.
1011
"""
1112

1213
from typing import Union
1314
from ..connection import server
1415
from ..error import KepError, KepHTTPError
15-
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_server
16+
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_server, _delete_cert_truststore
1617

1718

1819
def get_certificate(server: server, certificate: str) -> dict:
@@ -49,7 +50,7 @@ def get_all_certificates(server: server, *, options: dict = None) -> list:
4950
return r.payload
5051

5152
def trust_certificate(server: server, certificate: str) -> bool:
52-
'''Trusts the certificate in the UAG server endpoint certifcate store. This is updating the trust state of UA client instance
53+
'''Trusts the certificate in the UAG server endpoint certificate store. This is updating the trust state of UA client instance
5354
certificates that are used by UAG server endpoints for trust purposes in the UA security model.
5455
5556
:param server: instance of the `server` class
@@ -63,7 +64,7 @@ def trust_certificate(server: server, certificate: str) -> bool:
6364
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, True)
6465

6566
def reject_certificate(server: server, certificate: str) -> bool:
66-
'''Rejects the certificate in the UAG server endpoint certifcate store.
67+
'''Rejects the certificate in the UAG server endpoint certificate store.
6768
6869
:param server: instance of the `server` class
6970
:param certificate: name of certificate
@@ -75,6 +76,19 @@ def reject_certificate(server: server, certificate: str) -> bool:
7576
'''
7677
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, False)
7778

79+
def delete_certificate(server: server, certificate: str) -> bool:
80+
'''Deletes the certificate in the UAG server endpoint certificate store.
81+
82+
:param server: instance of the `server` class
83+
:param certificate: name of certificate
84+
85+
:return: True - If a "HTTP 200 - OK" is received from Kepware server
86+
87+
:raises KepHTTPError: If urllib provides an HTTPError
88+
:raises KepURLError: If urllib provides an URLError
89+
'''
90+
return _delete_cert_truststore(server, _INTER_TYPE.SERVER, certificate)
91+
7892
def get_ua_server_endpoint(server: server, ua_server_endpoint: str) -> dict:
7993
'''Returns the properties of the UAG server endpoint object.
8094

0 commit comments

Comments
 (0)