Skip to content

Commit

Permalink
INDY-1856: Additional review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: ArtObr <[email protected]>
  • Loading branch information
ArtObr committed Dec 26, 2018
1 parent 294e222 commit 01da0b9
Show file tree
Hide file tree
Showing 19 changed files with 516 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from indy_common.state import domain

from indy_common.constants import ATTRIB
from indy_node.server.request_handlers.utils import validate_attrib_keys
from plenum.common.constants import DOMAIN_LEDGER_ID, RAW, ENC, HASH, TARGET_NYM
from plenum.common.exceptions import InvalidClientRequest, UnauthorizedClientRequest

Expand All @@ -19,7 +20,7 @@ def static_validation(self, request: Request):
self._validate_request_type(request)
identifier, req_id, operation = get_request_data(request)

if not self._validate_attrib_keys(operation):
if not validate_attrib_keys(operation):
raise InvalidClientRequest(identifier, req_id,
'{} should have one and only one of '
'{}, {}, {}'
Expand Down Expand Up @@ -66,8 +67,3 @@ def _update_state_with_single_txn(self, txn, is_committed=True) -> None:

def __has_nym(self, nym, isCommitted: bool = True):
return self.database_manager.idr_cache.hasNym(nym, isCommitted=isCommitted)

@staticmethod
def _validate_attrib_keys(operation):
data_keys = {RAW, ENC, HASH}.intersection(set(operation.keys()))
return len(data_keys) == 1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def dynamic_validation(self, request: Request):
"Mentioned seqNo ({}) isn't seqNo of the schema.".format(ref))
# only owner can update claim_def,
# because his identifier is the primary key of claim_def
self.write_req_validator.validate(request,
[AuthActionAdd(txn_type=CLAIM_DEF,
field='*',
value='*')])
self.write_request_validator.validate(request,
[AuthActionAdd(txn_type=CLAIM_DEF,
field='*',
value='*')])

def gen_txn_path(self, txn):
self._validate_txn_type(txn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ def _update_state_with_single_txn(self, txn, is_committed=True):

def _validate_new_nym(self, request, operation):
role = operation.get(ROLE)
self.write_req_validator.validate(request,
[AuthActionAdd(txn_type=NYM,
field=ROLE,
value=role)])
self.write_request_validator.validate(request,
[AuthActionAdd(txn_type=NYM,
field=ROLE,
value=role)])

def _validate_existing_nym(self, request, operation, nym_data):
origin = request.identifier
owner = self.idrCache.getOwnerFor(operation[TARGET_NYM], isCommitted=False)
owner = self.database_manager.idr_cache.getOwnerFor(operation[TARGET_NYM], isCommitted=False)
is_owner = origin == owner

updateKeys = [ROLE, VERKEY]
for key in updateKeys:
if key in operation:
newVal = operation[key]
oldVal = nym_data.get(key)
self.write_req_validator.validate(request,
[AuthActionEdit(txn_type=NYM,
field=key,
old_value=oldVal,
new_value=newVal,
is_owner=is_owner)])
self.write_request_validator.validate(request,
[AuthActionEdit(txn_type=NYM,
field=key,
old_value=oldVal,
new_value=newVal,
is_owner=is_owner)])
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict, Callable

from indy_common.state import domain

from indy_common.constants import REVOC_REG_ENTRY, REVOC_REG_DEF_ID, VALUE, ISSUANCE_TYPE
Expand All @@ -14,10 +16,10 @@ class RevocRegEntryHandler(WriteRequestHandler):

def __init__(self, database_manager: DatabaseManager,
get_revoc_reg_entry: GetRevocRegHandler,
revocation_strategy_map: dict):
get_revocation_strategy: Callable):
super().__init__(database_manager, REVOC_REG_ENTRY, DOMAIN_LEDGER_ID)
self.get_revoc_reg_entry = get_revoc_reg_entry
self.revocation_strategy_map = revocation_strategy_map
self.get_revocation_strategy = get_revocation_strategy

def static_validation(self, request: Request):
pass
Expand Down Expand Up @@ -50,6 +52,3 @@ def _update_state_with_single_txn(self, txn, isCommitted=False):
revoc_def[VALUE][ISSUANCE_TYPE])
writer = writer_cls(self.state)
writer.write(current_entry, txn)

def get_revocation_strategy(self, type):
return self.revocation_strategy_map.get(type, None)
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def dynamic_validation(self, request: Request):
schema_version = get_write_schema_version(request)
schema, _, _, _ = self.get_schema_handler.get_schema(
author=identifier,
schemaName=schema_name,
schemaVersion=schema_version,
schema_name=schema_name,
schema_version=schema_version,
with_proof=False)
if schema:
raise InvalidClientRequest(identifier, req_id,
'{} can have one and only one SCHEMA with '
'name {} and version {}'
.format(identifier, schema_name, schema_version))
self.write_req_validator.validate(request,
[AuthActionAdd(txn_type=SCHEMA,
field='*',
value='*')])
self.write_request_validator.validate(request,
[AuthActionAdd(txn_type=SCHEMA,
field='*',
value='*')])

def gen_txn_path(self, txn):
self._validate_txn_type(txn)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
from indy_common.state import domain

from indy_common.constants import ATTRIB, GET_ATTR

from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler
from indy_node.server.request_handlers.utils import validate_attrib_keys
from plenum.common.constants import RAW, ENC, HASH, TARGET_NYM, DOMAIN_LEDGER_ID
from plenum.common.exceptions import InvalidClientRequest
from plenum.common.request import Request
from plenum.common.txn_util import get_request_data
from plenum.server.database_manager import DatabaseManager
from stp_core.common.log import getlogger

logger = getlogger()


class GetAttributeHandler(ReadRequestHandler):
pass

def __init__(self, database_manager: DatabaseManager):
super().__init__(database_manager, GET_ATTR, DOMAIN_LEDGER_ID)

def get_result(self, request: Request):
self._validate_request_type(request)
identifier, req_id, operation = get_request_data(request)
if not validate_attrib_keys(operation):
raise InvalidClientRequest(identifier, req_id,
'{} should have one and only one of '
'{}, {}, {}'
.format(ATTRIB, RAW, ENC, HASH))
nym = operation[TARGET_NYM]
if RAW in operation:
attr_type = RAW
elif ENC in operation:
# If attribute is encrypted, it will be queried by its hash
attr_type = ENC
else:
attr_type = HASH
attr_key = operation[attr_type]
value, last_seq_no, last_update_time, proof = \
self.get_attr(did=nym, key=attr_key, attr_type=attr_type)
attr = None
if value is not None:
if HASH in operation:
attr = attr_key
else:
attr = value
return self.make_result(request=request,
data=attr,
last_seq_no=last_seq_no,
update_time=last_update_time,
proof=proof)

def get_attr(self,
did: str,
key: str,
attr_type,
is_committed=True) -> (str, int, int, list):
assert did is not None
assert key is not None
path = domain.make_state_path_for_attr(did, key, attr_type == HASH)
try:
hashed_val, last_seq_no, last_update_time, proof = \
self.lookup(path, is_committed, with_proof=True)
except KeyError:
return None, None, None, None
if not hashed_val or hashed_val == '':
# Its a HASH attribute
return hashed_val, last_seq_no, last_update_time, proof
else:
try:
value = self.database_manager.attribute_store.get(hashed_val)
except KeyError:
logger.error('Could not get value from attribute store for {}'
.format(hashed_val))
return None, None, None, None
return value, last_seq_no, last_update_time, proof
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
from indy_common.state import domain

from indy_common.constants import CLAIM_DEF_SIGNATURE_TYPE, GET_CLAIM_DEF
from indy_common.req_utils import get_read_claim_def_from, get_read_claim_def_signature_type, \
get_read_claim_def_schema_ref, get_read_claim_def_tag

from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.request import Request
from plenum.server.database_manager import DatabaseManager


class GetClaimDefHandler(ReadRequestHandler):
pass

def __init__(self, database_manager: DatabaseManager):
super().__init__(database_manager, GET_CLAIM_DEF, DOMAIN_LEDGER_ID)

def get_result(self, request: Request):
self._validate_request_type(request)
frm = get_read_claim_def_from(request)
signature_type = get_read_claim_def_signature_type(request)
schema_ref = get_read_claim_def_schema_ref(request)
tag = get_read_claim_def_tag(request)
keys, last_seq_no, last_update_time, proof = self.get_claim_def(
author=frm,
schema_seq_no=schema_ref,
signature_type=signature_type,
tag=tag
)
result = self.make_result(request=request,
data=keys,
last_seq_no=last_seq_no,
update_time=last_update_time,
proof=proof)
result[CLAIM_DEF_SIGNATURE_TYPE] = signature_type
return result

def get_claim_def(self,
author: str,
schema_seq_no: str,
signature_type,
tag,
is_committed=True) -> (str, int, int, list):
assert author is not None
assert schema_seq_no is not None
path = domain.make_state_path_for_claim_def(author, schema_seq_no, signature_type, tag)
try:
keys, seq_no, last_update_time, proof = self.lookup(path, is_committed, with_proof=True)
return keys, seq_no, last_update_time, proof
except KeyError:
return None, None, None, None
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
from indy_common.constants import GET_NYM

from common.serializers.serialization import domain_state_serializer
from indy_common.state import domain
from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler

from plenum.common.constants import TARGET_NYM, TXN_TIME, DOMAIN_LEDGER_ID
from plenum.common.request import Request
from plenum.common.types import f
from plenum.server.database_manager import DatabaseManager


class GetNymHandler(ReadRequestHandler):
pass

def __init__(self, database_manager: DatabaseManager):
super().__init__(database_manager, GET_NYM, DOMAIN_LEDGER_ID)

def get_result(self, request: Request):
self._validate_request_type(request)
nym = request.operation[TARGET_NYM]
path = domain.make_state_path_for_nym(nym)
nym_data, proof = self.get_value_from_state(path, with_proof=True)
if nym_data:
nym_data = domain_state_serializer.deserialize(nym_data)
nym_data[TARGET_NYM] = nym
data = domain_state_serializer.serialize(nym_data)
seq_no = nym_data[f.SEQ_NO.nm]
update_time = nym_data[TXN_TIME]
else:
data = None
seq_no = None
update_time = None

# TODO: add update time here!
result = self.make_result(request=request,
data=data,
last_seq_no=seq_no,
update_time=update_time,
proof=proof)

result.update(request.operation)
return result
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
from indy_common.constants import ID, GET_REVOC_REG_DEF

from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.request import Request
from plenum.server.database_manager import DatabaseManager


class GetRevocRegDefHandler(ReadRequestHandler):
pass

def __init__(self, database_manager: DatabaseManager):
super().__init__(database_manager, GET_REVOC_REG_DEF, DOMAIN_LEDGER_ID)

def get_result(self, request: Request):
self._validate_request_type(request)
state_path = request.operation.get(ID, None)
assert state_path
try:
keys, last_seq_no, last_update_time, proof = self.lookup(state_path, isCommitted=True, with_proof=True)
except KeyError:
keys, last_seq_no, last_update_time, proof = None, None, None, None
result = self.make_result(request=request,
data=keys,
last_seq_no=last_seq_no,
update_time=last_update_time,
proof=proof)
return result
Loading

0 comments on commit 01da0b9

Please sign in to comment.