Пример #1
0
class Schema(Model):
    multipleOf = FloatType(min_value=0, serialize_when_none=False)
    # must be present if exclusiveMaximum is present.
    maximum = FloatType(serialize_when_none=False)
    exclusiveMaximum = BooleanType(serialize_when_none=False)
    # must be present if exclusiveMinimum is present.
    minimum = FloatType(serialize_when_none=False)
    exclusiveMinimum = BooleanType(serialize_when_none=False)

    # validation for strings
    maxLength = IntType(min_value=0, serialize_when_none=False)
    minLength = IntType(min_value=0, serialize_when_none=False)
    pattern = RegularExpression(serialize_when_none=False)

    # validation for arrays
    additionalItems = PolyModelType([BooleanType(), "Schema"],
                                    serialize_when_none=False)
    items_ = PolyModelType(["Schema", ListType(ModelType("Schema"))],
                           serialized_name="items",
                           deserialize_from=["items"],
                           serialize_when_none=False)
    maxItems = IntType(min_value=0, serialize_when_none=False)
    minItems = IntType(min_value=0, serialize_when_none=False)
    uniqueItems = BooleanType(serialize_when_none=False)

    # validation for objects
    maxProperties = IntType(min_value=0, serialize_when_none=False)
    minProperties = IntType(min_value=0, serialize_when_none=False)
    # TODO: allow boolean type.
    additionalProperties = PolyModelType(
        ["Schema"],
        # claim_function=_claim_additional_properties,
        required=False,
        serialize_when_none=False)
    properties = DictType(ModelType("Schema"), serialize_when_none=False)
    patternProperties = DictType(ModelType("Schema"),
                                 serialize_when_none=False)
    dependencies = ModelType("Schema", serialize_when_none=False)
    required = ListType(StringType(), min_size=1, serialize_when_none=False)

    # any type
    enum = ListType(BaseType(), serialize_when_none=False)
    type = StringType(serialize_when_none=False, required=True)
    format = DataTypeFormat(serialize_when_none=False)
    allOf = ListType(ModelType("Schema"), serialize_when_none=False)
    anyOf = ListType(ModelType("Schema"), serialize_when_none=False)
    oneOf = ListType(ModelType("Schema"), serialize_when_none=False)
    # not = ModelType("Schema")
    definitions = ModelType("Schema", serialize_when_none=False)
    title = StringType(serialize_when_none=False)
    description = StringType(serialize_when_none=False)
    default = BaseType(serialize_when_none=False)
    collectionFormat = StringType(
        choices={"csv", "ssv", "tsv", "pipes", "multi"},
        serialize_when_none=False)
Пример #2
0
class NginxContainer(Container):
    class ContainerAttrs(BaseModel):
        cert_folder = StringType(default="/etc/certs")

    id = StringType(default=lambda: str(uuid.uuid4()))
    cluster_id = StringType()
    node_id = StringType()
    name = StringType()
    type = StringType(default="nginx")
    state = StringType()
    hostname = StringType()
    cid = StringType()
    container_attrs = PolyModelType(ContainerAttrs, strict=False)
    _pyobject = StringType()

    @property
    def recovery_priority(self):
        """Gets recovery priority number used by recovery script.
        """
        return 5

    @property
    def image(self):
        return "gluunginx"

    @property
    def cert_folder(self):
        return self._resolve_container_attr("cert_folder")
class Agreement(Model):
    class Options:
        roles = RolesFromCsv('Agreement.csv', relative_to=__file__)

    id = MD5Type(required=True)
    agreementID = StringType()
    agreementNumber = StringType()
    contracts = ListType(ModelType(Contract))
    changes = ListType(PolyModelType((ChangeTaxRate, ChangeItemPriceVariation,
                                      ChangePartyWithdrawal, ChangeThirdParty),
                                     claim_function=get_change_class),
                       default=list())
    date = IsoDateTimeType()
    dateSigned = IsoDateTimeType()
    dateModified = IsoDateTimeType()
    description = StringType()
    description_en = StringType()
    description_ru = StringType()
    documents = ListType(ModelType(Document), default=list())
    items = ListType(ModelType(Item))
    features = ListType(ModelType(Feature),
                        validators=[validate_features_uniq])
    mode = StringType(choices=['test'])
    owner = StringType()
    period = ModelType(Period)
    procuringEntity = ModelType(ProcuringEntity)
    status = StringType(
        choices=['pending', 'active', 'cancelled', 'terminated'])
    tender_id = MD5Type()
    title = StringType()
    title_en = StringType()
    title_ru = StringType()
    terminationDetails = StringType()
    numberOfContracts = IntType()
