Exemplo n.º 1
0
def add_subscription(session, cluster_id, ctx):
    """ Adds an object representing a subscription regardless of the underlying protocol.
    """
    # Common
    ps_sub = PubSubSubscription()

    ps_sub.cluster_id = ctx.cluster_id
    ps_sub.server_id = ctx.server_id
    ps_sub.topic_id = ctx.topic.id
    ps_sub.is_internal = ctx.is_internal
    ps_sub.is_staging_enabled = ctx.is_staging_enabled
    ps_sub.creation_time = ctx.creation_time
    ps_sub.sub_key = ctx.sub_key
    ps_sub.pattern_matched = ctx.pattern_matched
    ps_sub.has_gd = ctx.has_gd
    ps_sub.active_status = ctx.active_status
    ps_sub.endpoint_type = ctx.endpoint_type
    ps_sub.endpoint_id = ctx.endpoint_id
    ps_sub.delivery_method = ctx.delivery_method
    ps_sub.delivery_data_format = ctx.delivery_data_format
    ps_sub.delivery_batch_size = ctx.delivery_batch_size
    ps_sub.wrap_one_msg_in_list = ctx.wrap_one_msg_in_list
    ps_sub.delivery_max_retry = ctx.delivery_max_retry
    ps_sub.delivery_err_should_block = ctx.delivery_err_should_block
    ps_sub.wait_sock_err = ctx.wait_sock_err
    ps_sub.wait_non_sock_err = ctx.wait_non_sock_err
    ps_sub.ext_client_id = ctx.ext_client_id

    # AMQP
    ps_sub.amqp_exchange = ctx.amqp_exchange
    ps_sub.amqp_routing_key = ctx.amqp_routing_key

    # Local files
    ps_sub.files_directory_list = ctx.files_directory_list

    # FTP
    ps_sub.ftp_directory_list = ctx.ftp_directory_list

    # REST/SOAP
    ps_sub.security_id = ctx.security_id
    ps_sub.out_http_soap_id = ctx.out_http_soap_id
    ps_sub.out_http_method = ctx.out_http_method

    # Services
    ps_sub.service_id = ctx.service_id

    # SMS - Twilio
    ps_sub.sms_twilio_from = ctx.sms_twilio_from
    ps_sub.sms_twilio_to_list = ctx.sms_twilio_to_list
    ps_sub.smtp_is_html = ctx.smtp_is_html
    ps_sub.smtp_subject = ctx.smtp_subject
    ps_sub.smtp_from = ctx.smtp_from
    ps_sub.smtp_to_list = ctx.smtp_to_list
    ps_sub.smtp_body = ctx.smtp_body

    # WebSockets
    ps_sub.ws_channel_id = ctx.ws_channel_id
    ps_sub.ws_channel_name = ctx.ws_channel_name
    ps_sub.ws_pub_client_id = ctx.ws_pub_client_id
    ps_sub.sql_ws_client_id = ctx.sql_ws_client_id

    session.add(ps_sub)

    return ps_sub
