mirror of https://github.com/nucypher/nucypher.git
Create an Ursula from a REST URL. Why not?
parent
672f796965
commit
de3d9e6c01
|
@ -6,7 +6,7 @@ import requests
|
|||
|
||||
from nkms.characters import Alice, Bob, Ursula, congregate
|
||||
from nkms.network.node import NetworkyStuff
|
||||
from nkms.policy.models import AgreementResponse
|
||||
from nkms.policy.models import ContractResponse
|
||||
|
||||
ALICE = Alice()
|
||||
BOB = Bob()
|
||||
|
@ -16,10 +16,10 @@ ALICE.learn_about_actor(URSULA)
|
|||
|
||||
|
||||
class SandboxNetworkyStuff(NetworkyStuff):
|
||||
def find_ursula(self, agreement=None):
|
||||
def find_ursula(self, contract=None):
|
||||
ursula = Ursula.as_discovered_on_network(None, None, pubkey_sig_bytes=bytes(URSULA.seal),
|
||||
rest_address="localhost", rest_port=3500)
|
||||
response = ursula.consider_agreement(agreement) # TODO: This needs to be a REST call.
|
||||
response = ursula.consider_contract(contract) # TODO: This needs to be a REST call.
|
||||
response.was_accepted = True
|
||||
return ursula, response
|
||||
|
||||
|
|
|
@ -420,6 +420,16 @@ class Ursula(Character):
|
|||
ursula.rest_port = rest_port
|
||||
return ursula
|
||||
|
||||
@classmethod
|
||||
def from_rest_url(cls, url):
|
||||
response = requests.get(url)
|
||||
if not response.status_code == 200:
|
||||
raise RuntimeError("Got a bad response: {}".format(response))
|
||||
signing_key_bytes, encrypting_key_bytes = BytestringSplitter(PublicKey)(response.content, return_remainder=True)
|
||||
stranger_ursula_from_public_keys = cls.from_public_keys(signing=signing_key_bytes,
|
||||
encrypting=encrypting_key_bytes)
|
||||
return stranger_ursula_from_public_keys
|
||||
|
||||
def attach_server(self, ksize=20, alpha=3, id=None, storage=None,
|
||||
*args, **kwargs):
|
||||
|
||||
|
@ -432,6 +442,8 @@ class Ursula(Character):
|
|||
routes = [
|
||||
Route('/kFrag/{hrac_as_hex}', 'POST', self.set_policy),
|
||||
Route('/kFrag/{hrac_as_hex}/reencrypt', 'POST', self.reencrypt_via_rest),
|
||||
Route('/public_keys', 'GET', self.get_signing_and_encrypting_public_keys),
|
||||
Route('/consider_contract', 'POST', self.consider_contract),
|
||||
]
|
||||
|
||||
self._rest_app = App(routes=routes)
|
||||
|
|
|
@ -17,7 +17,7 @@ from nkms.keystore.keypairs import PublicKey
|
|||
|
||||
class Contract(object):
|
||||
"""
|
||||
A Policy must be implemented by agreement with n Ursulas. This class tracks the status of that implementation.
|
||||
A Policy must be implemented by contract with n Ursulas. This class tracks the status of that implementation.
|
||||
"""
|
||||
|
||||
def __init__(self, alice, hrac, expiration, deposit=None, ursula=None, kfrag=UNKNOWN_KFRAG, alices_signature=None):
|
||||
|
@ -62,8 +62,8 @@ class ContractResponse(object):
|
|||
|
||||
class Policy(object):
|
||||
"""
|
||||
An individual agreement between Alice and Ursula. Together, all of the Policies by which
|
||||
Ursula nodes which enter into an agreement regarding the same series of kFrags constitute
|
||||
An individual contract between Alice and Ursula. Together, all of the Policies by which
|
||||
Ursula nodes which enter into an contract regarding the same series of kFrags constitute
|
||||
a PolicyGroup.
|
||||
|
||||
A Policy has a unique ID, which includes a fingerprint of Alice's public key so that
|
||||
|
|
Loading…
Reference in New Issue