Пример #4
0
class ListTemplatePayload(Model):
    """The list template is a list of 2-4 structured items with an optional global button rendered at the bottom. Each item may contain a thumbnail image, title, subtitle, and one button. You may also specify a default_action object that sets a URL that will be opened in the Messenger webview when the item is tapped.

    # Arguments
        template_type: Value must be list.
        top_element_style: Optional. Sets the format of the first list items. Messenger web client currently only renders compact.
        elements: Array of objects that describe items in the list. Minimum of 2 elements required. Maximum of 4 elements is supported.
        shareable: Optional. Set to true to enable the native share button in Messenger for the template message. Defaults to false.
        buttons: Optional. Button to display at the bottom of the list. Maximum of 1 button is supported. 

    """

    template_type = StringType(required=False,
                               default="list",
                               choices=["list"])
    top_element_style = StringType(required=False,
                                   default="compact",
                                   choices=["compact", "large"])
    elements = ListType(ModelType(Element), min_size=2, max_size=4)
    sharable = BooleanType(default=False)
    buttons = ListType(
        PolyModelType([PostbackButton, WebUrlButton],
                      claim_function=button_claim_function),
        max_size=1,
    )
Пример #5
0
class DigitalOceanProvider(Provider):
    class DriverAttrs(BaseModel):
        digitalocean_access_token = StringType()
        digitalocean_backups = BooleanType(default=False)
        digitalocean_private_networking = BooleanType(default=False)
        digitalocean_region = StringType()
        digitalocean_size = StringType(default="4gb")
        digitalocean_image = StringType(default="ubuntu-14-04-x64")
        digitalocean_ipv6 = BooleanType(default=False)

    id = StringType(default=lambda: str(uuid.uuid4()))
    name = StringType()
    driver = StringType(default="digitalocean")
    driver_attrs = PolyModelType(DriverAttrs, strict=False)
    _pyobject = StringType()

    @property
    def resource_fields(self):
        return {
            'id': self.id,
            'name': self.name,
            'driver': self.driver,
            "digitalocean_backups": self.digitalocean_backups,
            "digitalocean_private_networking": self.digitalocean_private_networking,  # noqa
            "digitalocean_region": self.digitalocean_region,
            "digitalocean_size": self.digitalocean_size,
            "digitalocean_image": self.digitalocean_image,
        }

    @property
    def digitalocean_access_token(self):
        return self._resolve_driver_attr("digitalocean_access_token")

    @property
    def digitalocean_backups(self):
        return self._resolve_driver_attr("digitalocean_backups")

    @property
    def digitalocean_private_networking(self):
        return self._resolve_driver_attr("digitalocean_private_networking")

    @property
    def digitalocean_region(self):
        return self._resolve_driver_attr("digitalocean_region")

    @property
    def digitalocean_size(self):
        return self._resolve_driver_attr("digitalocean_size")

    @property
    def digitalocean_image(self):
        return self._resolve_driver_attr("digitalocean_image")

    @property
    def digitalocean_ipv6(self):
        return self._resolve_driver_attr("digitalocean_ipv6")
Пример #6
0
class Operation(Model):
    tags = ListType(StringType(), serialize_when_none=False)
    summary = StringType(serialize_when_none=False)
    description = StringType(serialize_when_none=False)
    externalDocs = ModelType(ExternalDocumentation, serialize_when_none=False)
    operationId = StringType(serialize_when_none=False)
    consumes = ListType(MimeType(), serialize_when_none=False)
    produces = ListType(MimeType(), serialize_when_none=False)
    parameters = Parameters
    responses = DictType(PolyModelType([Response, Reference]), required=True)
