--- a/runtime/WampClient.py Wed Apr 02 12:07:15 2025 +0200
+++ b/runtime/WampClient.py Thu Apr 03 11:41:20 2025 +0200
@@ -267,7 +267,7 @@
- if os.path.exists(_WampConf):
+ if _WampConf and os.path.exists(_WampConf): WampClientConf = json.load(open(_WampConf))
UpdateWithDefault(WampClientConf, defaultWampConfig)
@@ -315,24 +315,12 @@
return re.match(r'wss?://[^\s?:#-]+(:[0-9]+)?(/[^\s]*)?$', uri) is not None
-def RegisterWampClient(wampconf=None, wampsecret=None, ConfDir=None, KeyStore=None, servicename=None):
- from twisted.internet import reactor
- global _WampConf, _WampSecret, _WampSercretFile, _WampClientCert, _WampTrust, defaultWampConfig
- defaultWampConfig["ID"] = servicename
+def PrepWampClientConfig(wampconf, ConfDir): ConfDir = ConfDir if ConfDir else WorkingDir
- KeyStore = KeyStore if KeyStore else WorkingDir
_WampConfDefault = os.path.join(ConfDir, "wampconf.json")
- _WampSecretDefault = os.path.join(KeyStore, "wamp.secret")
- if _WampClientCert is None:
- _WampClientCert = os.path.join(KeyStore, "wampClientCert.pem")
- _WampTrust = os.path.join(KeyStore, "wampTrustStore.crt")
# set config file path only if not already set
@@ -342,7 +330,27 @@
- WampClientConf = GetConfiguration()
+ return GetConfiguration() +def RegisterWampClient(wampconf=None, wampsecret=None, ConfDir=None, KeyStore=None, servicename=None): + from twisted.internet import reactor + global _WampConf, _WampSecret, _WampSercretFile, _WampClientCert, _WampTrust, defaultWampConfig + defaultWampConfig["ID"] = servicename + WampClientConf = PrepWampClientConfig(wampconf, ConfDir) + KeyStore = KeyStore if KeyStore else WorkingDir + _WampSecretDefault = os.path.join(KeyStore, "wamp.secret") + if _WampClientCert is None: + _WampClientCert = os.path.join(KeyStore, "wampClientCert.pem") + _WampTrust = os.path.join(KeyStore, "wampTrustStore.crt") if not WampClientConf["active"]:
print("WAMP deactivated in configuration")
@@ -370,7 +378,6 @@
reactor.callInThread(_RegisterWampClient)
def _RegisterWampClient():
global _WampSecret, _transportFactory
@@ -407,8 +414,8 @@
if os.path.exists(_WampClientCert):
client_cert = PrivateCertificate.loadPEM(open(_WampClientCert, 'rb').read())
- GetPLCObjectSingleton().LogMessage(LogLevelsDict["ERROR"],
- "WAMP client certificate not provided for:", WampClientConf["url"])
+ GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"], + "WAMP client certificate not provided for: " + WampClientConf["url"]) if os.path.exists(_WampTrust):
@@ -422,15 +429,15 @@
# non encrypted connection is not accepted in case some security is requested
if auth != AUTH_NONE or verify:
- GetPLCObjectSingleton().LogMessage(LogLevelsDict["ERROR"],
- "WAMP connection must be secure:", WampClientConf["url"])
+ GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"], + "WAMP connection must be secure: " + WampClientConf["url"]) connectWS(_transportFactory, contextFactory)
- print("WAMP client connecting to :", WampClientConf["url"])
+ print("WAMP client connecting to: " + WampClientConf["url"]) GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"],
- "WAMP configuration invalid:", WampClientConf["url"])
+ "WAMP configuration invalid: " + WampClientConf["url"]) def StopReconnectWampClient():
if _transportFactory is not None: