本文整理汇总了Python中indy_common.auth.Authoriser类的典型用法代码示例。如果您正苦于以下问题:Python Authoriser类的具体用法?Python Authoriser怎么用?Python Authoriser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Authoriser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
def validate(self, req: Request):
status = None
operation = req.operation
typ = operation.get(TXN_TYPE)
if typ not in self.operation_types:
return
origin = req.identifier
try:
origin_role = self.idrCache.getRole(origin, isCommitted=False)
except BaseException:
raise UnauthorizedClientRequest(
req.identifier,
req.reqId,
"Nym {} not added to the ledger yet".format(origin))
r = False
if typ == POOL_RESTART:
action = operation.get(ACTION)
r, msg = Authoriser.authorised(typ, origin_role,
field=ACTION,
oldVal=status,
newVal=action)
elif typ == VALIDATOR_INFO:
r, msg = Authoriser.authorised(typ, origin_role)
if not r:
raise UnauthorizedClientRequest(
req.identifier, req.reqId,
"{} cannot do action with type = {}".format(
Roles.nameFromValue(origin_role),
typ))
示例2: __init__
def __init__(self,
identifier: Identifier,
trust_anchor: Identifier=None,
verkey=None,
role=None,
last_synced=None,
seq_no=None):
"""
:param identifier:
:param trust_anchor:
:param verkey:
:param role: If role is explicitly passed as `null` then in the request
to ledger, `role` key would be sent as None which would stop the
Identity's ability to do any privileged actions. If role is not passed,
`role` key will not be included in the request to the ledger
:param last_synced:
:param seq_no:
"""
self.identity = DidIdentity(identifier, verkey=verkey)
self.trustAnchor = trust_anchor
# if role and role not in (TRUST_ANCHOR, STEWARD):
if not Authoriser.isValidRole(self.correctRole(role)):
raise AttributeError("Invalid role {}".format(role))
self._role = role
# timestamp for when the ledger was last checked for key replacement or
# revocation
self.last_synced = last_synced
# sequence number of the latest key management transaction for this
# identifier
self.seqNo = seq_no
示例3: _validateExistingNym
def _validateExistingNym(self, req: Request, op, originRole, nymData):
unauthorized = False
reason = None
origin = req.identifier
owner = self.idrCache.getOwnerFor(op[TARGET_NYM], isCommitted=False)
isOwner = origin == owner
if not originRole == TRUSTEE and not isOwner:
reason = '{} is neither Trustee nor owner of {}' \
.format(origin, op[TARGET_NYM])
unauthorized = True
if not unauthorized:
updateKeys = [ROLE, VERKEY]
for key in updateKeys:
if key in op:
newVal = op[key]
oldVal = nymData.get(key)
if oldVal != newVal:
r, msg = Authoriser.authorised(NYM, key, originRole,
oldVal=oldVal, newVal=newVal,
isActorOwnerOfSubject=isOwner)
if not r:
unauthorized = True
reason = "{} cannot update {}".\
format(Roles.nameFromValue(originRole), key)
break
if unauthorized:
raise UnauthorizedClientRequest(
req.identifier, req.reqId, reason)
示例4: test_pool_upgrade_wrong_new_name
def test_pool_upgrade_wrong_new_name(role, is_owner):
assert not Authoriser.authorised(typ=POOL_UPGRADE,
field=ACTION,
actorRole=role,
oldVal="start",
newVal="aaa",
isActorOwnerOfSubject=is_owner)[0]
示例5: _validate_schema
def _validate_schema(self, req: Request):
# we can not add a Schema with already existent NAME and VERSION
# sine a Schema needs to be identified by seqNo
identifier = req.identifier
operation = req.operation
schema_name = operation[DATA][NAME]
schema_version = operation[DATA][VERSION]
schema, _, _, _ = self.getSchema(
author=identifier,
schemaName=schema_name,
schemaVersion=schema_version,
with_proof=False
)
if schema:
raise InvalidClientRequest(identifier, req.reqId,
'{} can have one and only one SCHEMA with '
'name {} and version {}'
.format(identifier, schema_name, schema_version))
try:
origin_role = self.idrCache.getRole(
req.identifier, isCommitted=False) or None
except BaseException:
raise UnknownIdentifier(
req.identifier,
req.reqId)
r, msg = Authoriser.authorised(typ=SCHEMA,
actorRole=origin_role)
if not r:
raise UnauthorizedClientRequest(
req.identifier,
req.reqId,
"{} cannot add schema".format(
Roles.nameFromValue(origin_role))
)
示例6: test_node_wrong_new_service_name
def test_node_wrong_new_service_name(role, is_owner):
assert not Authoriser.authorised(typ=NODE,
actorRole=role,
field=SERVICES,
oldVal="[]",
newVal="aaa",
isActorOwnerOfSubject=is_owner)[0]
示例7: test_remove_steward
def test_remove_steward(role, is_owner):
authorized = (role == TRUSTEE)
assert authorized == Authoriser.authorised(typ=NYM,
actorRole=role,
field=ROLE,
oldVal=STEWARD,
newVal=None,
isActorOwnerOfSubject=is_owner)[0]
示例8: test_node_change_bls_keys
def test_node_change_bls_keys(role, is_owner, old_values):
authorized = (role == STEWARD and is_owner)
assert authorized == Authoriser.authorised(typ=NODE,
actorRole=role,
field=BLS_KEY,
oldVal=old_values,
newVal="value2",
isActorOwnerOfSubject=is_owner)[0]
示例9: test_pool_config_change
def test_pool_config_change(role, is_owner, old_values):
authorized = role in (TRUSTEE, TGB)
assert authorized == Authoriser.authorised(typ=POOL_CONFIG,
actorRole=role,
field=ACTION,
oldVal=old_values,
newVal="value2",
isActorOwnerOfSubject=is_owner)[0]
示例10: test_node_enable
def test_node_enable(role, is_owner):
authorized = (role == STEWARD and is_owner)
assert authorized == Authoriser.authorised(typ=NODE,
actorRole=role,
field=SERVICES,
oldVal=None,
newVal="[VALIDATOR]",
isActorOwnerOfSubject=is_owner)[0]
示例11: test_node_change_alias
def test_node_change_alias(role, is_owner, old_values):
authorized = False # alias can not be changed
assert authorized == Authoriser.authorised(typ=NODE,
actorRole=role,
field=ALIAS,
oldVal=old_values,
newVal="value2",
isActorOwnerOfSubject=is_owner)[0]
示例12: test_remove_trust_anchor
def test_remove_trust_anchor(role, is_owner):
authorized = (role == TRUSTEE)
assert authorized == Authoriser.authorised(typ=NYM,
actorRole=role,
field=ROLE,
oldVal=TRUST_ANCHOR,
newVal=None,
isActorOwnerOfSubject=is_owner)[0]
示例13: test_change_verkey
def test_change_verkey(role, is_owner, old_values):
authorized = is_owner
assert authorized == Authoriser.authorised(typ=NYM,
actorRole=role,
field=VERKEY,
oldVal=old_values,
newVal="value2",
isActorOwnerOfSubject=is_owner)[0]
示例14: test_pool_upgrade_start
def test_pool_upgrade_start(role, is_owner):
authorized = role in (TRUSTEE, TGB)
assert authorized == Authoriser.authorised(typ=POOL_UPGRADE,
field=ACTION,
actorRole=role,
oldVal=None,
newVal="start",
isActorOwnerOfSubject=is_owner)[0]
示例15: test_make_trustee
def test_make_trustee(role, is_owner):
authorized = (role == TRUSTEE)
assert authorized == Authoriser.authorised(typ=NYM,
actorRole=role,
field=ROLE,
oldVal=None,
newVal=TRUSTEE,
isActorOwnerOfSubject=is_owner)[0]