Пример #7
0
class AwsProvider(Provider):
    class DriverAttrs(BaseModel):
        amazonec2_access_key = StringType()
        amazonec2_secret_key = StringType()
        amazonec2_ami = StringType(default="ami-5f709f34")
        amazonec2_instance_type = StringType(default="m4.large")
        amazonec2_region = StringType()
        amazonec2_private_address_only = BooleanType(default=False)

    id = StringType(default=lambda: str(uuid.uuid4()))
    name = StringType()
    driver = StringType(default="amazonec2")
    driver_attrs = PolyModelType(DriverAttrs, strict=False)
    _pyobject = StringType()

    @property
    def resource_fields(self):
        return {
            'id': self.id,
            'name': self.name,
            'driver': self.driver,
            "amazonec2_ami": self.amazonec2_ami,
            "amazonec2_instance_type": self.amazonec2_instance_type,
            "amazonec2_region": self.amazonec2_region,
            "amazonec2_private_address_only": self.amazonec2_private_address_only,  # noqa
        }

    @property
    def amazonec2_access_key(self):
        return self._resolve_driver_attr("amazonec2_access_key")

    @property
    def amazonec2_secret_key(self):
        return self._resolve_driver_attr("amazonec2_secret_key")

    @property
    def amazonec2_ami(self):
        return self._resolve_driver_attr("amazonec2_ami")

    @property
    def amazonec2_instance_type(self):
        return self._resolve_driver_attr("amazonec2_instance_type")

    @property
    def amazonec2_region(self):
        return self._resolve_driver_attr("amazonec2_region")

    @property
    def amazonec2_private_address_only(self):
        return self._resolve_driver_attr("amazonec2_private_address_only")
Пример #8
0
class OxtrustContainer(Container):
    class ContainerAttrs(BaseModel):
        truststore_fn = StringType(
            default='/usr/lib/jvm/java-7-openjdk-amd64'
                    '/jre/lib/security/cacerts',
        )
        ldap_binddn = StringType(default='cn=directory manager')
        cert_folder = StringType(default="/etc/certs")
        tomcat_home = StringType(default="/opt/tomcat")
        tomcat_conf_dir = StringType(default="/opt/tomcat/conf")
        tomcat_log_folder = StringType(default="/opt/tomcat/logs")

    id = StringType(default=lambda: str(uuid.uuid4()))
    cluster_id = StringType()
    node_id = StringType()
    name = StringType()
    type = StringType(default="oxtrust")
    state = StringType()
    hostname = StringType()
    cid = StringType()
    container_attrs = PolyModelType(ContainerAttrs, strict=False)
    _pyobject = StringType()

    @property
    def recovery_priority(self):
        """Gets recovery priority number used by recovery script.
        """
        return 3

    @property
    def cert_folder(self):
        return self._resolve_container_attr("cert_folder")

    @property
    def tomcat_conf_dir(self):
        return self._resolve_container_attr("tomcat_conf_dir")

    @property
    def image(self):
        return "gluuoxtrust"

    @property
    def truststore_fn(self):
        return self._resolve_container_attr("truststore_fn")
Пример #9
0
class PathItem(Model):

    get_ = ModelType(
        Operation, serialize_when_none=False,
        serialized_name="get",
        deserialize_from=["get"],
    )
    put = ModelType(Operation, serialize_when_none=False)
    post = ModelType(Operation, serialize_when_none=False)
    delete = ModelType(Operation, serialize_when_none=False)
    options = ModelType(Operation, serialize_when_none=False)
    head = ModelType(Operation, serialize_when_none=False)
    patch = ModelType(Operation, serialize_when_none=False)
    parameters = ListType(
        PolyModelType([QueryParameter, HeaderParameter,
                      FormDataParameter, PathParameter,
                       BodyParameter, Reference]),
        serialize_when_none=False
    )
Пример #10
0
class GenericProvider(Provider):
    """This class represents entity for generic provider.
    """

    class DriverAttrs(BaseModel):
        generic_ip_address = StringType()
        generic_ssh_key = StringType()
        generic_ssh_user = StringType()
        generic_ssh_port = IntType()

    id = StringType(default=lambda: str(uuid.uuid4()))
    name = StringType()
    driver = StringType(default="generic")
    driver_attrs = PolyModelType(DriverAttrs, strict=False)
    _pyobject = StringType()

    @property
    def resource_fields(self):
        return {
            'id': self.id,
            'name': self.name,
            'driver': self.driver,
            "generic_ip_address": self.generic_ip_address,
            "generic_ssh_key": self.generic_ssh_key,
            "generic_ssh_user": self.generic_ssh_user,
            "generic_ssh_port": self.generic_ssh_port,
        }

    @property
    def generic_ip_address(self):
        return self._resolve_driver_attr("generic_ip_address")

    @property
    def generic_ssh_key(self):
        return self._resolve_driver_attr("generic_ssh_key")

    @property
    def generic_ssh_user(self):
        return self._resolve_driver_attr("generic_ssh_user")

    @property
    def generic_ssh_port(self):
        return self._resolve_driver_attr("generic_ssh_port")
