From 903b06f59e55488b552fb48665e9349997a6cda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Mon, 17 Jun 2019 10:41:10 +0200 Subject: [PATCH] Make Ursula.rest_interface() a property. Remove Character.rest_interface --- nucypher/characters/base.py | 4 ---- nucypher/characters/lawful.py | 5 +++-- nucypher/characters/unlawful.py | 4 ++-- nucypher/network/nodes.py | 6 +++--- nucypher/network/protocols.py | 3 +++ nucypher/utilities/sandbox/middleware.py | 6 +++--- nucypher/utilities/sandbox/ursula.py | 4 ++-- tests/characters/test_bob_handles_frags.py | 2 +- tests/characters/test_crypto_characters_and_their_powers.py | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/nucypher/characters/base.py b/nucypher/characters/base.py index 5bdd33b7c..099f9bc5b 100644 --- a/nucypher/characters/base.py +++ b/nucypher/characters/base.py @@ -238,10 +238,6 @@ class Character(Learner): def name(self): return self.__class__.__name__ - @property - def rest_interface(self): - return self.rest_server.rest_url() - @property def stamp(self): if self._stamp is NO_SIGNING_POWER: diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index 72f9a32a4..1e698587b 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -986,11 +986,12 @@ class Ursula(Teacher, Character, Worker): hosting_power.keypair.pubkey ) + @property def rest_interface(self): return self.rest_server.rest_interface def get_deployer(self): - port = self.rest_interface().port + port = self.rest_interface.port deployer = self._crypto_power.power_ups(TLSHostingPower).get_deployer(rest_app=self.rest_app, port=port) return deployer @@ -1000,7 +1001,7 @@ class Ursula(Teacher, Character, Worker): def __bytes__(self): version = self.TEACHER_VERSION.to_bytes(2, "big") - interface_info = VariableLengthBytestring(bytes(self.rest_interface())) + interface_info = VariableLengthBytestring(bytes(self.rest_interface)) decentralized_identity_evidence = VariableLengthBytestring(self.decentralized_identity_evidence) certificate = self.rest_server_certificate() diff --git a/nucypher/characters/unlawful.py b/nucypher/characters/unlawful.py index 02a879b0c..319010c0e 100644 --- a/nucypher/characters/unlawful.py +++ b/nucypher/characters/unlawful.py @@ -54,8 +54,8 @@ class Vladimir(Ursula): vladimir = cls(is_me=True, crypto_power=crypto_power, db_filepath=cls.db_filepath, - rest_host=target_ursula.rest_interface().host, - rest_port=target_ursula.rest_interface().port, + rest_host=target_ursula.rest_interface.host, + rest_port=target_ursula.rest_interface.port, certificate=target_ursula.rest_server_certificate(), network_middleware=cls.network_middleware, checksum_address=cls.fraud_address, diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index cfe8aecef..a6c979fb5 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -1105,8 +1105,8 @@ class Teacher: else: certificate_filepath = self.certificate_filepath - response_data = network_middleware.node_information(host=self.rest_interface().host, - port=self.rest_interface().port, + response_data = network_middleware.node_information(host=self.rest_interface.host, + port=self.rest_interface.port, certificate_filepath=certificate_filepath) version, node_bytes = self.version_splitter(response_data, return_remainder=True) @@ -1170,7 +1170,7 @@ class Teacher: raise self.InvalidNode def _signable_interface_info_message(self): - message = self.canonical_public_address + self.rest_interface() + message = self.canonical_public_address + self.rest_interface return message def _sign_and_date_interface_info(self): diff --git a/nucypher/network/protocols.py b/nucypher/network/protocols.py index 630225d8a..1f61ad487 100644 --- a/nucypher/network/protocols.py +++ b/nucypher/network/protocols.py @@ -84,3 +84,6 @@ class InterfaceInfo: def __radd__(self, other): return bytes(other) + bytes(self) + + def __repr__(self): + return self.uri diff --git a/nucypher/utilities/sandbox/middleware.py b/nucypher/utilities/sandbox/middleware.py index bf4b9ed7a..d5152969c 100644 --- a/nucypher/utilities/sandbox/middleware.py +++ b/nucypher/utilities/sandbox/middleware.py @@ -34,7 +34,7 @@ class _TestMiddlewareClient(NucypherMiddlewareClient): return response def _get_mock_client_by_ursula(self, ursula): - port = ursula.rest_interface().port + port = ursula.rest_interface.port return self._get_mock_client_by_port(port) def _get_mock_client_by_url(self, url): @@ -128,10 +128,10 @@ class NodeIsDownMiddleware(MockRestMiddleware): self.ports_that_are_down = [] def node_is_down(self, node): - self.client.ports_that_are_down.add(node.rest_interface().port) + self.client.ports_that_are_down.add(node.rest_interface.port) def node_is_up(self, node): - self.client.ports_that_are_down.remove(node.rest_interface().port) + self.client.ports_that_are_down.remove(node.rest_interface.port) class EvilMiddleWare(MockRestMiddleware): diff --git a/nucypher/utilities/sandbox/ursula.py b/nucypher/utilities/sandbox/ursula.py index 17081e777..a4c768bcb 100644 --- a/nucypher/utilities/sandbox/ursula.py +++ b/nucypher/utilities/sandbox/ursula.py @@ -51,7 +51,7 @@ def make_federated_ursulas(ursula_config: UrsulaConfiguration, # Store this Ursula in our global testing cache. - port = ursula.rest_interface().port + port = ursula.rest_interface.port MOCK_KNOWN_URSULAS_CACHE[port] = ursula if know_each_other: @@ -92,7 +92,7 @@ def make_decentralized_ursulas(ursula_config: UrsulaConfiguration, ursulas.append(ursula) # Store this Ursula in our global cache. - port = ursula.rest_interface().port + port = ursula.rest_interface.port MOCK_KNOWN_URSULAS_CACHE[port] = ursula return ursulas diff --git a/tests/characters/test_bob_handles_frags.py b/tests/characters/test_bob_handles_frags.py index d0caf3106..20a7c315e 100644 --- a/tests/characters/test_bob_handles_frags.py +++ b/tests/characters/test_bob_handles_frags.py @@ -195,7 +195,7 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_polic # OK, so cool - Bob has his cFrag! Let's make sure everything went properly. First, we'll show that it is in fact # the correct cFrag (ie, that Ursula performed re-encryption properly). for u in federated_ursulas: - if u.rest_interface().port == work_order.ursula.rest_interface().port: + if u.rest_interface.port == work_order.ursula.rest_interface.port: ursula = u break else: diff --git a/tests/characters/test_crypto_characters_and_their_powers.py b/tests/characters/test_crypto_characters_and_their_powers.py index 0203869b3..75070ab99 100644 --- a/tests/characters/test_crypto_characters_and_their_powers.py +++ b/tests/characters/test_crypto_characters_and_their_powers.py @@ -175,7 +175,7 @@ def test_anybody_can_encrypt(): def test_node_deployer(federated_ursulas): for ursula in federated_ursulas: deployer = ursula.get_deployer() - assert deployer.options['https_port'] == ursula.rest_interface().port + assert deployer.options['https_port'] == ursula.rest_interface.port assert deployer.application == ursula.rest_app