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 schema_name = get_write_schema_name(req) schema_version = get_write_schema_version(req) 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)))
def make_schema_exist(schema_request, schema_handler): identifier, req_id, operation = get_request_data(schema_request) schema_name = get_write_schema_name(schema_request) schema_version = get_write_schema_version(schema_request) path = SchemaHandler.make_state_path_for_schema(identifier, schema_name, schema_version) schema_handler.state.set(path, encode_state_value("value", "seqNo", "txnTime"))
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 schema_name = get_write_schema_name(req) schema_version = get_write_schema_version(req) 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)) self.write_req_validator.validate( req, [AuthActionAdd(txn_type=SCHEMA, field='*', value='*')])
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 schema_name = get_write_schema_name(req) schema_version = get_write_schema_version(req) schema, _, _, _ = self.getSchema(author=identifier, schemaName=schema_name, schemaVersion=schema_version, with_proof=False) if schema: self.write_req_validator.validate(req, [ AuthActionEdit( txn_type=SCHEMA, field='*', old_value='*', new_value='*') ]) else: self.write_req_validator.validate( req, [AuthActionAdd(txn_type=SCHEMA, field='*', value='*')])
def dynamic_validation(self, request: Request): # we can not add a Schema with already existent NAME and VERSION # sine a Schema needs to be identified by seqNo self._validate_request_type(request) identifier, req_id, operation = get_request_data(request) schema_name = get_write_schema_name(request) schema_version = get_write_schema_version(request) schema, _, _, _ = self.get_schema_handler.get_schema( author=identifier, 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_request_validator.validate( request, [AuthActionAdd(txn_type=SCHEMA, field='*', value='*')])
def dynamic_validation(self, request: Request): # we can not add a Schema with already existent NAME and VERSION # sine a Schema needs to be identified by seqNo self._validate_request_type(request) identifier, req_id, operation = get_request_data(request) schema_name = get_write_schema_name(request) schema_version = get_write_schema_version(request) path = SchemaHandler.make_state_path_for_schema( identifier, schema_name, schema_version) schema, _, _ = self.get_from_state(path) if schema: self.write_req_validator.validate(request, [ AuthActionEdit( txn_type=SCHEMA, field='*', old_value='*', new_value='*') ]) else: self.write_req_validator.validate( request, [AuthActionAdd(txn_type=SCHEMA, field='*', value='*')])
def test_get_write_schema_name(write_schema_request): assert 'Degree' == get_write_schema_name(write_schema_request)