Пример #11
0
class Element(Model):
    """The generic template supports a maximum of 10 elements per message. At least one property must be set in addition to title.

    # Arguments
        title: The title to display in the template. 80 character limit.
        subtitle: Optional. The subtitle to display in the template. 80 character limit.
        image_url: Optional. The URL of the image to display in the template.
        default_action: Optional. The default action executed when the template is tapped. Accepts the same properties as URL button, except title.
        buttons: Optional. An array of buttons to append to the template. A maximum of 3 buttons per element is supported.

    """

    title = StringType(required=True, max_length=80)
    image_url = StringType(required=False, max_length=80)
    subtitle = StringType(required=False)
    default_action = ModelType(DefaultAction, required=False)
    buttons = ListType(
        PolyModelType([PostbackButton, WebUrlButton],
                      claim_function=button_claim_function),
        max_size=3,
    )
Пример #12
0
class Attachment(Model):
    """The following can be included in the attachment object: Rich media messages including images, audios, videos, or files and Templates including generic template, button template, receipt template, or list template.

    # Arguments
        type: Type of attachment, may be image, audio, video, file or template. For assets, max file size is 25MB.
        payload: Payload of attachment

    """

    type = StringType(required=True,
                      choices=["image", "audio", "video", "file", "template"])
    payload = PolyModelType(
        [
            RichMediaPayload,
            GenericTemplatePayload,
            ButtonTemplatePayload,
            ListTemplatePayload,
            ReceiptTemplatePayload,
        ],
        claim_function=payload_claim_function,
    )
Пример #13
0
class DiscoveryNode(Node):
    class StateAttrs(BaseModel):
        state_node_create = BooleanType(default=False)
        state_install_consul = BooleanType(default=False)
        state_complete = BooleanType(default=False)

    id = StringType(default=lambda: str(uuid.uuid4()))
    name = StringType()
    provider_id = StringType()
    type = StringType(default="discovery")
    state_attrs = PolyModelType(StateAttrs, strict=False)
    _pyobject = StringType()

    @property
    def resource_fields(self):
        return {
            "id": self.id,
            "name": self.name,
            "type": self.type,
            "provider_id": self.provider_id,
            "state_node_create": self.state_node_create,
            "state_install_consul": self.state_install_consul,
            "state_complete": self.state_complete,
        }

    @property
    def state_node_create(self):
        return self._resolve_state_attr("state_node_create")

    @property
    def state_install_consul(self):
        return self._resolve_state_attr("state_install_consul")

    @property
    def state_complete(self):
        return self._resolve_state_attr("state_complete")
Пример #14
0
class WorkerNode(Node):
    class StateAttrs(BaseModel):
        state_node_create = BooleanType(default=False)
        state_install_weave = BooleanType(default=False)
        state_weave_permission = BooleanType(default=False)
        state_weave_launch = BooleanType(default=False)
        state_recovery = BooleanType(default=False)
        state_complete = BooleanType(default=False)
        state_rng_tools = BooleanType(default=False)
        state_pull_images = BooleanType(default=False)
        state_registry_cert = BooleanType(default=False)

    id = StringType(default=lambda: str(uuid.uuid4()))
    name = StringType()
    provider_id = StringType()
    type = StringType(default="worker")
    state_attrs = PolyModelType(StateAttrs, strict=False)
    _pyobject = StringType()

    @property
    def resource_fields(self):
        return {
            "id": self.id,
            "name": self.name,
            "type": self.type,
            "provider_id": self.provider_id,
            "state_node_create": self.state_node_create,
            "state_install_weave": self.state_install_weave,
            "state_weave_permission": self.state_weave_permission,
            "state_weave_launch": self.state_weave_launch,
            "state_recovery": self.state_recovery,
            "state_complete": self.state_complete,
            "state_rng_tools": self.state_rng_tools,
            "state_pull_images": self.state_pull_images,
            # "state_registry_cert": self.state_registry_cert,
        }

    @property
    def state_node_create(self):
        return self._resolve_state_attr("state_node_create")

    @property
    def state_install_weave(self):
        return self._resolve_state_attr("state_install_weave")

    @property
    def state_weave_permission(self):
        return self._resolve_state_attr("state_weave_permission")

    @property
    def state_weave_launch(self):
        return self._resolve_state_attr("state_weave_launch")

    @property
    def state_recovery(self):
        return self._resolve_state_attr("state_recovery")

    @property
    def state_complete(self):
        return self._resolve_state_attr("state_complete")

    @property
    def state_rng_tools(self):
        return self._resolve_state_attr("state_rng_tools")

    @property
    def state_pull_images(self):
        return self._resolve_state_attr("state_pull_images")

    @property
    def state_registry_cert(self):
        return self._resolve_state_attr("state_registry_cert")
