Configuration fields for policy credential and vard storage feature switches.

pull/2115/head
Kieran R. Prasch 2020-06-24 00:52:37 -07:00
parent c51c4a7f09
commit 612d380bc8
No known key found for this signature in database
GPG Key ID: FDC3146ED25617D8
2 changed files with 52 additions and 10 deletions

View File

@ -152,11 +152,22 @@ class AliceConfiguration(CharacterConfiguration):
DEFAULT_M = 2
DEFAULT_N = 3
DEFAULT_STORE_POLICIES = True
DEFAULT_STORE_CARDS = True
_CONFIG_FIELDS = (
*CharacterConfiguration._CONFIG_FIELDS,
'store_policies',
'store_cards'
)
def __init__(self,
m: int = None,
n: int = None,
rate: int = None,
duration_periods: int = None,
store_policies: bool = DEFAULT_STORE_POLICIES,
store_cards: bool = DEFAULT_STORE_CARDS,
*args, **kwargs):
super().__init__(*args, **kwargs)
@ -167,8 +178,16 @@ class AliceConfiguration(CharacterConfiguration):
self.rate = rate
self.duration_periods = duration_periods
self.store_policies = store_policies
self.store_cards = store_cards
def static_payload(self) -> dict:
payload = dict(m=self.m, n=self.n)
payload = dict(
m=self.m,
n=self.n,
store_policy_credentials=self.store_policies,
store_character_cards=self.store_cards
)
if not self.federated_only:
if self.rate:
payload['rate'] = self.rate
@ -188,8 +207,23 @@ class BobConfiguration(CharacterConfiguration):
CHARACTER_CLASS = Bob
NAME = CHARACTER_CLASS.__name__.lower()
DEFAULT_CONTROLLER_PORT = 7151
DEFFAULT_STORE_POLICIES = True
DEFAULT_STORE_CARDS = True
_CONFIG_FIELDS = (
*CharacterConfiguration._CONFIG_FIELDS,
'store_policies',
'store_cards'
)
def __init__(self,
store_policies: bool = DEFFAULT_STORE_POLICIES,
store_cards: bool = DEFAULT_STORE_CARDS,
*args, **kwargs):
super().__init__(*args, **kwargs)
self.store_policies = store_policies
self.store_cards = store_cards
def write_keyring(self, password: str, **generation_kwargs) -> NucypherKeyring:
return super().write_keyring(password=password,
@ -197,6 +231,13 @@ class BobConfiguration(CharacterConfiguration):
rest=False,
**generation_kwargs)
def static_payload(self) -> dict:
payload = dict(
store_policies=self.store_policies,
store_cards=self.store_cards
)
return {**super().static_payload(), **payload}
class FelixConfiguration(CharacterConfiguration):
from nucypher.characters.chaotic import Felix

View File

@ -69,6 +69,14 @@ class CharacterConfiguration(BaseConfiguration):
# Gas
DEFAULT_GAS_STRATEGY = 'fast'
_CONFIG_FIELDS = ('config_root',
'poa',
'light',
'provider_uri',
'registry_filepath',
'gas_strategy',
'signer_uri')
def __init__(self,
# Base
@ -334,14 +342,7 @@ class CharacterConfiguration(BaseConfiguration):
Warning: This method allows mutation and may result in an inconsistent configuration.
"""
merged_parameters = {**self.static_payload(), **self.dynamic_payload, **overrides}
non_init_params = ('config_root',
'poa',
'light',
'provider_uri',
'registry_filepath',
'gas_strategy',
'signer_uri')
character_init_params = filter(lambda t: t[0] not in non_init_params, merged_parameters.items())
character_init_params = filter(lambda t: t[0] not in self._CONFIG_FIELDS, merged_parameters.items())
return dict(character_init_params)
def produce(self, **overrides) -> CHARACTER_CLASS: