Пример #1
0
class CertificateRevokeSchema(LemurInputSchema):
    comments = fields.String()
Пример #2
0
class DataSubjectQuerySchema(Schema):
    email = fields.String()
    moodle_username = fields.String()
    source = fields.String()
class FooRequestSchema(Schema):
    text = fields.String(required=True)
Пример #4
0
class sUserAccountUpdate (Schema):
    _id = fields.String(required=True)
    email = fields.Email(required=True)
    first_name = fields.String(required=True)
    last_name = fields.String()
    change_password = fields.Boolean(required=True)
    password = fields.String(validate=validate.Length(min=8))
    new_password = fields.String(validate=validate.Length(min=8))
    confirm_new_password = fields.String(validate=validate.Length(min=8))

    class Meta:
        ordered=True

    @pre_load
    def remove_empty(self, data):
        processed_data = data.copy()
        for key in data:
            if (data[key]==""):
                processed_data.pop(key)
        return processed_data

    @validates("_id")
    def validate_id(self, value):
        user_id = value
        Users = mongodb['users']
        user = Users.find_one({"_id": user_id})
        if (user== None):
            raise ValidationError('User ID does not exist')

    @validates_schema()
    def validate_password(self, data):
        if ('password' in data):
            user_id = data['_id']
            Users = mongodb['users']
            user = Users.find_one({"_id": user_id})
            password = data["password"]
            authenticated = check_password_hash(user['password_hash'], password)
            if (not authenticated):
                raise ValidationError('Incorrect Password',"password")


    @validates_schema()
    def validate_confirm_password(self, data):
        if ('change_password' in data):
            if (('new_password' in data) and ('confirm_new_password' in data)):
                if data['new_password'] != data['confirm_new_password']:
                    raise ValidationError('Passwords do not match','confirm_new_password')


    @validates_schema()
    def validate_password_change(self, data):
        missing_fields = []
        if ('change_password' in data):
            if (data['change_password']):
                if ('password' not in data):
                    missing_fields.append("password")
                if ('new_password' not in data):
                    missing_fields.append("new_password")
                if ('confirm_new_password' not in data):
                    missing_fields.append("confirm_new_password")

            if (len(missing_fields) > 0):
                raise ValidationError('Field is definitely Required', missing_fields)
Пример #5
0
class RecordSchema(common.CommonRecordSchema):
    """Schema for records v1 in JSON."""
    type = fields.Str(default='record')

    draft_id = fields.String(attribute='metadata._deposit.id', dump_only=True)
Пример #6
0
class UserSchema(mm.Schema):
    email = fields.String()
    name = fields.Function(lambda u: f'{u["first_name"]} {u["last_name"]}')
    initials = fields.Function(
        lambda u: f'{u["first_name"][0]} {u["last_name"][0]}')
    uid = fields.String()
Пример #7
0
class RelatedResultResponseSchema(Schema):
    value = fields.Integer(description="The related item identifier")
    text = fields.String(description="The related item string representation")
Пример #8
0
class BookmarkSchema(Schema):
    id = fields.Integer()
    url = fields.Url()
    title = fields.String()
    user = fields.Nested("UserSchema")
    created_at = fields.Date()
Пример #9
0
class CreateBookmarkSchema(Schema):
    id = fields.Integer()
    url = fields.Url(required=True)
    title = fields.String(required=True)
Пример #10
0
 class WidgetSchema(Schema):
     id = fields.Integer(as_string=True)
     owner_id = fields.String()
Пример #11
0
class RoleSchema(Schema):
    id = fields.Integer()
    name = fields.String()
Пример #12
0
class DeviceSchema(Schema):
    id = fields.Integer()
    uuid = fields.String()
    name = fields.String(validate=Length(0, 100))