Пример #15
0
class Foo(Model):
    base = PolyModelType(A)  # accepts any subclass for import and export
    strict = PolyModelType([A, B])  # accepts [A, B] for import and export
    nfb = PolyModelType([B, C])  # no fallback since A not present
    cfn = PolyModelType([B, C], claim_function=claim_func)
Пример #16
0
 class M(Model):
     single = PolyModelType('M')
     multi = PolyModelType([A, 'M', C])
     nested = ListType(ListType(PolyModelType('M')))
Пример #17
0
class LdapContainer(Container):
    class ContainerAttrs(BaseModel):
        ldap_type = StringType(default="opendj")
        truststore_fn = StringType(
            default='/usr/lib/jvm/java-7-openjdk-amd64'
                    '/jre/lib/security/cacerts',
        )
        cert_folder = StringType(default="/etc/certs")
        opendj_cert_fn = StringType(default='/etc/certs/opendj.crt')
        ldap_binddn = StringType(default='cn=directory manager')
        ldap_port = StringType(default='1389')
        ldaps_port = StringType(default='1636')
        ldap_jmx_port = StringType(default='1689')
        ldap_admin_port = StringType(default='4444')
        ldap_replication_port = StringType(default="8989")
        ldap_base_folder = StringType(default='/opt/opendj')
        ldap_start_timeout = IntType(default=30)
        ldap_setup_command = StringType(default='/opt/opendj/setup')
        ldap_run_command = StringType(default='/opt/opendj/bin/start-ds')
        ldap_dsconfig_command = StringType(default="/opt/opendj/bin/dsconfig")
        ldap_ds_java_prop_command = StringType(
            default="/opt/opendj/bin/dsjavaproperties",
        )
        ldap_pass_fn = StringType(default='/home/ldap/.pw')
        schema_folder = StringType(
            default="/opt/opendj/template/config/schema",
        )
        org_custom_schema = StringType(
            default="/opt/opendj/config/schema/100-user.ldif",
        )

    id = StringType(default=lambda: str(uuid.uuid4()))
    cluster_id = StringType()
    node_id = StringType()
    name = StringType()
    type = StringType(default="ldap")
    state = StringType()
    hostname = StringType()
    cid = StringType()
    container_attrs = PolyModelType(ContainerAttrs, strict=False)
    _pyobject = StringType()

    @property
    def ldap_pass_fn(self):
        return self._resolve_container_attr("ldap_pass_fn")

    @property
    def schema_folder(self):
        return self._resolve_container_attr("schema_folder")

    @property
    def ldap_base_folder(self):
        return self._resolve_container_attr("ldap_base_folder")

    @property
    def ldap_port(self):
        return self._resolve_container_attr("ldap_port")

    @property
    def ldap_jmx_port(self):
        return self._resolve_container_attr("ldap_jmx_port")

    @property
    def ldap_admin_port(self):
        return self._resolve_container_attr("ldap_admin_port")

    @property
    def ldap_setup_command(self):
        return self._resolve_container_attr("ldap_setup_command")

    @property
    def ldap_ds_java_prop_command(self):
        return self._resolve_container_attr("ldap_ds_java_prop_command")

    @property
    def ldap_dsconfig_command(self):
        return self._resolve_container_attr("ldap_dsconfig_command")

    @property
    def opendj_cert_fn(self):
        return self._resolve_container_attr("opendj_cert_fn")

    @property
    def truststore_fn(self):
        return self._resolve_container_attr("truststore_fn")

    @property
    def ldap_replication_port(self):
        return self._resolve_container_attr("ldap_replication_port")

    @property
    def keytool_command(self):
        # Full path to java keytool command
        return '/usr/bin/keytool'

    @property
    def openssl_command(self):
        # Full path to openssl command
        return '/usr/bin/openssl'

    @property
    def recovery_priority(self):
        """Gets recovery priority number used by recovery script.
        """
        return 1

    @property
    def image(self):
        # currently only supports opendj
        return "gluuopendj"
