class ClientDiscloOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(DISCLO)), (DATA, NonEmptyStringField()), (NONCE, NonEmptyStringField()), (TARGET_NYM, IdentifierField(optional=True)), )
class ClientClaimDefSubmitOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(CLAIM_DEF)), (REF, TxnSeqNoField()), (DATA, NonEmptyStringField()), (SIGNATURE_TYPE, NonEmptyStringField()), )
class ClientClaimDefGetOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(GET_CLAIM_DEF)), (REF, TxnSeqNoField()), (ORIGIN, NonEmptyStringField()), (SIGNATURE_TYPE, NonEmptyStringField()), )
class SchemaField(MessageValidator): schema = ( (NAME, NonEmptyStringField()), (VERSION, VersionField(components_number=( 2, 3, ))), (ATTR_NAMES, IterableField(NonEmptyStringField())), )
class GetSchemaField(MessageValidator): schema = ( (NAME, NonEmptyStringField()), (VERSION, VersionField(components_number=( 2, 3, ))), (ORIGIN, NonEmptyStringField(optional=True)), )
class ClientAttribOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(ATTRIB)), (TARGET_NYM, IdentifierField(optional=True)), (RAW, JsonField(optional=True)), (ENC, NonEmptyStringField(optional=True)), (HASH, NonEmptyStringField(optional=True)), ) def _validate_message(self, msg): self.__validate_field_set(msg) if RAW in msg: self.__validate_raw_field(msg[RAW]) def __validate_field_set(self, msg): fields_n = sum(1 for f in (RAW, ENC, HASH) if f in msg) if fields_n == 0: self._raise_missed_fields(RAW, ENC, HASH) if fields_n > 1: self._raise_invalid_message( "only one field from {}, {}, {} is expected".format( RAW, ENC, HASH)) def __validate_raw_field(self, raw_field): raw = self.__decode_raw_field(raw_field) if not isinstance(raw, dict): self._raise_invalid_fields(RAW, type(raw), 'should be a dict') if len(raw) != 1: self._raise_invalid_fields(RAW, raw, 'should contain one attribute') if ENDPOINT in raw: self.__validate_endpoint_ha_field(raw[ENDPOINT]) def __decode_raw_field(self, raw_field): return json.loads(raw_field) def __validate_endpoint_ha_field(self, endpoint): if endpoint is None: return # remove the attribute, valid case HA_NAME = 'ha' ha = endpoint.get(HA_NAME) if ha is None: return # remove ha attribute, valid case if ':' not in ha: self._raise_invalid_fields( ENDPOINT, endpoint, "invalid endpoint format " "ip_address:port") ip, port = ha.split(':') if not is_network_ip_address_valid(ip): self._raise_invalid_fields('ha', ha, 'invalid endpoint address') if not is_network_port_valid(port): self._raise_invalid_fields('ha', ha, 'invalid endpoint port')
class ClientPoolUpgradeOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(POOL_UPGRADE)), (ACTION, NonEmptyStringField()), # TODO check actual value set (VERSION, VersionField(components_number=( 2, 3, ))), # TODO replace actual checks (idr, datetime) (SCHEDULE, MapField(NonEmptyStringField(), NonEmptyStringField(), optional=True)), (SHA256, Sha256HexField()), (TIMEOUT, NonNegativeNumberField(optional=True)), (JUSTIFICATION, LimitedLengthStringField(max_length=JUSTIFICATION_MAX_SIZE, optional=True, nullable=True)), (NAME, NonEmptyStringField(optional=True)), (FORCE, BooleanField(optional=True)), )
class ClientGetAttribOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(GET_ATTR)), (TARGET_NYM, IdentifierField(optional=True)), (RAW, NonEmptyStringField()), )
class ClientSchemaOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(SCHEMA)), (DATA, NonEmptyStringField()), )
class TestMsg(MessageBase): typename = "TESTMSG" schema = ( ("subject", NonEmptyStringField()), ("content", NonEmptyStringField()), )