Пример #13
0
class CertificateInputSchema(CertificateCreationSchema):
    name = fields.String()
    common_name = fields.String(required=True, validate=validators.common_name)
    authority = fields.Nested(AssociatedAuthoritySchema, required=True)

    validity_start = ArrowDateTime(allow_none=True)
    validity_end = ArrowDateTime(allow_none=True)
    validity_years = fields.Integer(allow_none=True)

    destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
    notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True)
    replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
    replacements = fields.Nested(
        AssociatedCertificateSchema, missing=[], many=True
    )  # deprecated
    roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
    dns_provider = fields.Nested(
        AssociatedDnsProviderSchema, missing=None, allow_none=True, required=False
    )

    csr = fields.String(allow_none=True, validate=validators.csr)

    key_type = fields.String(
        validate=validate.OneOf(CERTIFICATE_KEY_TYPES), missing="RSA2048"
    )

    notify = fields.Boolean(default=True)
    rotation = fields.Boolean()
    rotation_policy = fields.Nested(
        AssociatedRotationPolicySchema,
        missing={"name": "default"},
        allow_none=True,
        default={"name": "default"},
    )

    # certificate body fields
    organizational_unit = fields.String(
        missing=lambda: current_app.config.get("LEMUR_DEFAULT_ORGANIZATIONAL_UNIT")
    )
    organization = fields.String(
        missing=lambda: current_app.config.get("LEMUR_DEFAULT_ORGANIZATION")
    )
    location = fields.String(
        missing=lambda: current_app.config.get("LEMUR_DEFAULT_LOCATION")
    )
    country = fields.String(
        missing=lambda: current_app.config.get("LEMUR_DEFAULT_COUNTRY")
    )
    state = fields.String(missing=lambda: current_app.config.get("LEMUR_DEFAULT_STATE"))

    extensions = fields.Nested(ExtensionSchema)

    @validates_schema
    def validate_authority(self, data):
        if 'authority' not in data:
            raise ValidationError("Missing Authority.")

        if isinstance(data["authority"], str):
            raise ValidationError("Authority not found.")

        if not data["authority"].active:
            raise ValidationError("The authority is inactive.", ["authority"])

    @validates_schema
    def validate_dates(self, data):
        validators.dates(data)

    @pre_load
    def load_data(self, data):
        if data.get("replacements"):
            data["replaces"] = data[
                "replacements"
            ]  # TODO remove when field is deprecated
        if data.get("csr"):
            csr_sans = cert_utils.get_sans_from_csr(data["csr"])
            if not data.get("extensions"):
                data["extensions"] = {"subAltNames": {"names": []}}
            elif not data["extensions"].get("subAltNames"):
                data["extensions"]["subAltNames"] = {"names": []}
            elif not data["extensions"]["subAltNames"].get("names"):
                data["extensions"]["subAltNames"]["names"] = []

            data["extensions"]["subAltNames"]["names"] = csr_sans
        return missing.convert_validity_years(data)
Пример #14
0
class CertificateSchema(LemurInputSchema):
    owner = fields.Email(required=True)
    description = fields.String(missing="", allow_none=True)
