Skip to content

Commit 5096a29

Browse files
committed
reorder and add uag server interface methods
1 parent bf37dc6 commit 5096a29

File tree

1 file changed

+90
-59
lines changed

1 file changed

+90
-59
lines changed

kepconfig/ua_gateway/server.py

Lines changed: 90 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,39 @@
1313
from typing import Union
1414
from ..connection import server
1515
from ..error import KepError, KepHTTPError
16-
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_server, _delete_cert_truststore
16+
from ..ua_gateway.common import _INTER_TYPE, _change_cert_trust, _create_url_cert, _create_url_server, _delete_cert_truststore, SERVER_ROOT
1717

18-
19-
def get_certificate(server: server, certificate: str) -> dict:
20-
'''Returns the properties of the UAG server endpoint certificate object in the UAG client connection
21-
certificate store. These are UA client instance certificates that are used by UAG server endpoints for
22-
trust purposes in the UA security model.
23-
24-
:param server: instance of the `server` class
25-
:param certificate: name of certificate
26-
27-
:return: Dict of data for the certificate requested
18+
def get_uag_server_interface_properties(server: server) -> dict:
19+
''' Get the UAG Server Interface Properties of the Kepware instance. These properties expose User Identify
20+
Policy, Security Policy and other Communication properties that are applied across all UAG server endpoints.
21+
22+
:return: Dict of all the UAG Server Interface properties
2823
2924
:raises KepHTTPError: If urllib provides an HTTPError
3025
:raises KepURLError: If urllib provides an URLError
3126
'''
32-
r = server._config_get(server.url + _create_url_cert(_INTER_TYPE.SERVER, certificate))
33-
return r.payload
3427

35-
def get_all_certificates(server: server, *, options: dict = None) -> list:
36-
'''Returns list of all UAG server endpoint certificate objects and their properties.This is updating the trust state of UA client instance
37-
certificates that are used by UAG server endpoints for trust purposes in the UA security model. These are UA client instance certificates
38-
that are used by UAG server endpoints for trust purposes in the UA security model.
39-
40-
:param server: instance of the `server` class
41-
:param options: *(optional)* Dict of parameters to filter, sort or pagenate the list of certificates. Options are `filter`,
42-
`sortOrder`, `sortProperty`, `pageNumber`, and `pageSize`
43-
44-
:return: List of data for all certificates in Kepware server UAG server endpoint certificate store
45-
46-
:raises KepHTTPError: If urllib provides an HTTPError
47-
:raises KepURLError: If urllib provides an URLError
48-
'''
49-
r = server._config_get(server.url + _create_url_cert(_INTER_TYPE.SERVER), params= options)
28+
r = server._config_get(server.url + SERVER_ROOT)
5029
return r.payload
5130

52-
def trust_certificate(server: server, certificate: str) -> bool:
53-
'''Trusts the certificate in the UAG server endpoint certificate store. This is updating the trust state of UA client instance
54-
certificates that are used by UAG server endpoints for trust purposes in the UA security model.
55-
56-
:param server: instance of the `server` class
57-
:param certificate: name of certificate
58-
59-
:return: True - If a "HTTP 200 - OK" is received from Kepware server
60-
61-
:raises KepHTTPError: If urllib provides an HTTPError
62-
:raises KepURLError: If urllib provides an URLError
63-
'''
64-
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, True)
31+
def modify_uag_server_interface_properties(server: server, DATA: dict, force: bool = False) -> bool:
32+
''' Modify the UAG Server Interface Properties of the Kepware instance. These properties expose User Identify
33+
Policy, Security Policy and other Communication properties that are applied across all UAG server endpoints.
6534
66-
def reject_certificate(server: server, certificate: str) -> bool:
67-
'''Rejects the certificate in the UAG server endpoint certificate store.
68-
69-
:param server: instance of the `server` class
70-
:param certificate: name of certificate
35+
:param DATA: Dict of the UAG Server Interface properties to be modified
36+
:param force: *(optional)* if True, will force the configuration update to the Kepware server
7137
7238
:return: True - If a "HTTP 200 - OK" is received from Kepware server
7339
7440
:raises KepHTTPError: If urllib provides an HTTPError
7541
:raises KepURLError: If urllib provides an URLError
7642
'''
77-
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, False)
7843

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
44+
prop_data = server._force_update_check(force, DATA)
45+
r = server._config_update(server.url + SERVER_ROOT, prop_data)
46+
if r.code == 200: return True
47+
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
8648

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)
9149

