예제 #1
0
def _schema_1():
    """Returns Voluptuous Schema object."""
    return Schema({
        Required('schema'): 1,
        Required('bugzilla'): {
            Required('product'): All(str, Length(min=1)),
            Required('component'): All(str, Length(min=1)),
        },
        'origin': {
            Required('name'): All(str, Length(min=1)),
            Required('description'): All(str, Length(min=1)),
            Required('url'): FqdnUrl(),
            Required('license'): Msg(License(), msg='Unsupported License'),
            Required('release'): All(str, Length(min=1)),
        },
        'vendoring': {
            Required('url'): FqdnUrl(),
            Required('revision'): Match(r'^[a-fA-F0-9]{12,40}$'),
            'patches': Unique([str]),
            'keep': Unique([str]),
            'exclude': Unique([str]),
            'include': Unique([str]),
            'run_after': Unique([str]),
        },
    })
예제 #2
0
class ArgumentSchemas:
    MASS_UNITS = frozenset({'g', 'kg', 'lb', 'oz',})
    VOLUME_UNITS = frozenset({'L', 'mL', 'cup', 'floz', 'Tbsp', 'tsp', 'qt', 'gal'})
    TIME_UNITS = frozenset({'sec', 'min', 'hr', 'day', 'week'})
    LENGTH_UNITS = frozenset({'cm', 'm', 'mm', 'in', 'ft',})

    STRING = Schema(All(str, Length(min=1)))
    POS_INT = Schema(All(int, Range(min=1)))
    NON_NEG_INT = Schema(All(int, Range(min=0)))
    VARIANT_TAG_SET = Schema(All(Unique(), Length(min=1), [NON_NEG_INT]))
    FRACTION = Schema({
                                Required('keep'): POS_INT,
                                Required('pass'): POS_INT,
                            })
    QUANTITY_BASE = Schema({
                                Required('base'): POS_INT,
                                Required('range', default=0): NON_NEG_INT,
                                Required('base_den', default=1): POS_INT,
                                Required('range_den', default=1): POS_INT,
                                Required('less_ok', default=True): bool,
                                Required('more_ok', default=True): bool,
                            })
    QUANTITY_MASS = QUANTITY_BASE.extend({
                                Required('units'): All(str, In(MASS_UNITS)),
                            })
    QUANTITY_VOLUME = QUANTITY_BASE.extend({
                                Required('units'): All(str, In(VOLUME_UNITS)),
                            })
    QUANTITY_COUNT = QUANTITY_BASE.extend({
                                Required('units'): STRING,
                            })
    QUANTITY_TIME = QUANTITY_BASE.extend({
                                Required('units'): All(str, In(TIME_UNITS)),
                            })
    NONE = Schema(None)
    STRING_OR_NONE = Schema(Or(STRING, NONE))
예제 #3
0
         Extra: object,
     }
 },
 Required('provisionerId',
          msg="Required for TaskCluster schema."):
 All(Match(r'^([a-zA-Z0-9-_]*)$'), Length(min=1,
                                          max=22)),
 Required('priority',
          msg="Required for releasetasks schema."):
 'high',
 Required('routes',
          msg="Required for releasetasks schema."):
 All([All(str, Length(min=1, max=249))],
     index_route_requirement,
     Length(max=10),
     Unique(),
     msg="Maximum 10 unique routes per task."),
 Required('workerType',
          msg="Required for TaskCluster schema."):
 All(Match(r'^([a-zA-Z0-9-_]*)$'), Length(min=1,
                                          max=22)),
 'dependencies':
 All([Match(TASKCLUSTER_ID_REGEX)], Length(max=100),
     Unique()),
 'expires':
 str,
 'requires':
 Any('all-completed', 'all-resolved'),
 'retries':
 Range(min=0, max=49),
 'schedulerId':
