Beispiel #1
0
class RegionConfiguration(Configuration, metaclass=RegionConfigurationMeta):
    """Local configuration for the MAAS region."""

    maas_url = ConfigurationOption(
        "maas_url", "The HTTP URL for the MAAS region.", ExtendedURL(
            require_tld=False, if_missing="http://localhost:5240/MAAS"))

    # Database options.
    database_host = ConfigurationOption(
        "database_host", "The address of the PostgreSQL database.",
        UnicodeString(if_missing="localhost", accept_python=False))
    database_port = ConfigurationOption(
        "database_port", "The port of the PostgreSQL database.",
        Int(if_missing=5432, accept_python=False, min=1, max=65535))
    database_name = ConfigurationOption(
        "database_name", "The name of the PostgreSQL database.",
        UnicodeString(if_missing="maasdb", accept_python=False))
    database_user = ConfigurationOption(
        "database_user", "The user to connect to PostgreSQL as.",
        UnicodeString(if_missing="maas", accept_python=False))
    database_pass = ConfigurationOption(
        "database_pass", "The password for the PostgreSQL user.",
        UnicodeString(if_missing="", accept_python=False))
    database_conn_max_age = ConfigurationOption(
        "database_conn_max_age",
        "The lifetime of a database connection, in seconds.",
        Int(if_missing=(5 * 60), accept_python=False, min=0))
class WaittimesSchema(ReportSchema):
    """Wait Times Report Schema."""
    int_size = IntervalValidator()
    pool = PoolValidator()
    num = NumberTypeValidator()
    mpb = Int(min=0, if_missing=15, if_empty=15)  # minutes per block
    maxb = Int(min=0, if_missing=120, if_empty=120)  # max block

    chained_validators = ReportSchema.chained_validators + [IntSizeInit()]