9250
def get_ua_server_endpoint(server: server, ua_server_endpoint: str) -> dict:
9351
'''Returns the properties of the UAG server endpoint object.
@@ -193,4 +151,77 @@ def del_ua_server_endpoint(server: server, ua_server_endpoint: str) -> bool:
193151
r = server._config_del(server.url + _create_url_server(ua_server_endpoint))
194152
if r.code == 200: return True
195153
else:
196-
raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
154+
raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
155+
156+
def get_certificate(server: server, certificate: str) -> dict:
157+
'''Returns the properties of the UAG server endpoint certificate object in the UAG client connection
158+
certificate store. These are UA client instance certificates that are used by UAG server endpoints for
159+
trust purposes in the UA security model.
160+
161+
:param server: instance of the `server` class
162+
:param certificate: name of certificate
163+
164+
:return: Dict of data for the certificate requested
165+
166+
:raises KepHTTPError: If urllib provides an HTTPError
167+
:raises KepURLError: If urllib provides an URLError
168+
'''
169+
r = server._config_get(server.url + _create_url_cert(_INTER_TYPE.SERVER, certificate))
170+
return r.payload
171+
172+
def get_all_certificates(server: server, *, options: dict = None) -> list:
173+
'''Returns list of all UAG server endpoint certificate objects and their properties.This is updating the trust state of UA client instance
174+
certificates that are used by UAG server endpoints for trust purposes in the UA security model. These are UA client instance certificates
175+
that are used by UAG server endpoints for trust purposes in the UA security model.
176+
177+
:param server: instance of the `server` class
178+
:param options: *(optional)* Dict of parameters to filter, sort or pagenate the list of certificates. Options are `filter`,
179+
`sortOrder`, `sortProperty`, `pageNumber`, and `pageSize`
180+
181+
:return: List of data for all certificates in Kepware server UAG server endpoint certificate store
182+
183+
:raises KepHTTPError: If urllib provides an HTTPError
184+
:raises KepURLError: If urllib provides an URLError
185+
'''
186+
r = server._config_get(server.url + _create_url_cert(_INTER_TYPE.SERVER), params= options)
187+
return r.payload
188+
189+
def trust_certificate(server: server, certificate: str) -> bool:
190+
'''Trusts the certificate in the UAG server endpoint certificate store. This is updating the trust state of UA client instance
191+
certificates that are used by UAG server endpoints for trust purposes in the UA security model.
192+
193+
:param server: instance of the `server` class
194+
:param certificate: name of certificate
195+
196+
:return: True - If a "HTTP 200 - OK" is received from Kepware server
197+
198+
:raises KepHTTPError: If urllib provides an HTTPError
199+
:raises KepURLError: If urllib provides an URLError
200+
'''
201+
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, True)
202+
203+
def reject_certificate(server: server, certificate: str) -> bool:
204+
'''Rejects the certificate in the UAG server endpoint certificate store.
205+
206+
:param server: instance of the `server` class
207+
:param certificate: name of certificate
208+
209+
:return: True - If a "HTTP 200 - OK" is received from Kepware server
210+
211+
:raises KepHTTPError: If urllib provides an HTTPError
212+
:raises KepURLError: If urllib provides an URLError
213+
'''
214+
return _change_cert_trust(server, _INTER_TYPE.SERVER, certificate, False)
215+
216+
def delete_certificate(server: server, certificate: str) -> bool:
217+
'''Deletes the certificate in the UAG server endpoint certificate store.
218+
219+
:param server: instance of the `server` class
220+
:param certificate: name of certificate
221+
222+
:return: True - If a "HTTP 200 - OK" is received from Kepware server
223+
224+
:raises KepHTTPError: If urllib provides an HTTPError
225+
:raises KepURLError: If urllib provides an URLError
226+
'''
227+
return _delete_cert_truststore(server, _INTER_TYPE.SERVER, certificate)

0 commit comments

Comments
 (0)