예제 #4
0
def _schema_1():
    """Returns Voluptuous Schema object."""
    return Schema({
        Required("schema"): 1,
        Required("bugzilla"): {
            Required("product"): All(str, Length(min=1)),
            Required("component"): All(str, Length(min=1)),
        },
        "origin": {
            Required("name"):
            All(str, Length(min=1)),
            Required("description"):
            All(str, Length(min=1)),
            Required("url"):
            FqdnUrl(),
            Required("license"):
            Msg(License(), msg="Unsupported License"),
            "license-file":
            All(str, Length(min=1)),
            Required("release"):
            All(str, Length(min=1)),
            # The following regex defines a valid git reference
            # The first group [^ ~^:?*[\]] matches 0 or more times anything
            # that isn't a Space, ~, ^, :, ?, *, or ]
            # The second group [^ ~^:?*[\]\.]+ matches 1 or more times
            # anything that isn't a Space, ~, ^, :, ?, *, [, ], or .
            Required("revision"):
            Match(r"^[^ ~^:?*[\]]*[^ ~^:?*[\]\.]+$"),
        },
        "updatebot": {
            Required("maintainer-phab"):
            All(str, Length(min=1)),
            Required("maintainer-bz"):
            All(str, Length(min=1)),
            "tracking":
            All(str, Length(min=1)),
            "tasks":
            All(
                UpdatebotTasks(),
                [{
                    Required("type"):
                    In(
                        ["vendoring", "commit-alert"],
                        msg="Invalid type specified in tasks",
                    ),
                    "branch":
                    All(str, Length(min=1)),
                    "enabled":
                    Boolean(),
                    "cc":
                    Unique([str]),
                    "needinfo":
                    Unique([str]),
                    "filter":
                    In(
                        ["none", "security", "source-extensions"],
                        msg="Invalid filter value specified in tasks",
                    ),
                    "source-extensions":
                    Unique([str]),
                    "frequency":
                    Match(r"^(every|release|[1-9][0-9]* weeks?)$"),
                    "platform":
                    Match(r"^(windows|linux)$"),
                }],
            ),
        },
        "vendoring": {
            Required("url"):
            FqdnUrl(),
            Required("source-hosting"):
            All(
                str,
                Length(min=1),
                In(VALID_SOURCE_HOSTS, msg="Unsupported Source Hosting"),
            ),
            "vendor-directory":
            All(str, Length(min=1)),
            "patches":
            Unique([str]),
            "keep":
            Unique([str]),
            "exclude":
            Unique([str]),
            "include":
            Unique([str]),
            "update-actions":
            All(
                UpdateActions(),
                [{
                    Required("action"):
                    In(
                        [
                            "copy-file",
                            "replace-in-file",
                            "run-script",
                            "delete-path",
                        ],
                        msg="Invalid action specified in update-actions",
                    ),
                    "from":
                    All(str, Length(min=1)),
                    "to":
                    All(str, Length(min=1)),
                    "pattern":
                    All(str, Length(min=1)),
                    "with":
                    All(str, Length(min=1)),
                    "file":
                    All(str, Length(min=1)),
                    "script":
                    All(str, Length(min=1)),
                    "cwd":
                    All(str, Length(min=1)),
                    "path":
                    All(str, Length(min=1)),
                }],
            ),
        },
    })
예제 #5
0
         Optional('properties'): {
             'version': str,
             'build_number': int,
             'release_promotion': bool,
             'revision': str,
             'product': str,
             Extra: object,
         }
     },
     Required('provisionerId', msg="Required for TaskCluster schema."): All(Match(r'^([a-zA-Z0-9-_]*)$'), Length(min=1, max=22)),
     Required('priority', msg="Required for releasetasks schema."): 'high',
     Required('routes', msg="Required for releasetasks schema."): All(
         [All(str, Length(min=1, max=249))],
         index_route_requirement,
         Length(max=10),
         Unique(),
         msg="Maximum 10 unique routes per task."),
     Required('workerType', msg="Required for TaskCluster schema."): All(Match(r'^([a-zA-Z0-9-_]*)$'), Length(min=1, max=22)),
     'dependencies': All([Match(TASKCLUSTER_ID_REGEX)],
                         Length(max=100),
                         Unique()),
     'expires': str,
     'requires': Any('all-completed', 'all-resolved'),
     'retries': Range(min=0, max=49),
     'schedulerId': All(Match(r'^([a-zA-Z0-9-_]*)$'), Length(min=1, max=22)),
     'scopes': [Match(r'^[\x20-\x7e]*$')],
     'tags': {
         All(str, Length(max=4096)): str,
     },
     'taskGroupId': Match(TASKCLUSTER_ID_REGEX),
 }, extra=False, required=False))