Пример #18
0
class PathParameter(Items, _ParameterBase):
    IN = "path"
    _in = StringType(default=IN, serialized_name="in")
    required = BooleanType(required=True)


class BodyParameter(_ParameterBase):
    IN = "body"
    _in = StringType(default=IN, serialized_name="in")
    schema = ModelType(Schema, required=True)


def _match_data_to_parameter(cls, data):
    """ find the appropriate parameter for a parameter field """
    in_value = data["in"]
    for cls in [
            QueryParameter, HeaderParameter, FormDataParameter, PathParameter,
            BodyParameter
    ]:
        if in_value == cls.IN:
            return cls
    return None


Parameters = ListType(PolyModelType([
    QueryParameter, HeaderParameter, FormDataParameter, PathParameter,
    BodyParameter
],
                                    claim_function=_match_data_to_parameter),
                      serialize_when_none=False)
Пример #19
0
class Agreement(BaseAgreement):
    class Options:
        _data_fields = whitelist("agreementID", "agreementNumber", "changes",
                                 "contracts", "dateSigned", "description",
                                 "description_en", "description_ru",
                                 "documents", "features", "id", "items",
                                 "mode", "numberOfContracts", "owner",
                                 "period", "procuringEntity", "status",
                                 "tender_id", "terminationDetails", "title",
                                 "title_en", "title_ru")
        _create = _data_fields + whitelist("tender_token")
        _embedded = _create + whitelist(
            "dateModified",
            "agreementType",
            "revisions",
            "owner_token",
            "date",
            "transfer_token",
            "doc_id",
        )
        roles = {
            "view":
            _data_fields + whitelist("dateModified"),
            "create":
            _create,
            "edit_terminated":
            whitelist(),
            "edit_active":
            whitelist("documents", "status", "terminationDetails"),
            "Administrator":
            whitelist("documents", "mode", "procuringEntity", "status",
                      "terminationDetails"),
            "embedded":
            _embedded,
            "default":
            _embedded - whitelist("doc_id") +
            whitelist("_id", "_rev", "doc_type"),
            "plain":
            _embedded - whitelist("revisions", "dateModified"),
        }

    agreementNumber = StringType()
    agreementType = StringType(default="cfaua")
    period = ModelType(Period)
    dateSigned = IsoDateTimeType()
    title_en = StringType()
    title_ru = StringType()
    description_en = StringType()
    description_ru = StringType()
    changes = ListType(
        PolyModelType(
            (ChangeTaxRate, ChangeItemPriceVariation, ChangePartyWithdrawal,
             ChangeThirdParty),
            claim_function=get_change_class,
        ),
        default=list(),
    )
    documents = ListType(ModelType(Document, required=True), default=list())
    contracts = ListType(ModelType(Contract, required=True), default=list())
    features = ListType(ModelType(Feature, required=True),
                        validators=[validate_features_uniq])
    items = ListType(ModelType(Item, required=True))
    procuringEntity = ModelType(ProcuringEntity, required=True)
    terminationDetails = StringType()

    create_accreditations = (ACCR_3, ACCR_5)  # TODO

    def __acl__(self):
        acl = super(Agreement, self).__acl__()
        acl.append((Allow, "{}_{}".format(self.owner, self.owner_token),
                    "upload_agreement_documents"))
        return acl

    def get_role(self):
        root = self.__parent__
        request = root.request
        if request.authenticated_role == "Administrator":
            role = "Administrator"
        else:
            role = "edit_{}".format(request.context.status)
        return role

    def get_active_contracts_count(self):
        return len([c.id for c in self.contracts if c.status == "active"])