Пример #15
0
class ChartDataRollingOptionsSchema(ChartDataPostProcessingOperationOptionsSchema):
    """
    Rolling operation config.
    """

    columns = (
        fields.Dict(
            description="columns on which to perform rolling, mapping source column to "
            "target column. For instance, `{'y': 'y'}` will replace the "
            "column `y` with the rolling value in `y`, while `{'y': 'y2'}` "
            "will add a column `y2` based on rolling values calculated "
            "from `y`, leaving the original column `y` unchanged.",
            example={"weekly_rolling_sales": "sales"},
        ),
    )
    rolling_type = fields.String(
        description="Type of rolling window. Any numpy function will work.",
        validate=validate.OneOf(
            choices=(
                "average",
                "argmin",
                "argmax",
                "cumsum",
                "cumprod",
                "max",
                "mean",
                "median",
                "nansum",
                "nanmin",
                "nanmax",
                "nanmean",
                "nanmedian",
                "min",
                "percentile",
                "prod",
                "product",
                "std",
                "sum",
                "var",
            )
        ),
        required=True,
        example="percentile",
    )
    window = fields.Integer(
        description="Size of the rolling window in days.", required=True, example=7,
    )
    rolling_type_options = fields.Dict(
        desctiption="Optional options to pass to rolling method. Needed for "
        "e.g. quantile operation.",
        example={},
    )
    center = fields.Boolean(
        description="Should the label be at the center of the window. Default: `false`",
        example=False,
    )
    win_type = fields.String(
        description="Type of window function. See "
        "[SciPy window functions](https://docs.scipy.org/doc/scipy/reference"
        "/signal.windows.html#module-scipy.signal.windows) "
        "for more details. Some window functions require passing "
        "additional parameters to `rolling_type_options`. For instance, "
        "to use `gaussian`, the parameter `std` needs to be provided.",
        validate=validate.OneOf(
            choices=(
                "boxcar",
                "triang",
                "blackman",
                "hamming",
                "bartlett",
                "parzen",
                "bohman",
                "blackmanharris",
                "nuttall",
                "barthann",
                "kaiser",
                "gaussian",
                "general_gaussian",
                "slepian",
                "exponential",
            )
        ),
    )
    min_periods = fields.Integer(
        description="The minimum amount of periods required for a row to be included "
        "in the result set.",
        example=7,
    )
Пример #16
0
class EditBookmarkSchema(Schema):
    url = fields.Url()
    title = fields.String()
Пример #17
0
class ChartDataQueryObjectSchema(Schema):
    filters = fields.List(fields.Nested(ChartDataFilterSchema), required=False)
    granularity = fields.String(
        description="Name of temporal column used for time filtering. For legacy Druid "
        "datasources this defines the time grain.",
    )
    granularity_sqla = fields.String(
        description="Name of temporal column used for time filtering for SQL "
        "datasources. This field is deprecated, use `granularity` "
        "instead.",
        deprecated=True,
    )
    groupby = fields.List(
        fields.String(description="Columns by which to group the query.",),
    )
    metrics = fields.List(
        fields.Raw(),
        description="Aggregate expressions. Metrics can be passed as both "
        "references to datasource metrics (strings), or ad-hoc metrics"
        "which are defined only within the query object. See "
        "`ChartDataAdhocMetricSchema` for the structure of ad-hoc metrics.",
    )
    post_processing = fields.List(
        fields.Nested(ChartDataPostProcessingOperationSchema, allow_none=True),
        description="Post processing operations to be applied to the result set. "
        "Operations are applied to the result set in sequential order.",
    )
    time_range = fields.String(
        description="A time rage, either expressed as a colon separated string "
        "`since : until` or human readable freeform. Valid formats for "
        "`since` and `until` are: \n"
        "- ISO 8601\n"
        "- X days/years/hours/day/year/weeks\n"
        "- X days/years/hours/day/year/weeks ago\n"
        "- X days/years/hours/day/year/weeks from now\n"
        "\n"
        "Additionally, the following freeform can be used:\n"
        "\n"
        "- Last day\n"
        "- Last week\n"
        "- Last month\n"
        "- Last quarter\n"
        "- Last year\n"
        "- No filter\n"
        "- Last X seconds/minutes/hours/days/weeks/months/years\n"
        "- Next X seconds/minutes/hours/days/weeks/months/years\n",
        example="Last week",
    )
    time_shift = fields.String(
        description="A human-readable date/time string. "
        "Please refer to [parsdatetime](https://github.com/bear/parsedatetime) "
        "documentation for details on valid values.",
    )
    is_timeseries = fields.Boolean(
        description="Is the `query_object` a timeseries.", required=False
    )
    timeseries_limit = fields.Integer(
        description="Maximum row count for timeseries queries. Default: `0`",
    )
    timeseries_limit_metric = fields.Raw(
        description="Metric used to limit timeseries queries by.", allow_none=True,
    )
    row_limit = fields.Integer(
        description='Maximum row count. Default: `config["ROW_LIMIT"]`',
        validate=[
            Range(min=1, error=_("`row_limit` must be greater than or equal to 1"))
        ],
    )
    row_offset = fields.Integer(
        description="Number of rows to skip. Default: `0`",
        validate=[
            Range(min=0, error=_("`row_offset` must be greater than or equal to 0"))
        ],
    )
    order_desc = fields.Boolean(
        description="Reverse order. Default: `false`", required=False
    )
    extras = fields.Nested(ChartDataExtrasSchema, required=False)
    columns = fields.List(fields.String(), description="",)
    orderby = fields.List(
        fields.List(fields.Raw()),
        description="Expects a list of lists where the first element is the column "
        "name which to sort by, and the second element is a boolean ",
        example=[["my_col_1", False], ["my_col_2", True]],
    )
    where = fields.String(
        description="WHERE clause to be added to queries using AND operator."
        "This field is deprecated and should be passed to `extras`.",
        deprecated=True,
    )
    having = fields.String(
        description="HAVING clause to be added to aggregate queries using "
        "AND operator. This field is deprecated and should be passed "
        "to `extras`.",
        deprecated=True,
    )
    having_filters = fields.List(
        fields.Dict(),
        description="HAVING filters to be added to legacy Druid datasource queries. "
        "This field is deprecated and should be passed to `extras` "
        "as `filters_druid`.",
        deprecated=True,
    )