Beispiel #3
0
class ClassSchema(Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    code = String(not_empty=True)
    descrip = String(not_empty=True)
    eventtrophy = Bool()
    champtrophy = Bool()
    carindexed = Bool()
    classindex = String()
    classmultiplier = Number(not_empty=True)
    usecarflag = Bool()
    numorder = Int()
    countedruns = Int(if_empty=0)
    caridxrestrict = String()
Beispiel #4
0
class UnrestrictedUser(Schema):
    """UnrestrictedUser validator ensures that unrestricted users are integers
    representing user IDs.
    
    """

    unrestrictedUser = Int()
Beispiel #5
0
class RegionConfiguration(Configuration, metaclass=RegionConfigurationMeta):
    """Local configuration for the MAAS region."""

    maas_url = ConfigurationOption(
        "maas_url", "The HTTP URL for the MAAS region.", ExtendedURL(
            require_tld=False, if_missing="http://localhost:5240/MAAS"))

    # Database options.
    database_host = ConfigurationOption(
        "database_host", "The address of the PostgreSQL database.",
        UnicodeString(if_missing="localhost", accept_python=False))
    database_port = ConfigurationOption(
        "database_port", "The port of the PostgreSQL database.",
        Int(if_missing=5432, accept_python=False, min=1, max=65535))
    database_name = ConfigurationOption(
        "database_name", "The name of the PostgreSQL database.",
        UnicodeString(if_missing="maasdb", accept_python=False))
    database_user = ConfigurationOption(
        "database_user", "The user to connect to PostgreSQL as.",
        UnicodeString(if_missing="maas", accept_python=False))
    database_pass = ConfigurationOption(
        "database_pass", "The password for the PostgreSQL user.",
        UnicodeString(if_missing="", accept_python=False))
    database_conn_max_age = ConfigurationOption(
        "database_conn_max_age",
        "The lifetime of a database connection, in seconds.",
        Int(if_missing=(5 * 60), accept_python=False, min=0))

    # Worker options.
    num_workers = ConfigurationOption(
        "num_workers", "The number of regiond worker process to run.",
        Int(if_missing=4, accept_python=False, min=1))

    # Debug options.
    debug = ConfigurationOption(
        "debug", "Enable debug mode for detailed error and log reporting.",
        StringBool(if_missing=False))
    debug_queries = ConfigurationOption(
        "debug_queries",
        "Enable query debugging. Reports number of queries and time for all "
        "actions performed. Requires debug to also be True. mode for detailed "
        "error and log reporting.",
        StringBool(if_missing=False))
    debug_http = ConfigurationOption(
        "debug_http",
        "Enable HTTP debugging. Logs all HTTP requests and HTTP responses.",
        StringBool(if_missing=False))
Beispiel #6
0
class SettingsSchema(Schema):
    allow_extra_fields = True
    filter_extra_fields = False
    seriesname = String(not_empty=True)
    largestcarnumber = Int(min=99)
    minevents = Int(if_empty=0)
    useevents = Int(not_empty=True)
    sponsorlink = String()
    pospointlist = String()
    champsorting = String()
    superuniquenumbers = Bool()
    indexafterpenalties = Bool()
    locked = Bool()
    usepospoints = Bool()
    sponsorimage = Validator()
    seriesimage = Validator()
    cardimage = Validator()
Beispiel #7
0
class ConfigFrontend(Schema):
    """Configuration validator for the front-end service."""

    if_key_missing = None

    port = Int(min=1, max=65535, if_missing=8001)
    prefix = String(if_missing=None)
    interface = String(if_missing=None)
Beispiel #8
0
class ConfigTFTP(Schema):
    """Configuration validator for the TFTP service."""

    if_key_missing = None

    root = String(if_missing="/var/lib/maas/tftp")
    port = Int(min=1, max=65535, if_missing=69)
    generator = String(if_missing=b"http://localhost/MAAS/api/1.0/pxeconfig/")
Beispiel #9
0
class LockssomaticSpaceSchema(TypeOfSpaceSchema):
    collection_iri = UnicodeString(max=256)
    content_provider_id = UnicodeString(max=32)
    checksum_type = UnicodeString(max=64)
    keep_local = Bool()
    au_size = Int()
    sd_iri = URL(max=256)
    external_domain = URL()
Beispiel #10
0
class UpdateHomePageForm(Schema):
    """NewPageForm is a Schema for validating the 
    data entered at the Edit Home Page page."""
    allow_extra_fields = True
    filter_extra_fields = True
    name = UnicodeString()
    heading = UnicodeString()
    content = UnicodeString()
    ID = Int()
Beispiel #11
0
class LocationSchema(Schema):
    description = UnicodeString(max=256)
    purpose = OneOf(_flatten(models.Location.PURPOSE_CHOICES))
    relative_path = UnicodeString()
    quota = Int(min=0)
    enabled = Bool()
    space = ResourceURI(model_cls=models.Space)
    pipeline = ForEach(ResourceURI(model_cls=models.Pipeline))
    replicators = ForEach(ResourceURI(model_cls=models.Location))
Beispiel #12
0
class AddProyecto(AddRecordForm):
    """ Define el formato del formulario para crear un nuevo proyecto"""
    __model__ = Proyecto
    __omit_fields__ = ['id', 'fases', 'fichas', 'estado', 'fecha_inicio', \
                      'fecha_fin']
    nombre = All(NotEmpty(), ValidarExpresion(r'^[A-Za-z][A-Za-z0-9 ]*$'), \
            Unico())
    nro_fases = All(NotEmpty(), Int(min=0))
    __dropdown_field_names__ = {'lider': 'nombre_usuario'}
Beispiel #13
0
class ConfigBroker(Schema):
    """Configuration validator for message broker options."""

    if_key_missing = None

    host = String(if_missing=b"localhost")
    port = Int(min=1, max=65535, if_missing=5672)
    username = String(if_missing=b"guest")
    password = String(if_missing=b"guest")
    vhost = String(if_missing="/")
class SlaveDetailsSchema(ReportSchema):
    """Slave Details Report Schema."""
    int_size = IntervalValidator()
    last_int_size = IntervalValidator()
    slave_id = Int(min=0)
    type = OneOf(list=['busy', 'all'], if_empty='all', if_missing='all')

    chained_validators = ReportSchema.chained_validators + [
        IntSizeInit(divisions=24),
        IntSizeInit(divisions=24, int_size_param='last_int_size')
    ]
Beispiel #15
0
class UserPasswordForm(UserForm):
    """ Form validation schema for user password change."""
    user_id = Int()  # used in forms hidden field
    username = None
    first_name = None
    last_name = None
    email = None
    group_id = None

    chained_validators = [
        FieldsMatch('password', 'password_confirm'),
    ]
Beispiel #16
0
class EventSchema(Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    name = String(not_empty=True)
    date = SDate()
    location = String()
    sponsor = String()
    host = String()
    designer = String()
    chair = String()
    practice = Bool()
    ispro = Bool()
    courses = Int(min=1, not_empty=True)
    runs = Int(min=1, not_empty=True)
    countedruns = Int(if_empty=0)
    conepen = Number(if_empty=2.0)
    gatepen = Number(if_empty=10.0)
    segments = String()
    regopened = SDateTime()
    regclosed = SDateTime()
    perlimit = Int(min=1)
    doublespecial = Bool()
    totlimit = Int(min=0)
    paypal = String()
    cost = Int()
    notes = String()
Beispiel #17
0
class PackageSchema(Schema):
    current_location = ResourceURI(model_cls=models.Location)
    current_path = UnicodeString()
    description = UnicodeString(max=256)
    encryption_key_fingerprint = UnicodeString(max=512)
    misc_attributes = UnicodeString()
    origin_pipeline = ResourceURI(model_cls=models.Pipeline)
    package_type = OneOf(_flatten(models.Package.PACKAGE_TYPE_CHOICES))
    pointer_file_location = ResourceURI(model_cls=models.Location)
    pointer_file_path = UnicodeString()
    related_packages = ForEach(ResourceURI(model_cls=models.Package))
    replicated_package = ResourceURI(model_cls=models.Package)
    size = Int(min=0)
    status = OneOf(_flatten(models.Package.STATUS_CHOICES))
Beispiel #18
0
class UserForm(Schema):
    """ Form validation schema for users."""
    filter_extra_fields = True
    allow_extra_fields = True

    username = UsernamePlainText(min=5, max=16, strip=True)
    first_name = FirstNameString(not_empty=True, strip=True)
    last_name = LastNameString(not_empty=True, strip=True)
    email = Email()
    password = SecurePassword(min=6, max=80, strip=True)
    password_confirm = String(strip=True)
    group_id = Int(not_empty=True)

    chained_validators = [
        FieldsMatch('password', 'password_confirm'),
        UniqueAuthUsername(),
        UniqueAuthEmail(),
    ]
class DeclarativeAllValidator(All):
    """A CompoundValidator with subvalidators given as attributes."""

    first_validator = Int(min=3)
    second_validator = Int(max=5)
 def setUp(self):
     self.validator = CustomCompoundValidator(
         validators=[Int(min=3), Int(max=5)])
Beispiel #21
0
 def init(self):
     self.add_processor('nums', Int(), show_msg=True, takes_list=True)
Beispiel #22
0
class SpaceUpdateSchema(Schema):
    size = Int(min=0)
    path = UnicodeString(max=256)
    staging_path = UnicodeString(max=256)
Beispiel #23
0
class UserEditForm(UserForm):
    """ Form validation schema for user edit."""
    user_id = Int()  # used in forms hidden field
    password = None
    password_confirm = None
Beispiel #24
0
 def test_validator_fe_instance(self):
     form = Form('f')
     form.add_text('units', 'Units')
     form.add_validator(Int())
     assert isinstance(form._validators[0][0], Int)
Beispiel #25
0
class RegionConfiguration(Configuration, metaclass=RegionConfigurationMeta):
    """Local configuration for the MAAS region."""

    maas_url = ConfigurationOption(
        "maas_url",
        "The HTTP URL for the MAAS region.",
        ExtendedURL(require_tld=False,
                    if_missing="http://localhost:5240/MAAS"),
    )

    # Database options.
    database_host = ConfigurationOption(
        "database_host",
        "The address of the PostgreSQL database.",
        UnicodeString(if_missing="localhost", accept_python=False),
    )
    database_port = ConfigurationOption(
        "database_port",
        "The port of the PostgreSQL database.",
        Int(if_missing=5432, accept_python=False, min=1, max=65535),
    )
    database_name = ConfigurationOption(
        "database_name",
        "The name of the PostgreSQL database.",
        UnicodeString(if_missing="maasdb", accept_python=False),
    )
    database_user = ConfigurationOption(
        "database_user",
        "The user to connect to PostgreSQL as.",
        UnicodeString(if_missing="maas", accept_python=False),
    )
    database_pass = ConfigurationOption(
        "database_pass",
        "The password for the PostgreSQL user.",
        UnicodeString(if_missing="", accept_python=False),
    )
    database_conn_max_age = ConfigurationOption(
        "database_conn_max_age",
        "The lifetime of a database connection, in seconds.",
        Int(if_missing=(5 * 60), accept_python=False, min=0),
    )
    database_keepalive = ConfigurationOption(
        "database_keepalive",
        "Whether keepalive for database connections is enabled.",
        OneWayStringBool(if_missing=True),
    )
    database_keepalive_idle = ConfigurationOption(
        "database_keepalive_idle",
        "Time (in seconds) after which keepalives will be started.",
        Int(if_missing=15),
    )
    database_keepalive_interval = ConfigurationOption(
        "database_keepalive_interval",
        "Interval (in seconds) between keepaliveds.",
        Int(if_missing=15),
    )
    database_keepalive_count = ConfigurationOption(
        "database_keepalive_count",
        "Number of keeaplives that can be lost before connection is reset.",
        Int(if_missing=2),
    )

    # Worker options.
    num_workers = ConfigurationOption(
        "num_workers",
        "The number of regiond worker process to run.",
        Int(if_missing=4, accept_python=False, min=1),
    )

    # Debug options.
    debug = ConfigurationOption(
        "debug",
        "Enable debug mode for detailed error and log reporting.",
        OneWayStringBool(if_missing=False),
    )
    debug_queries = ConfigurationOption(
        "debug_queries",
        "Enable query debugging. Reports number of queries and time for all "
        "actions performed. Requires debug to also be True. mode for detailed "
        "error and log reporting.",
        OneWayStringBool(if_missing=False),
    )
    debug_http = ConfigurationOption(
        "debug_http",
        "Enable HTTP debugging. Logs all HTTP requests and HTTP responses.",
        OneWayStringBool(if_missing=False),
    )
Beispiel #26
0
 def init(self):
     self.add_processor('towho', UnicodeString())
     self.add_processor('num', Int(), show_msg=True)
     self.add_processor('num2', Int(), custom_msg='num: must be an integer')
     self.strict_args = True
 def setUp(self):
     self.validator = AllAndNotOneValidator(
         validators=[Int(min=3), Int(max=5)], number=4)
Beispiel #28
0
class FTPStorageForm(StorageForm):
    event = events.Admin.Storage.FTPStorageForm

    fields = StorageForm.fields + [
        ListFieldSet(
            'ftp',
            suppress_label=True,
            legend=N_('FTP Server Details:'),
            children=[
                TextField('server', label_text=N_('Server Hostname')),
                TextField('user', label_text=N_('Username')),
                TextField('password', label_text=N_('Password')),
                TextField(
                    'upload_dir',
                    label_text=N_('Subdirectory on server to upload to')),
                TextField(
                    'upload_integrity_retries',
                    label_text=N_(
                        'How many times should MediaDrop try to verify the FTP upload before declaring it a failure?'
                    ),
                    validator=Int()),
                TextField(
                    'http_download_uri',
                    label_text=N_('HTTP URL to access remotely stored files')),
                TextField(
                    'rtmp_server_uri',
                    label_text=N_(
                        'RTMP Server URL to stream remotely stored files (Optional)'
                    )),
            ]),
    ] + StorageForm.buttons

    def display(self, value, engine, **kwargs):
        """Display the form with default values from the given StorageEngine.

        If the value dict is not fully populated, populate any missing entries
        with the values from the given StorageEngine's
        :attr:`_data <mediadrop.lib.storage.StorageEngine._data>` dict.

        :param value: A (sparse) dict of values to populate the form with.
        :type value: dict
        :param engine: An instance of the storage engine implementation.
        :type engine: :class:`mediadrop.lib.storage.StorageEngine` subclass

        """
        data = engine._data
        ftp = value.setdefault('ftp', {})
        ftp.setdefault('server', data.get(FTP_SERVER, None))
        ftp.setdefault('user', data.get(FTP_USERNAME, None))
        ftp.setdefault('password', data.get(FTP_PASSWORD, None))
        ftp.setdefault('upload_dir', data.get(FTP_UPLOAD_DIR, None))
        ftp.setdefault('upload_integrity_retries',
                       data.get(FTP_MAX_INTEGRITY_RETRIES, None))
        ftp.setdefault('http_download_uri', data.get(HTTP_DOWNLOAD_URI, None))
        ftp.setdefault('rtmp_server_uri', data.get(RTMP_SERVER_URI, None))
        return StorageForm.display(self, value, engine, **kwargs)

    def save_engine_params(self, engine, **kwargs):
        """Map validated field values to engine data.

        Since form widgets may be nested or named differently than the keys
        in the :attr:`mediadrop.lib.storage.StorageEngine._data` dict, it is
        necessary to manually map field values to the data dictionary.

        :type engine: :class:`mediadrop.lib.storage.StorageEngine` subclass
        :param engine: An instance of the storage engine implementation.
        :param \*\*kwargs: Validated and filtered form values.
        :raises formencode.Invalid: If some post-validation error is detected
            in the user input. This will trigger the same error handling
            behaviour as with the @validate decorator.

        """
        StorageForm.save_engine_params(self, engine, **kwargs)
        ftp = kwargs['ftp']
        engine._data[FTP_SERVER] = ftp['server']
        engine._data[FTP_USERNAME] = ftp['user']
        engine._data[FTP_PASSWORD] = ftp['password']
        engine._data[FTP_UPLOAD_DIR] = ftp['upload_dir']
        engine._data[FTP_MAX_INTEGRITY_RETRIES] = ftp[
            'upload_integrity_retries']
        engine._data[HTTP_DOWNLOAD_URI] = ftp['http_download_uri']
        engine._data[RTMP_SERVER_URI] = ftp['rtmp_server_uri']
Beispiel #29
0

class AddProyecto(AddRecordForm):
    """ Define el formato del formulario para crear un nuevo proyecto"""
    __model__ = Proyecto
    __omit_fields__ = ['id', 'fases', 'fichas', 'estado', 'fecha_inicio', \
                      'fecha_fin']
    nombre = All(NotEmpty(), ValidarExpresion(r'^[A-Za-z][A-Za-z0-9 ]*$'), \
            Unico())
    nro_fases = All(NotEmpty(), Int(min=0))
    __dropdown_field_names__ = {'lider': 'nombre_usuario'}


add_proyecto_form = AddProyecto(DBSession)

form_validator =  Schema(nro_fases = All(NroValido(), NotEmpty(), Int(min = \
                 0)), ignore_key_missing = True)


class CantidadFasesField(TextField):
    """
    Clase correspondiente a un validador que se utiliza para deshabilitar la
    modificación del número de fases de un proyecto si el mismo ya ha iniciado.
    """
    def update_params(self, d):
        """
        Realiza el control citado anteriormente.
        """
        id_proy = unicode(request.url.split("/")[-2])
        pr = DBSession.query(Proyecto).get(id_proy)
        if pr.estado != u"Nuevo":
            d.disabled = True
Beispiel #30
0
 def init(self):
     self.add_processor('towho', UnicodeString())
     self.add_processor('num', Int())