Exemplo n.º 2
0
    def add_pubsub_sec_endpoints(self, session, cluster):

        from zato.common.api import CONNECTION, DATA_FORMAT, PUBSUB, URL_TYPE
        from zato.common.json_internal import dumps
        from zato.common.odb.model import HTTPBasicAuth, HTTPSOAP, PubSubEndpoint, PubSubSubscription, PubSubTopic, \
             Service
        from zato.common.pubsub import new_sub_key
        from zato.common.util.time_ import utcnow_as_ms

        sec_demo = HTTPBasicAuth(
            None, 'zato.pubsub.demo.secdef', True, 'zato.pubsub.demo', 'Zato pub/sub demo', new_password(), cluster)
        session.add(sec_demo)

        sec_default_internal = HTTPBasicAuth(None, 'zato.pubsub.internal.secdef', True, 'zato.pubsub.internal',
            'Zato pub/sub internal', new_password(), cluster)
        session.add(sec_default_internal)

        impl_name1 = 'zato.server.service.internal.pubsub.pubapi.TopicService'
        impl_name2 = 'zato.server.service.internal.pubsub.pubapi.SubscribeService'
        impl_name3 = 'zato.server.service.internal.pubsub.pubapi.MessageService'
        impl_demo = 'zato.server.service.internal.helpers.JSONRawRequestLogger'

        service_topic = Service(None, 'zato.pubsub.pubapi.topic-service', True, impl_name1, True, cluster)
        service_sub = Service(None, 'zato.pubsub.pubapi.subscribe-service', True, impl_name2, True, cluster)
        service_msg = Service(None, 'zato.pubsub.pubapi.message-service', True, impl_name3, True, cluster)
        service_demo = Service(None, 'zato.pubsub.helpers.json-raw-request-logger', True, impl_demo, True, cluster)

        # Opaque data that lets clients use topic contain slash characters
        opaque = dumps({'match_slash':True})

        chan_topic = HTTPSOAP(None, 'zato.pubsub.topic.topic_name', True, True, CONNECTION.CHANNEL,
            URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/topic/{topic_name}',
            None, '', None, DATA_FORMAT.JSON, security=None, service=service_topic, opaque=opaque,
            cluster=cluster)

        chan_sub = HTTPSOAP(None, 'zato.pubsub.subscribe.topic.topic_name', True, True, CONNECTION.CHANNEL,
            URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/subscribe/topic/{topic_name}',
            None, '', None, DATA_FORMAT.JSON, security=None, service=service_sub, opaque=opaque,
            cluster=cluster)

        chan_msg = HTTPSOAP(None, 'zato.pubsub.msg.msg_id', True, True, CONNECTION.CHANNEL,
            URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/msg/{msg_id}',
            None, '', None, DATA_FORMAT.JSON, security=None, service=service_msg, opaque=opaque,
            cluster=cluster)

        chan_demo = HTTPSOAP(None, 'pubsub.demo.sample.channel', True, True, CONNECTION.CHANNEL,
            URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/zato.demo.sample',
            None, '', None, DATA_FORMAT.JSON, security=sec_demo, service=service_demo, opaque=opaque,
            cluster=cluster)

        outconn_demo = HTTPSOAP(None, 'pubsub.demo.sample.outconn', True, True, CONNECTION.OUTGOING,
            URL_TYPE.PLAIN_HTTP, 'http://localhost:11223', '/zato/pubsub/zato.demo.sample',
            None, '', None, DATA_FORMAT.JSON, security=sec_demo, opaque=opaque,
            cluster=cluster)

        endpoint_default_internal = PubSubEndpoint()
        endpoint_default_internal.name = PUBSUB.DEFAULT.INTERNAL_ENDPOINT_NAME
        endpoint_default_internal.is_internal = True
        endpoint_default_internal.role = PUBSUB.ROLE.PUBLISHER_SUBSCRIBER.id
        endpoint_default_internal.topic_patterns = 'pub=/*\nsub=/*'
        endpoint_default_internal.security = sec_default_internal
        endpoint_default_internal.cluster = cluster
        endpoint_default_internal.endpoint_type = PUBSUB.ENDPOINT_TYPE.INTERNAL.id

        endpoint_demo = PubSubEndpoint()
        endpoint_demo.name = 'zato.pubsub.demo.endpoint'
        endpoint_demo.is_internal = True
        endpoint_demo.role = PUBSUB.ROLE.PUBLISHER_SUBSCRIBER.id
        endpoint_demo.topic_patterns = 'pub=/zato/demo/*\nsub=/zato/demo/*'
        endpoint_demo.security = sec_demo
        endpoint_demo.cluster = cluster
        endpoint_demo.endpoint_type = PUBSUB.ENDPOINT_TYPE.REST.id

        topic = PubSubTopic()
        topic.name = '/zato/demo/sample'
        topic.is_active = True
        topic.is_api_sub_allowed = True
        topic.is_internal = True
        topic.max_depth = 100
        topic.has_gd = False
        topic.cluster = cluster

        sub = PubSubSubscription()
        sub.creation_time = utcnow_as_ms()
        sub.topic = topic
        sub.endpoint = endpoint_demo
        sub.sub_key = new_sub_key(endpoint_demo.endpoint_type)
        sub.has_gd = False
        sub.sub_pattern_matched = 'sub=/zato/demo/*'
        sub.active_status = PUBSUB.QUEUE_ACTIVE_STATUS.FULLY_ENABLED.id
        sub.cluster = cluster
        sub.wrap_one_msg_in_list = False
        sub.delivery_err_should_block = False
        sub.out_http_soap = outconn_demo

        session.add(endpoint_default_internal)
        session.add(endpoint_demo)
        session.add(topic)
        session.add(sub)

        session.add(service_topic)
        session.add(service_sub)
        session.add(service_msg)

        session.add(chan_topic)
        session.add(chan_sub)
        session.add(chan_msg)

        session.add(chan_demo)
        session.add(outconn_demo)