Пример #18
0
class CreateUserSchema(Schema):
    username = fields.String(required=True)
    email = fields.Email(required=True)
    password = fields.String(required=True)
    role_id = fields.Integer()
Пример #19
0
class NewUnknownParticipantSchema(mm.Schema):
    name = fields.String(required=True)
Пример #20
0
class EditUserSchema(Schema):
    email = fields.Email()
    password = fields.String()
    role_id = fields.Integer()
Пример #21
0
class DistinctResultResponseSchema(Schema):
    text = fields.String(description="The distinct item")
Пример #22
0
class UserSchema(Schema):
    id = fields.Integer()
    username = fields.String()
    email = fields.Email()
    role_id = fields.Integer()
    role_name = fields.String(attribute="role.name")
class CommentSchema(Schema):
    user = fields.Nested(CommentUserSchema)
    comment = fields.String(required=True)
    time = fields.Time(required=True)
Пример #24
0
class ChartGetDatasourceObjectResponseSchema(Schema):
    label = fields.String(description="The name of the datasource")
    value = fields.Nested(ChartGetDatasourceObjectDataResponseSchema)
Пример #25
0
class DataSubjectSchema(Schema):
    id = fields.Integer()
    email = fields.Email()
    lti_user_id = fields.String()
    moodle_username = fields.String()
    source = fields.String()
Пример #26
0
class ChartCacheScreenshotResponseSchema(Schema):
    cache_key = fields.String(description="The cache key")
    chart_url = fields.String(description="The url to render the chart")
    image_url = fields.String(description="The url to fetch the screenshot")
