Python: add possibility to modify also the public key address of
authorjani <jani@asema.com>
Mon, 5 Aug 2019 11:27:31 +0000 (14:27 +0300)
committerjani <jani@asema.com>
Mon, 5 Aug 2019 11:27:31 +0000 (14:27 +0300)
RegistrationAgent

Common/Python/SmartAPI/agents/RegistrationAgent.py
Examples/Python/AdaptDataService/AdaptDataService.py

index 274bbaaee5957d389f35a3c27c364235595d06db..fcb6f980c851aff64ac553431f8d49de0d7a3030 100755 (executable)
@@ -32,7 +32,11 @@ class RegistrationAgent(Agent):
         self.debug = False
         self.locked = False # switch to mark registration as locked so others cannot overwrite
         self.serverAddress = FIND_URI  # uri of the SMARTAPI registration service
+        self.serverKeyAddress = FIND_KEY_URI # uri from where the public key can be fecthed from
     
+    def setServerKeyAddress(self, registrationServerKeyUri):
+        self.serverKeyAddress = registrationServerKeyUri
+            
     def registrateAndLock(self):
         self.locked = True
         resp = self.registrate()
@@ -76,7 +80,7 @@ class RegistrationAgent(Agent):
                 # decrypt and return
                 activity = activity.decrypt(self.aesKey)
             
-                if self.debug:
+                if self.debug and activity is not None:
                     print"\nRegistration activity:"
                     activity.turtlePrint()
             
@@ -177,7 +181,7 @@ class RegistrationAgent(Agent):
         keyString = ""
         key = None
         try:
-            keyString = HttpClient().sendGet(FIND_KEY_URI)
+            keyString = HttpClient().sendGet(self.serverKeyAddress)
             key = SmartAPICrypto().extractPemFormatPublicKey(keyString, "RSA");
         except:
             print "Failed to get a key from the registration server."
index 3270e2f457f4a5a6582e795b88d99367e432aafc..38e0a53d5cd1fd51355ff13cdec2fdd8a41ba0b7 100755 (executable)
@@ -27,7 +27,9 @@ from SmartAPI.model.ValueObject import ValueObject
 
 myIdentity = "http://adapt.asema.com/demos/python/datasource/"
 adaptServiceIdentity = "http://adapt.asema.com"
-registrationServerUri = "http://find.smart-api.io/smart/v1.0e1.0/access"
+#registrationServerUri = "http://find.smart-api.io/smart/v1.0e1.0/access"
+registrationServerUri = "http://192.168.2.96:8080/smartapifind-core/smart/v1.0e1.0/access"
+registrationServerKeyUri = "http://192.168.2.96:8080/smartapifind-core/smart/v1.0e1.0/key"
 
 PORT = 8111
 
@@ -42,6 +44,7 @@ class SampleRegistration(object):
        def run(self):
                agent = RegistrationAgent(myIdentity)
                agent.setServerAddress(registrationServerUri)
+               agent.setServerKeyAddress(registrationServerKeyUri)
                agent.setDebugMode(True)
 
                # registrate