예제 #6
0
파일: moz_yaml.py 프로젝트: jt9897253/mozjs
def _schema_1():
    """Returns Voluptuous Schema object."""
    return Schema({
        Required("schema"): 1,
        Required("bugzilla"): {
            Required("product"): All(str, Length(min=1)),
            Required("component"): All(str, Length(min=1)),
        },
        "origin": {
            Required("name"): All(str, Length(min=1)),
            Required("description"): All(str, Length(min=1)),
            Required("url"): FqdnUrl(),
            Required("license"): Msg(License(), msg="Unsupported License"),
            "license-file": All(str, Length(min=1)),
            Required("release"): All(str, Length(min=1)),
            Required("revision"): Match(r"^[a-fA-F0-9]{12,40}$"),
        },
        "updatebot": {
            Required("maintainer-phab"):
            All(str, Length(min=1)),
            Required("maintainer-bz"):
            All(str, Length(min=1)),
            "tasks":
            All(
                UpdatebotTasks(),
                [{
                    Required("type"):
                    In(
                        [
                            "vendoring",
                            "commit-alert",
                        ],
                        msg="Invalid type specified in tasks",
                    ),
                    "branch":
                    All(str, Length(min=1)),
                    "enabled":
                    Boolean(),
                    "cc":
                    Unique([str]),
                    "filter":
                    In(
                        [
                            "none",
                            "security",
                            "source-extensions",
                        ],
                        msg="Invalid filter value specified in tasks",
                    ),
                    "source-extensions":
                    Unique([str]),
                }],
            ),
        },
        "vendoring": {
            Required("url"):
            FqdnUrl(),
            Required("source-hosting"):
            All(
                str,
                Length(min=1),
                In(VALID_SOURCE_HOSTS, msg="Unsupported Source Hosting"),
            ),
            "vendor-directory":
            All(str, Length(min=1)),
            "patches":
            Unique([str]),
            "keep":
            Unique([str]),
            "exclude":
            Unique([str]),
            "include":
            Unique([str]),
            "update-actions":
            All(
                UpdateActions(),
                [{
                    Required("action"):
                    In(
                        [
                            "copy-file",
                            "replace-in-file",
                            "run-script",
                            "delete-path",
                        ],
                        msg="Invalid action specified in update-actions",
                    ),
                    "from":
                    All(str, Length(min=1)),
                    "to":
                    All(str, Length(min=1)),
                    "pattern":
                    All(str, Length(min=1)),
                    "with":
                    All(str, Length(min=1)),
                    "file":
                    All(str, Length(min=1)),
                    "script":
                    All(str, Length(min=1)),
                    "cwd":
                    All(str, Length(min=1)),
                    "path":
                    All(str, Length(min=1)),
                }],
            ),
        },
    })
예제 #7
0
    return v


parsed_meta_schema = Schema({
    Required('name'):
    All(Length(min=1), _safepathcomp_str),
    Required('volumes'):
    Schema(
        All(dict, Length(min=1), _dict_value_unique,
            {All(Length(min=1), _safepathcomp_str): FqdnUrl()})),
    'finished':
    bool,
    'description':
    All(str, _st_str),
    'authors':
    All([_st_str], Unique()),
})

meta_schema = parsed_meta_schema.extend({
    Required('url'):
    FqdnUrl(),
    Required('volumes_checked_time'):
    DT.datetime,
    Required('volumes_modified_time'):
    DT.datetime,
})

config_schema = Schema({
    'data_dirs':
    All(
        [
예제 #8
0
class EntityTypeHandler(Handler):
    def __init__(self):
        self.session = Session()

    def get(self, ident=None):
        if ident is None:
            return [
                entity_type.to_dict()
                for entity_type in get_all(self.session, EntityType)
            ]
        else:
            return get_one(self.session, EntityType, id=ident).to_dict()

    @requires_validation(
        Schema({
            Required('name'): non_empty_string,
            Required('tags'): And([non_empty_string], Unique()),
            Required('meta'): And([non_empty_string], Unique()),
            Required('series'): And([non_empty_string], Unique()),
        }))
    def post(self):
        data = self.request.data
        entity_type = EntityType(name=data['name'])
        self.session.add(entity_type)

        # add tags, meta and series
        for tag in data['tags']:
            self.session.add(TagAttribute(
                entity_type=entity_type,
                name=tag,
            ))
        for meta in data['meta']:
            self.session.add(
                MetaAttribute(
                    entity_type=entity_type,
                    name=meta,
                ))
        for series in data['series']:
            self.session.add(
                SeriesAttribute(
                    entity_type=entity_type,
                    name=series,
                ))

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity_type.id,
        }

    @requires_validation(_assert_objects_were_not_created,
                         with_route_params=True)
    @requires_validation(
        Schema({
            'name': non_empty_string,
            'tags': And([non_empty_string], Unique()),
            'meta': And([non_empty_string], Unique()),
            'series': And([non_empty_string], Unique()),
        }))
    def put(self, ident):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=ident)
        if 'name' in data:
            entity_type.name = data['name']

        # add tags, meta and series
        if 'tags' in data:
            for tag in data['tags']:
                self.session.add(
                    TagAttribute(
                        entity_type=entity_type,
                        name=tag,
                    ))
        if 'meta' in data:
            for meta in data['meta']:
                self.session.add(
                    MetaAttribute(
                        entity_type=entity_type,
                        name=meta,
                    ))
        if 'series' in data:
            for series in data['series']:
                self.session.add(
                    SeriesAttribute(
                        entity_type=entity_type,
                        name=series,
                    ))

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity_type.id,
        }

    def delete(self, ident):
        entity_type = get_one(self.session, EntityType, id=ident)
        now = time.time()
        entity_type.delete_ts = now
        for tag in entity_type.tags:
            tag.delete_ts = now
        for series in entity_type.series:
            series.delete_ts = now
            for alert in series.alerts:
                alert.delete_ts = now
        for meta in entity_type.meta:
            meta.delete_ts = now
        for entity in entity_type.nodes:
            entity.delete_ts = now
            for tag in entity.tags:
                tag.delete_ts = now
            for meta in entity.meta:
                meta.delete_ts = now
            for child in entity.children:
                child.parent = entity.parent

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}