Пример #27
0
class PostItem(Schema):
    Id = fields.String(data_key="_id", default="", missing="")
    Id2 = fields.String(data_key="id", default="", missing="")
    At = fields.Dict(data_key="@", default="", missing="")
    Article = fields.Bool(data_key="article", default="", missing="")
    Body = fields.String(data_key="body", default="", missing="")
    Color = fields.String(data_key="color", default="", missing="")
    CommentDepth = fields.Int(data_key="commentDepth", default="", missing="")
    Commented = fields.Bool(data_key="commented", default="", missing="")
    Comments = fields.String(data_key="comments", default="", missing="")
    Controversy = fields.Int(data_key="controversy", default="", missing="")
    Conversation = fields.String(data_key="conversation",
                                 default="",
                                 missing="")
    CreatedAt = fields.String(data_key="createdAt", default="", missing="")
    Creator = fields.String(data_key="creator", default="", missing="")
    Depth = fields.String(data_key="depth", default="", missing="")
    DepthRaw = fields.Int(data_key="depthRaw", default="", missing="")
    Downvotes = fields.String(data_key="downvotes", default="", missing="")
    Hashtags = fields.List(fields.String(),
                           data_key="hashtags",
                           default="",
                           missing="")
    Impressions = fields.String(data_key="impressions", default="", missing="")
    IsPrimary = fields.Bool(data_key="isPrimary", default="", missing="")
    Links = fields.List(fields.String(),
                        data_key="links",
                        default="",
                        missing="")
    Post = fields.String(data_key="post", default="", missing="")
    Preview = fields.String(data_key="preview", default="", missing="")
    ReplyingTo = fields.String(data_key="replyingTo", default="", missing="")
    Reposted = fields.Bool(data_key="reposted", default="", missing="")
    Reposts = fields.String(data_key="reposts", default="", missing="")
    ShareLink = fields.String(data_key="shareLink", default="", missing="")
    State = fields.Int(data_key="state", default="", missing="")
    Upvotes = fields.String(data_key="upvotes", default="", missing="")
    Parent = fields.String(data_key="parent", default="", missing="")
    Score = fields.String(data_key="score", default="", missing="")
    Sponsored = fields.String(data_key="sponsored", default="", missing="")
    Sensitive = fields.Bool(data_key="sensitive", default="", missing="")
    Root = fields.String(data_key="root", default="", missing="")
    Voted = fields.String(data_key="voted", default="", missing="")

    class Meta:
        unknown = EXCLUDE
Пример #28
0
class ChartDataColumnSchema(Schema):
    column_name = fields.String(
        description="The name of the target column", example="mycol",
    )
    type = fields.String(description="Type of target column", example="BIGINT")
class FooResponseSchema(Schema):
    text = fields.String(request=True)
Пример #30
0
class CertificateOutputSchema(LemurOutputSchema):
    id = fields.Integer()
    external_id = fields.String()
    bits = fields.Integer()
    body = fields.String()
    chain = fields.String()
    csr = fields.String()
    deleted = fields.Boolean(default=False)
    description = fields.String()
    issuer = fields.String()
    name = fields.String()
    dns_provider_id = fields.Integer(required=False, allow_none=True)
    date_created = ArrowDateTime()
    resolved = fields.Boolean(required=False, allow_none=True)
    resolved_cert_id = fields.Integer(required=False, allow_none=True)

    rotation = fields.Boolean()

    # Note aliasing is the first step in deprecating these fields.
    notify = fields.Boolean()
    active = fields.Boolean(attribute="notify")
    has_private_key = fields.Boolean()

    cn = fields.String()
    common_name = fields.String(attribute="cn")
    distinguished_name = fields.String()

    not_after = fields.DateTime()
    validity_end = ArrowDateTime(attribute="not_after")

    not_before = fields.DateTime()
    validity_start = ArrowDateTime(attribute="not_before")

    owner = fields.Email()
    san = fields.Boolean()
    serial = fields.String()
    serial_hex = Hex(attribute="serial")
    signing_algorithm = fields.String()

    status = fields.String()
    user = fields.Nested(UserNestedOutputSchema)

    extensions = fields.Nested(ExtensionSchema)

    # associated objects
    domains = fields.Nested(DomainNestedOutputSchema, many=True)
    destinations = fields.Nested(DestinationNestedOutputSchema, many=True)
    notifications = fields.Nested(NotificationNestedOutputSchema, many=True)
    replaces = fields.Nested(CertificateNestedOutputSchema, many=True)
    authority = fields.Nested(AuthorityNestedOutputSchema)
    dns_provider = fields.Nested(DnsProvidersNestedOutputSchema)
    roles = fields.Nested(RoleNestedOutputSchema, many=True)
    endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])
    replaced_by = fields.Nested(
        CertificateNestedOutputSchema, many=True, attribute="replaced"
    )
    rotation_policy = fields.Nested(RotationPolicyNestedOutputSchema)