コード例 #1
0
ファイル: types.py プロジェクト: trentlarson/indy-node
class ClientDiscloOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(DISCLO)),
        (DATA, NonEmptyStringField()),
        (NONCE, NonEmptyStringField()),
        (TARGET_NYM, IdentifierField(optional=True)),
    )
コード例 #2
0
class ClientClaimDefSubmitOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(CLAIM_DEF)),
        (REF, TxnSeqNoField()),
        (DATA, NonEmptyStringField()),
        (SIGNATURE_TYPE, NonEmptyStringField()),
    )
コード例 #3
0
ファイル: types.py プロジェクト: trentlarson/indy-node
class ClientClaimDefGetOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(GET_CLAIM_DEF)),
        (REF, TxnSeqNoField()),
        (ORIGIN, NonEmptyStringField()),
        (SIGNATURE_TYPE, NonEmptyStringField()),
    )
コード例 #4
0
ファイル: types.py プロジェクト: trentlarson/indy-node
class SchemaField(MessageValidator):
    schema = (
        (NAME, NonEmptyStringField()),
        (VERSION, VersionField(components_number=(
            2,
            3,
        ))),
        (ATTR_NAMES, IterableField(NonEmptyStringField())),
    )
コード例 #5
0
ファイル: types.py プロジェクト: trentlarson/indy-node
class GetSchemaField(MessageValidator):
    schema = (
        (NAME, NonEmptyStringField()),
        (VERSION, VersionField(components_number=(
            2,
            3,
        ))),
        (ORIGIN, NonEmptyStringField(optional=True)),
    )
コード例 #6
0
ファイル: types.py プロジェクト: trentlarson/indy-node
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')
コード例 #7
0
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)),
    )
コード例 #8
0
ファイル: types.py プロジェクト: trentlarson/indy-node
class ClientGetAttribOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(GET_ATTR)),
        (TARGET_NYM, IdentifierField(optional=True)),
        (RAW, NonEmptyStringField()),
    )
コード例 #9
0
class ClientSchemaOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(SCHEMA)),
        (DATA, NonEmptyStringField()),
    )
コード例 #10
0
ファイル: msgs.py プロジェクト: aigoncharov/plenum
class TestMsg(MessageBase):
    typename = "TESTMSG"
    schema = (
        ("subject", NonEmptyStringField()),
        ("content", NonEmptyStringField()),
    )