Ejemplo n.º 1
0
class ClientPoolUpgradeOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(POOL_UPGRADE)),
        (ACTION, ChooseField(values=(
            START,
            CANCEL,
        ))),
        (VERSION,
         VersionField(components_number=(
             2,
             3,
         ),
                      max_length=VERSION_FIELD_LIMIT)),
        # TODO replace actual checks (idr, datetime)
        (SCHEDULE,
         MapField(IdentifierField(), NonEmptyStringField(), optional=True)),
        (SHA256, Sha256HexField()),
        (TIMEOUT, NonNegativeNumberField(optional=True)),
        (JUSTIFICATION,
         LimitedLengthStringField(max_length=JUSTIFICATION_MAX_SIZE,
                                  optional=True,
                                  nullable=True)),
        (NAME, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)),
        (FORCE, BooleanField(optional=True)),
        (REINSTALL, BooleanField(optional=True)),
    )
Ejemplo n.º 2
0
class ClientPoolRestartOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(POOL_RESTART)),
        (ACTION, ChooseField(values=(START, CANCEL,))),
        (DATETIME, DatetimeStringField(exceptional_values=["0", ""],
                                       optional=True)),
    )
Ejemplo n.º 3
0
class ObservedData(MessageBase):
    """
    Purpose: propagate data from Validators to Observers
    """
    # TODO: support other types
    # TODO: support validation of Msg according to the type
    allowed_types = {BATCH}
    typename = OBSERVED_DATA
    schema = (
        (f.MSG_TYPE.nm, ChooseField(values=allowed_types)),
        (f.MSG.nm, AnyValueField())
    )

    def _validate_message(self, dct):
        msg = dct[f.MSG.nm]
        # TODO: support other types
        expected_type_cls = BatchCommitted
        if isinstance(msg, expected_type_cls):
            return None
        if isinstance(msg, dict):
            expected_type_cls(**msg)
            return None
        self._raise_invalid_fields(
            f.MSG.nm, msg,
            "The message type must be {} ".format(expected_type_cls.typename))
Ejemplo n.º 4
0
class ConstraintEntityField(MessageValidator):
    schema = (
        (CONSTRAINT_ID, ChooseField(values=ConstraintsEnum.values())),
        (ROLE, RoleField()),
        (SIG_COUNT, NonNegativeNumberField()),
        (NEED_TO_BE_OWNER, BooleanField(optional=True)),
        (METADATA, AnyMapField(optional=True))
    )
Ejemplo n.º 5
0
class MessageRep(MessageBase):
    """
    Purpose: respond to a node for any requested message
    """
    # TODO: support a setter for `msg` to create an instance of a type
    # according to `msg_type`
    typename = MESSAGE_RESPONSE
    schema = ((f.MSG_TYPE.nm, ChooseField(values=MessageReq.allowed_types)),
              (f.PARAMS.nm, AnyMapField()), (f.MSG.nm, AnyField()))
Ejemplo n.º 6
0
class ClientGetAuthRuleOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(GET_AUTH_RULE)),
        (AUTH_ACTION, ChooseField(values=(ADD_PREFIX, EDIT_PREFIX), optional=True)),
        (AUTH_TYPE, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT, optional=True)),
        (FIELD, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT, optional=True)),
        (OLD_VALUE, AuthRuleValueField(optional=True)),
        (NEW_VALUE, AuthRuleValueField(optional=True))
    )
Ejemplo n.º 7
0
class RevocDefValueField(MessageValidator):
    schema = (
        (ISSUANCE_TYPE, ChooseField(values=(ISSUANCE_BY_DEFAULT,
                                            ISSUANCE_ON_DEMAND))),
        (MAX_CRED_NUM, IntegerField()),
        (PUBLIC_KEYS, AnyMapField()),
        (TAILS_HASH, NonEmptyStringField()),
        (TAILS_LOCATION, NonEmptyStringField()),
    )
Ejemplo n.º 8
0
class ClientPoolRestartOperation(MessageValidator):
    schema = (
        (TXN_TYPE, ConstantField(POOL_RESTART)),
        (ACTION, ChooseField(values=(
            START,
            CANCEL,
        ))),
        (DATETIME, NonEmptyStringField(optional=True)),
    )
Ejemplo n.º 9
0
class AuthRuleField(MessageValidator):
    schema = (
        (CONSTRAINT, ConstraintField(ConstraintEntityField(),
                                     ConstraintListField())),
        (AUTH_ACTION, ChooseField(values=(ADD_PREFIX, EDIT_PREFIX))),
        (AUTH_TYPE, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)),
        (FIELD, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)),
        (OLD_VALUE, AuthRuleValueField(optional=True)),
        (NEW_VALUE, AuthRuleValueField())
    )
Ejemplo n.º 10
0
class MessageReq(MessageBase):
    """
    Purpose: ask node for any message
    """
    allowed_types = {
        LEDGER_STATUS, CONSISTENCY_PROOF, PREPREPARE, PROPAGATE, PREPARE
    }
    typename = MESSAGE_REQUEST
    schema = ((f.MSG_TYPE.nm, ChooseField(values=allowed_types)),
              (f.PARAMS.nm, AnyMapField()))
Ejemplo n.º 11
0
class ConstraintListField(MessageValidator):
    schema = ((CONSTRAINT_ID, ChooseField(values=ConstraintsEnum.values())),
              (AUTH_CONSTRAINTS, IterableField(AnyField())))

    def _validate_message(self, val):
        constraints = val.get(AUTH_CONSTRAINTS)
        if not constraints:
            self._raise_invalid_message("Fields {} should not be an empty "
                                        "list.".format(AUTH_CONSTRAINTS))
        for constraint in constraints:
            error_msg = ConstraintField(ConstraintEntityField(),
                                        self).validate(constraint)
            if error_msg:
                self._raise_invalid_message(error_msg)
Ejemplo n.º 12
0
class ClientAuthRuleOperation(MessageValidator):
    schema = ((TXN_TYPE, ConstantField(AUTH_RULE)),
              (CONSTRAINT,
               ConstraintField(ConstraintEntityField(),
                               ConstraintListField())),
              (AUTH_ACTION, ChooseField(values=(ADD_PREFIX, EDIT_PREFIX))),
              (AUTH_TYPE,
               LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)),
              (FIELD, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)),
              (OLD_VALUE,
               LimitedLengthStringField(max_length=NAME_FIELD_LIMIT,
                                        optional=True)),
              (NEW_VALUE,
               LimitedLengthStringField(max_length=NAME_FIELD_LIMIT,
                                        can_be_empty=True)))
Ejemplo n.º 13
0
class ClientNodeOperationData(MessageValidator):
    schema = (
        (NODE_IP, NetworkIpAddressField(optional=True)),
        (NODE_PORT, NetworkPortField(optional=True)),
        (CLIENT_IP, NetworkIpAddressField(optional=True)),
        (CLIENT_PORT, NetworkPortField(optional=True)),
        (ALIAS, LimitedLengthStringField(max_length=ALIAS_FIELD_LIMIT)),
        (SERVICES, IterableField(ChooseField(values=(VALIDATOR,)), optional=True)),
        (BLS_KEY, Base58Field(byte_lengths=(128,), optional=True)),
    )

    def _validate_message(self, dct):
        # TODO: make ha fields truly optional (needs changes in stackHaChanged)
        required_ha_fields = {NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT}
        ha_fields = {f for f in required_ha_fields if f in dct}
        if ha_fields and len(ha_fields) != len(required_ha_fields):
            self._raise_missed_fields(*list(required_ha_fields - ha_fields))