Exemplo n.º 1
0
def update_trader_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_t_id = validate.is_trader(request.form["t_id"])
    form_t_name = validate.sql_escape(request.form["t_name"])
    form_contact_name = validate.sql_escape(request.form["contact_name"])
    form_phone = validate.sql_escape(request.form["phone"])
    form_address = validate.sql_escape(request.form["address"])
    form_notes = validate.sql_escape(request.form["notes"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    form_is_supplier = validate.is_boolean(request.form["is_supplier"])
    form_is_costumer = validate.is_boolean(request.form["is_costumer"])

    is_success = traders.trader_update(form_t_id, form_t_name,
                                       form_contact_name, form_phone,
                                       form_address, form_notes,
                                       form_is_active, form_is_supplier,
                                       form_is_costumer)
    if (is_success):
        return render_template('index.html',
                               page_title="Edit trader: ",
                               message="trader details updated! ",
                               content=traders.traders_list())
    else:
        return render_template('index.html',
                               page_title="Edit trader: ",
                               warning="Error - update failed! ",
                               content=traders.trader_edit(form_t_id))
Exemplo n.º 2
0
def add_trader_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    if (request.method == 'POST'
        ):  #Adding form was sent - then add the new trader
        form_t_name = validate.sql_escape(request.form["t_name"])
        form_contact_name = validate.sql_escape(request.form["contact_name"])
        form_phone = validate.sql_escape(request.form["phone"])
        form_address = validate.sql_escape(request.form["address"])
        form_notes = validate.sql_escape(request.form["notes"])
        form_is_active = validate.is_boolean(request.form["is_active"])
        form_is_supplier = validate.is_boolean(request.form["is_supplier"])
        form_is_costumer = validate.is_boolean(request.form["is_costumer"])

        new_trader_id = traders.add_trader(form_t_name, form_contact_name,
                                           form_phone, form_address,
                                           form_notes, form_is_active,
                                           form_is_supplier, form_is_costumer)
        return redirect('/traders/edit/' + str(new_trader_id))

    #If the request is get - then print the add new trader form
    return render_template('index.html',
                           page_title="Add new trader: ",
                           content=traders.add_trader_form())
Exemplo n.º 3
0
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster,
                'zato:definition.jms_wmq.get-list', zato_message)
        
        if zato_path('data.definition_list.definition').get_from(zato_message) is not None:
            
            for definition_elem in zato_message.data.definition_list.definition:

                id = definition_elem.id.text
                name = definition_elem.name.text
                host = definition_elem.host.text
                port = definition_elem.port.text
                queue_manager = definition_elem.queue_manager.text
                channel = definition_elem.channel.text
                cache_open_send_queues = is_boolean(definition_elem.cache_open_send_queues.text)
                cache_open_receive_queues = is_boolean(definition_elem.cache_open_receive_queues.text)
                use_shared_connections = is_boolean(definition_elem.use_shared_connections.text)
                ssl = is_boolean(definition_elem.ssl.text)
                ssl_cipher_spec = definition_elem.ssl_cipher_spec.text
                ssl_key_repository = definition_elem.ssl_key_repository.text
                needs_mcd = is_boolean(definition_elem.needs_mcd.text)
                max_chars_printed = definition_elem.max_chars_printed.text
                
                def_jms_wmq = ConnDefWMQ(id, name, host, port, queue_manager, channel,
                    cache_open_send_queues, cache_open_receive_queues, use_shared_connections, 
                    ssl, ssl_cipher_spec, ssl_key_repository, needs_mcd, max_chars_printed)
                
                items.append(def_jms_wmq)
                

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/definition/jms_wmq.html', return_data,
                              context_instance=RequestContext(req))
Exemplo n.º 4
0
    def get_data(self, session):

        return_internal = is_boolean(self.server.fs_server_config.misc.return_internal_objects)
        internal_del = is_boolean(self.server.fs_server_config.misc.internal_services_may_be_deleted)

        out = []
        sl = service_list(session, self.request.input.cluster_id, return_internal, False)

        name_filter = self.request.input.get('name_filter')
        if name_filter:
            name_filter = [elem.strip().lower() for elem in name_filter.strip().split() if elem]
        else:
            name_filter = [_no_such_service_name] # So it matches nothing

        for item in sl:
            if self.request.input.name_filter != '*':
                skip_item = False
                for filter in name_filter:
                    if not filter in item.name.lower():
                        skip_item = True
                    
                if skip_item:
                    continue
            
            item.may_be_deleted = internal_del if item.is_internal else True
            item.usage = self.server.kvdb.conn.get('{}{}'.format(KVDB.SERVICE_USAGE, item.name)) or 0
            
            out.append(item)
        
        return out
Exemplo n.º 5
0
    def get_data(self, session):

        return_internal = is_boolean(
            self.server.fs_server_config.misc.return_internal_objects)
        internal_del = is_boolean(
            self.server.fs_server_config.misc.internal_services_may_be_deleted)

        out = []
        search_result = self._search(service_list, session,
                                     self.request.input.cluster_id,
                                     return_internal, False)
        for item in elems_with_opaque(search_result):
            item.may_be_deleted = internal_del if item.is_internal else True
            item.usage = self.server.kvdb.conn.get('{}{}'.format(
                KVDB.SERVICE_USAGE, item.name)) or 0

            # Attach JSON Schema validation configuration
            json_schema_config = get_service_config(item, self.server)

            item.is_json_schema_enabled = json_schema_config[
                'is_json_schema_enabled']
            item.needs_json_schema_err_details = json_schema_config[
                'needs_json_schema_err_details']

            out.append(item)

        return out
Exemplo n.º 6
0
Arquivo: ftp.py Projeto: brtsz/zato
    def handle(self, *args, **kwargs):

        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')

            core_params = ['id', 'cluster_id', 'name', 'is_active', 'host', 'port', 'dircache']
            core_params = _get_params(payload, core_params, 'data.')
            
            optional_params = ['user', 'acct', 'timeout']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)

            id = core_params['id']
            name = core_params['name']
            cluster_id = core_params['cluster_id']

            existing_one = session.query(OutgoingFTP.id).\
                filter(OutgoingFTP.cluster_id==cluster_id).\
                filter(OutgoingFTP.name==name).\
                filter(OutgoingFTP.id!=core_params['id']).\
                first()

            if existing_one:
                raise Exception('An outgoing FTP connection [{0}] already exists on this cluster'.format(name))

            xml_item = Element('out_ftp')

            try:

                core_params['id'] = int(core_params['id'])
                core_params['is_active'] = is_boolean(core_params['is_active'])
                core_params['dircache'] = is_boolean(core_params['dircache'])

                item = session.query(OutgoingFTP).filter_by(id=id).one()
                old_name = item.name
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.cluster_id = core_params['cluster_id']
                item.dircache = core_params['dircache']
                item.host = core_params['host']
                item.port = core_params['port']
                item.user = optional_params['user']
                item.acct = optional_params['acct']
                item.timeout = optional_params['timeout']

                session.add(item)
                session.commit()

                xml_item.id = item.id
                self.update_facade(core_params, optional_params, old_name)

                return ZATO_OK, etree.tostring(xml_item)

            except Exception, e:
                msg = 'Could not update the outgoing FTP connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 7
0
 def handle(self, *args, **kwargs):
     
     with closing(self.server.odb.session()) as session:
         payload = kwargs.get('payload')
         request_params = ['cluster_id', 'name', 'host', 'port', 'queue_manager', 
             'channel', 'cache_open_send_queues', 'cache_open_receive_queues',
             'use_shared_connections', 'ssl', 'ssl_cipher_spec', 
             'ssl_key_repository', 'needs_mcd', 'max_chars_printed']
         
         params = _get_params(payload, request_params, 'data.')
         name = params['name']
         params['port'] = int(params['port'])
         params['cache_open_send_queues'] = is_boolean(params['cache_open_send_queues'])
         params['cache_open_receive_queues'] = is_boolean(params['cache_open_receive_queues'])
         params['use_shared_connections'] = is_boolean(params['use_shared_connections'])
         params['ssl'] = is_boolean(params['ssl'])
         params['needs_mcd'] = is_boolean(params['needs_mcd'])
         params['max_chars_printed'] = int(params['max_chars_printed'])
         
         cluster_id = params['cluster_id']
         cluster = session.query(Cluster).filter_by(id=cluster_id).first()
         
         # Let's see if we already have an object of that name before committing
         # any stuff into the database.
         existing_one = session.query(ConnDefWMQ).\
             filter(ConnDefWMQ.cluster_id==Cluster.id).\
             filter(ConnDefWMQ.name==name).\
             first()
         
         if existing_one:
             raise Exception('JMS WebSphere MQ definition [{0}] already exists on this cluster'.format(name))
         
         created_elem = Element('def_jms_wmq')
         
         try:
             def_ = ConnDefWMQ(None, name, params['host'], params['port'], params['queue_manager'], 
                 params['channel'], params['cache_open_send_queues'], params['cache_open_receive_queues'],
                 params['use_shared_connections'], params['ssl'], params['ssl_cipher_spec'], 
                 params['ssl_key_repository'], params['needs_mcd'], params['max_chars_printed'],
                 cluster_id)
             session.add(def_)
             session.commit()
             
             created_elem.id = def_.id
             
             return ZATO_OK, etree.tostring(created_elem)
             
         except Exception, e:
             msg = "Could not create a JMS WebSphere MQ definition, e=[{e}]".format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise 
Exemplo n.º 8
0
Arquivo: ftp.py Projeto: brtsz/zato
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by("name").all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get("cluster")
    items = []

    create_form = CreateForm()
    edit_form = EditForm(prefix="edit")
    change_password_form = ChangePasswordForm()

    if cluster_id and req.method == "GET":

        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        zato_message = Element("{%s}zato_message" % zato_namespace)
        zato_message.data = Element("data")
        zato_message.data.cluster_id = cluster_id

        _, zato_message, soap_response = invoke_admin_service(cluster, "zato:outgoing.ftp.get-list", zato_message)

        if zato_path("data.item_list.item").get_from(zato_message) is not None:

            for msg_item in zato_message.data.item_list.item:

                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)

                host = msg_item.host.text if msg_item.host else ""
                user = msg_item.user.text if msg_item.user else ""
                acct = msg_item.acct.text if msg_item.acct else ""
                timeout = msg_item.timeout.text if msg_item.timeout else ""
                port = msg_item.port.text if msg_item.port else ""
                dircache = is_boolean(msg_item.dircache.text)

                item = OutgoingFTP(id, name, is_active, host, user, None, acct, timeout, port, dircache)
                items.append(item)

    return_data = {
        "zato_clusters": zato_clusters,
        "cluster_id": cluster_id,
        "choose_cluster_form": choose_cluster_form,
        "items": items,
        "create_form": create_form,
        "edit_form": edit_form,
        "change_password_form": change_password_form,
    }

    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, "Returning render_to_response [{0}]".format(return_data))

    return render_to_response("zato/outgoing/ftp.html", return_data, context_instance=RequestContext(req))
Exemplo n.º 9
0
Arquivo: service.py Projeto: xbx/zato
    def get_data(self, session):
        out = []
        sl = service_list(session, self.request.input.cluster_id, False)

        internal_del = is_boolean(
            self.server.fs_server_config.misc.internal_services_may_be_deleted)
        name_filter = [
            elem.strip().lower() for elem in self.request.input.get(
                'name_filter', '').strip().split()
        ]
        if not name_filter:
            name_filter = [_no_such_service_name]  # So it matches nothing

        for item in sl:
            if self.request.input.name_filter != '*':
                skip_item = False
                for filter in name_filter:
                    if not filter in item.name.lower():
                        skip_item = True

                if skip_item:
                    continue

            item.may_be_deleted = internal_del if item.is_internal else True
            item.usage = self.server.kvdb.conn.get('{}{}'.format(
                KVDB.SERVICE_USAGE, item.name)) or 0

            out.append(item)

        return out
Exemplo n.º 10
0
    def handle(self):
        input = self.request.input
        with closing(self.odb.session()) as session:
            try:
                service = session.query(Service).filter_by(id=input.id).one()
                service.is_active = input.is_active
                service.slow_threshold = input.slow_threshold

                session.add(service)
                session.commit()

                input.action = SERVICE.EDIT.value
                input.impl_name = service.impl_name
                self.broker_client.publish(input)

                self.response.payload = service

                internal_del = is_boolean(self.server.fs_server_config.misc.
                                          internal_services_may_be_deleted)
                self.response.payload.may_be_deleted = internal_del if service.is_internal else True

            except Exception, e:
                msg = 'Could not update the service, e:[{e}]'.format(
                    e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 11
0
def parse_extra_into_dict(lines):
    """ Creates a dictionary out of key=value lines.
    """
    _extra = {}

    if lines:
        extra = ';'.join(lines.splitlines())

        for line in extra.split(';'):
            original_line = line
            if line:
                line = line.split('=')
                if not len(line) == 2:
                    raise ValueError('Each line must be a single key=value entry, not [{}]'.format(original_line))

                key, value = line
                value = value.strip()

                try:
                    value = is_boolean(value)
                except VdtTypeError:
                    # It's cool, not a boolean
                    pass

                try:
                    value = is_integer(value)
                except VdtTypeError:
                    # OK, not an integer
                    pass

                _extra[key.strip()] = value

    return _extra
Exemplo n.º 12
0
def parse_extra_into_dict(lines, convert_bool=True):
    """ Creates a dictionary out of key=value lines.
    """
    _extra = {}

    if lines:
        extra = ';'.join(lines.splitlines())

        for line in extra.split(';'):
            original_line = line
            if line:
                line = line.split('=')
                if not len(line) == 2:
                    raise ValueError('Each line must be a single key=value entry, not [{}]'.format(original_line))

                key, value = line
                value = value.strip()

                if convert_bool:
                    try:
                        value = is_boolean(value)
                    except VdtTypeError:
                        # It's cool, not a boolean
                        pass

                try:
                    value = is_integer(value)
                except VdtTypeError:
                    # OK, not an integer
                    pass

                _extra[key.strip()] = value

    return _extra
Exemplo n.º 13
0
    def handle(self):
        with closing(self.odb.session()) as session:
            try:
                service = session.query(Service).\
                    filter(Service.id==self.request.input.id).\
                    one()

                internal_del = is_boolean(self.server.fs_server_config.misc.internal_services_may_be_deleted)
                
                if service.is_internal and not internal_del:
                    msg = "Can't delete service:[{}], it's an internal one and internal_services_may_be_deleted is not True".format(
                        service.name)
                    raise ZatoException(self.cid, msg)
                
                # This will also cascade to delete the related DeployedService objects
                session.delete(service)
                session.commit()

                msg = {'action': SERVICE.DELETE.value, 'id': self.request.input.id, 'impl_name':service.impl_name, 
                       'is_internal':service.is_internal}
                self.broker_client.publish(msg)
                
            except Exception, e:
                session.rollback()
                msg = 'Could not delete the service, e:[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                
                raise
Exemplo n.º 14
0
 def handle(self):
     input = self.request.input
     with closing(self.odb.session()) as session:
         try:
             service = session.query(Service).filter_by(id=input.id).one()
             service.is_active = input.is_active
             service.slow_threshold = input.slow_threshold
             
             session.add(service)
             session.commit()
             
             input.action = SERVICE.EDIT.value
             input.impl_name = service.impl_name
             self.broker_client.publish(input)
             
             self.response.payload = service
             
             internal_del = is_boolean(self.server.fs_server_config.misc.internal_services_may_be_deleted)
             self.response.payload.may_be_deleted = internal_del if service.is_internal else True
             
         except Exception, e:
             msg = 'Could not update the service, e:[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise         
Exemplo n.º 15
0
    def handle(self):
        with closing(self.odb.session()) as session:
            service = self.get_data(session)
            internal_del = is_boolean(self.server.fs_server_config.misc.
                                      internal_services_may_be_deleted)

            self.response.payload.id = service.id
            self.response.payload.name = service.name
            self.response.payload.is_active = service.is_active
            self.response.payload.impl_name = service.impl_name
            self.response.payload.is_internal = service.is_internal
            self.response.payload.slow_threshold = service.slow_threshold
            self.response.payload.may_be_deleted = internal_del if service.is_internal else True
            self.response.payload.usage = self.server.kvdb.conn.get(
                '{}{}'.format(KVDB.SERVICE_USAGE, service.name)) or 0

            time_key = '{}{}'.format(KVDB.SERVICE_TIME_BASIC, service.name)
            self.response.payload.time_last = self.server.kvdb.conn.hget(
                time_key, 'last')

            for name in ('min_all_time', 'max_all_time', 'mean_all_time'):
                setattr(self.response.payload, 'time_{}'.format(name),
                        float(self.server.kvdb.conn.hget(time_key, name) or 0))

            self.response.payload.time_min_all_time = int(
                self.response.payload.time_min_all_time)
            self.response.payload.time_max_all_time = int(
                self.response.payload.time_max_all_time)
            self.response.payload.time_mean_all_time = round(
                self.response.payload.time_mean_all_time, 1)
Exemplo n.º 16
0
Arquivo: amqp.py Projeto: brtsz/zato
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        def_ids = _get_def_ids(cluster)
        create_form.set_def_id(def_ids)
        edit_form.set_def_id(def_ids)

        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster, 'zato:outgoing.amqp.get-list', zato_message)
        
        if zato_path('data.item_list.item').get_from(zato_message) is not None:
            
            for msg_item in zato_message.data.item_list.item:
                
                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                delivery_mode = int(msg_item.delivery_mode.text)
                priority = msg_item.priority.text
                content_type = msg_item.content_type.text
                content_encoding = msg_item.content_encoding.text
                expiration = msg_item.expiration.text
                user_id = msg_item.user_id.text
                app_id = msg_item.app_id.text
                delivery_mode_text = delivery_friendly_name[delivery_mode]
                def_name = msg_item.def_name.text
                def_id = msg_item.def_id.text
                
                item =  OutgoingAMQP(id, name, is_active, delivery_mode, priority,
                    content_type, content_encoding, expiration, user_id, app_id,
                    def_id, delivery_mode_text, def_name)
                items.append(item)

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/outgoing/amqp.html', return_data,
                              context_instance=RequestContext(req))
Exemplo n.º 17
0
    def handle(self):
        with closing(self.odb.session()) as session:
            try:
                service = session.query(Service).\
                    filter(Service.id==self.request.input.id).\
                    one() # type: Service

                internal_del = is_boolean(self.server.fs_server_config.misc.
                                          internal_services_may_be_deleted)

                if service.is_internal and not internal_del:
                    msg = "Can't delete service:[{}], it's an internal one and internal_services_may_be_deleted is not True".format(
                        service.name)
                    raise ZatoException(self.cid, msg)

                # This will also cascade to delete the related DeployedService objects
                session.delete(service)
                session.commit()

                msg = {
                    'action': SERVICE.DELETE.value,
                    'id': self.request.input.id,
                    'name': service.name,
                    'impl_name': service.impl_name,
                    'is_internal': service.is_internal,
                }
                self.broker_client.publish(msg)

            except Exception:
                session.rollback()
                msg = 'Service could not be deleted, e:`{}`'.format(
                    format_exc())
                self.logger.error(msg)

                raise
Exemplo n.º 18
0
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')
            
            core_params = ['cluster_id', 'name', 'is_active', 'def_id', 'delivery_mode', 'priority']
            core_params = _get_params(payload, core_params, 'data.')
            
            optional_params = ['expiration']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)
        
            priority = int(core_params['priority'])
        
            if not(priority >= 0 and priority <= 9):
                msg = 'Priority should be between 0 and 9, not [{0}]'.format(repr(priority))
                raise ValueError(msg)
            
            name = core_params['name']
            cluster_id = core_params['cluster_id']
            core_params['def_id'] = int(core_params['def_id'])
            
            existing_one = session.query(OutgoingWMQ.id).\
                filter(ConnDefWMQ.cluster_id==cluster_id).\
                filter(OutgoingWMQ.def_id==ConnDefWMQ.id).\
                filter(OutgoingWMQ.name==name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing JMS WebSphere MQ connection [{0}] already exists on this cluster'.format(name))
            
            created_elem = Element('out_jms_wmq')
            
            try:

                core_params['delivery_mode'] = int(core_params['delivery_mode'])
                core_params['priority'] = int(core_params['priority'])
                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = OutgoingWMQ()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.def_id = core_params['def_id']
                item.delivery_mode = core_params['delivery_mode']
                item.priority = core_params['priority']
                item.expiration = optional_params['expiration']
                
                session.add(item)
                session.commit()
                
                created_elem.id = item.id
                start_connector(self.server.repo_location, item.id, item.def_id)
                
                return ZATO_OK, etree.tostring(created_elem)
                
            except Exception, e:
                msg = 'Could not create an outgoing JMS WebSphere MQ connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise 
Exemplo n.º 19
0
def details(req, service_id):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    service = None
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.id = service_id
        zato_message.data.cluster_id = cluster_id
        
        
        _, zato_message, soap_response  = invoke_admin_service(cluster, 'zato:service.get-by-id', zato_message)
        
        if zato_path('data.item').get_from(zato_message) is not None:
            
            msg_item = zato_message.data.item
                
            id = msg_item.id.text
            name = msg_item.name.text
            is_active = is_boolean(msg_item.is_active.text)
            impl_name = msg_item.impl_name.text
            is_internal = is_boolean(msg_item.is_internal.text)
            usage_count = msg_item.usage_count.text
            
            service = Service(id, name, is_active, impl_name, is_internal, None, usage_count)

    return_data = {'zato_clusters':zato_clusters,
        'service': service,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/service/details.html', return_data, context_instance=RequestContext(req))
Exemplo n.º 20
0
    def get_data(self, session):

        return_internal = is_boolean(
            self.server.fs_server_config.misc.return_internal_objects)
        internal_del = is_boolean(
            self.server.fs_server_config.misc.internal_services_may_be_deleted)

        out = []
        for item in self._search(service_list, session,
                                 self.request.input.cluster_id,
                                 return_internal, False):
            item.may_be_deleted = internal_del if item.is_internal else True
            item.usage = self.server.kvdb.conn.get('{}{}'.format(
                KVDB.SERVICE_USAGE, item.name)) or 0

            out.append(item)

        return out
Exemplo n.º 21
0
Arquivo: wss.py Projeto: brtsz/zato
def index(req):

    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')
    change_password_form = ChangePasswordForm()

    if cluster_id and req.method == 'GET':
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()

        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id

        _ignored, zato_message, soap_response  = invoke_admin_service(cluster,
                'zato:security.wss.get-list', zato_message)

        if zato_path('data.definition_list.definition').get_from(zato_message) is not None:
            for definition_elem in zato_message.data.definition_list.definition:

                id = definition_elem.id.text
                name = definition_elem.name.text
                is_active = is_boolean(definition_elem.is_active.text)
                username = definition_elem.username.text
                password_type = ZATO_WSS_PASSWORD_TYPES[definition_elem.password_type.text]
                password_type_raw = definition_elem.password_type.text
                reject_empty_nonce_ts = definition_elem.reject_empty_nonce_ts
                reject_stale_username = definition_elem.reject_stale_username
                expiry_limit = definition_elem.expiry_limit
                nonce_freshness = definition_elem.nonce_freshness

                wss = WSSDefinition(id, name, is_active, username, None,
                        password_type, reject_empty_nonce_ts, reject_stale_username,
                        expiry_limit, nonce_freshness, password_type_raw=password_type_raw)

                items.append(wss)

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form': create_form,
        'edit_form': edit_form,
        'change_password_form': change_password_form
        }

    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [%s]' % return_data)

    return render_to_response('zato/security/wss.html', return_data,
                              context_instance=RequestContext(req))
Exemplo n.º 22
0
    def handle(self, *args, **kwargs):

        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')

            core_params = ['id', 'cluster_id', 'name', 'is_active', 'url_path', 'connection', 'transport']
            core_params = _get_params(payload, core_params, 'data.')

            optional_params = ['method', 'soap_action', 'soap_version']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)

            id = core_params['id']
            name = core_params['name']
            cluster_id = core_params['cluster_id']

            existing_one = session.query(HTTPSOAP.id).\
                filter(HTTPSOAP.cluster_id==cluster_id).\
                filter(HTTPSOAP.id!=id).\
                filter(HTTPSOAP.name==name).\
                first()

            if existing_one:
                raise Exception('An object of that name [{0}] already exists on this cluster'.format(name))

            xml_item = Element('http_soap')

            try:

                core_params['id'] = int(core_params['id'])
                core_params['is_active'] = is_boolean(core_params['is_active'])

                item = session.query(HTTPSOAP).filter_by(id=id).one()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.url_path = core_params['url_path']
                item.connection = core_params['connection']
                item.transport = core_params['transport']
                item.cluster_id = core_params['cluster_id']
                item.method = optional_params.get('method')
                item.soap_action = optional_params.get('soap_action')
                item.soap_version = optional_params.get('soap_version')

                session.add(item)
                session.commit()

                xml_item.id = item.id

                return ZATO_OK, etree.tostring(xml_item)

            except Exception, e:
                msg = 'Could not update the object, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 23
0
Arquivo: amqp.py Projeto: brtsz/zato
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by("name").all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get("cluster")
    items = []

    create_form = CreateForm()
    edit_form = EditForm(prefix="edit")

    if cluster_id and req.method == "GET":

        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()

        def_ids = _get_def_ids(cluster)
        create_form.set_def_id(def_ids)
        edit_form.set_def_id(def_ids)

        zato_message = Element("{%s}zato_message" % zato_namespace)
        zato_message.data = Element("data")
        zato_message.data.cluster_id = cluster_id

        _, zato_message, soap_response = invoke_admin_service(cluster, "zato:channel.amqp.get-list", zato_message)

        if zato_path("data.item_list.item").get_from(zato_message) is not None:

            for msg_item in zato_message.data.item_list.item:

                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                queue = msg_item.queue.text
                consumer_tag_prefix = msg_item.consumer_tag_prefix.text
                def_name = msg_item.def_name.text
                def_id = msg_item.def_id.text
                service_name = msg_item.service_name.text

                item = ChannelAMQP(id, name, is_active, queue, consumer_tag_prefix, def_id, def_name, service_name)
                items.append(item)

    return_data = {
        "zato_clusters": zato_clusters,
        "cluster_id": cluster_id,
        "choose_cluster_form": choose_cluster_form,
        "items": items,
        "create_form": create_form,
        "edit_form": edit_form,
    }

    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, "Returning render_to_response [{0}]".format(return_data))

    return render_to_response("zato/channel/amqp.html", return_data, context_instance=RequestContext(req))
Exemplo n.º 24
0
def _edit_create_response(verb, service_elem):

    return_data = {'id': str(service_elem.id),
                   'is_internal':is_boolean(service_elem.is_internal.text),
                   'impl_name':service_elem.impl_name.text,
                   'usage_count':str(service_elem.usage_count.text),
                   'message': 'Successfully {0} the service [{1}]'.format(verb, service_elem.name.text),
                }

    print(dumps(return_data))
    
    return HttpResponse(dumps(return_data), mimetype='application/javascript')
Exemplo n.º 25
0
Arquivo: zmq.py Projeto: brtsz/zato
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')

            core_params = ['id', 'cluster_id', 'name', 'is_active', 'address', 'socket_type']
            core_params = _get_params(payload, core_params, 'data.')
            
            id = core_params['id']
            name = core_params['name']
            cluster_id = core_params['cluster_id']
            
            existing_one = session.query(OutgoingZMQ.id).\
                filter(OutgoingZMQ.cluster_id==cluster_id).\
                filter(OutgoingZMQ.name==name).\
                filter(OutgoingZMQ.id!=core_params['id']).\
                first()
            
            if existing_one:
                raise Exception('An outgoing ZeroMQ connection [{0}] already exists on this cluster'.format(name))
            
            xml_item = Element('out_zmq')
            
            try:
                
                core_params['id'] = int(core_params['id'])
                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = session.query(OutgoingZMQ).filter_by(id=id).one()
                old_name = item.name
                item.name = name
                item.is_active = core_params['is_active']
                item.address = core_params['address']
                item.socket_type = core_params['socket_type']
                
                session.add(item)
                session.commit()
                
                xml_item.id = item.id
                
                core_params['action'] = OUTGOING.ZMQ_EDIT
                core_params['old_name'] = old_name
                self.broker_client.send_json(core_params, msg_type=MESSAGE_TYPE.TO_ZMQ_CONNECTOR_SUB)
                
                return ZATO_OK, etree.tostring(xml_item)
                
            except Exception, e:
                msg = 'Could not update the outgoing ZeroMQ connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise  
Exemplo n.º 26
0
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        def_ids = _get_def_ids(cluster)
        create_form.set_def_id(def_ids)
        edit_form.set_def_id(def_ids)

        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster, 'zato:channel.jms_wmq.get-list', zato_message)
        
        if zato_path('data.item_list.item').get_from(zato_message) is not None:
            
            for msg_item in zato_message.data.item_list.item:
                
                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                queue = msg_item.queue.text
                def_name = msg_item.def_name.text
                def_id = msg_item.def_id.text
                service_name = msg_item.service_name.text
                
                item =  ChannelWMQ(id, name, is_active, queue, def_id, def_name, service_name)
                items.append(item)
                
    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/channel/jms_wmq.html', return_data,
                              context_instance=RequestContext(req))
Exemplo n.º 27
0
 def get_data(self, session):
     out = []
     sl = service_list(session, self.request.input.cluster_id, False)
     
     internal_del = is_boolean(self.server.fs_server_config.misc.internal_services_may_be_deleted)
     
     for item in sl:
         item.may_be_deleted = internal_del if item.is_internal else True
         item.usage = self.server.kvdb.conn.get('{}{}'.format(KVDB.SERVICE_USAGE, item.name)) or 0
         
         out.append(item)
     
     return out
Exemplo n.º 28
0
Arquivo: sql.py Projeto: dsuch/zato
def index(req):
    """ Lists all the SQL connections.
    """
    items = []
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')
    change_password_form = ChangePasswordForm()

    if req.zato.cluster_id and req.method == 'GET':
        zato_message, soap_response  = invoke_admin_service(req.zato.cluster, 'zato:outgoing.sql.get-list', {'cluster_id': req.zato.cluster_id})
        if zato_path('response.item_list.item').get_from(zato_message) is not None:

            for msg_item in zato_message.response.item_list.item:

                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                engine = msg_item.engine.text if msg_item.engine else ''
                host = msg_item.host.text if msg_item.host else ''
                port = msg_item.port.text if msg_item.port else ''
                db_name = msg_item.db_name.text if msg_item.db_name else ''
                username = msg_item.username.text if msg_item.username else ''
                pool_size = msg_item.pool_size.text if msg_item.pool_size else ''
                extra = msg_item.extra.text if msg_item.extra else ''
                
                item =  SQLConnectionPool()
                item.id = id
                item.name = name
                item.is_active = is_active
                item.engine = engine
                item.engine_text = odb_engine_friendly_name[engine]
                item.host = host
                item.port = port
                item.db_name = db_name
                item.username = username
                item.pool_size = pool_size
                item.extra = extra
                items.append(item)

    return_data = {'zato_clusters':req.zato.clusters,
        'cluster_id':req.zato.cluster_id,
        'choose_cluster_form':req.zato.choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        'change_password_form': change_password_form
        }

    return TemplateResponse(req, 'zato/outgoing/sql.html', return_data)
Exemplo n.º 29
0
Arquivo: s3.py Projeto: brtsz/zato
    def handle(self, *args, **kwargs):

        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')

            core_params = ['id', 'cluster_id', 'name', 'is_active', 'prefix', 'separator', 'key_sync_timeout']
            core_params = _get_params(payload, core_params, 'data.')

            id = core_params['id']
            name = core_params['name']
            cluster_id = core_params['cluster_id']

            existing_one = session.query(OutgoingS3.id).\
                filter(OutgoingS3.cluster_id==cluster_id).\
                filter(OutgoingS3.name==name).\
                filter(OutgoingS3.id!=core_params['id']).\
                first()

            if existing_one:
                raise Exception('An outgoing S3 connection [{0}] already exists on this cluster'.format(name))

            xml_item = Element('out_s3')

            try:

                core_params['id'] = int(core_params['id'])
                core_params['is_active'] = is_boolean(core_params['is_active'])

                item = session.query(OutgoingS3).filter_by(id=id).one()
                old_name = item.name
                item.name = name
                item.is_active = core_params['is_active']
                item.prefix = core_params['prefix']
                item.separator = core_params['separator']
                item.key_sync_timeout = core_params['key_sync_timeout']

                session.add(item)
                session.commit()

                xml_item.id = item.id

                return ZATO_OK, etree.tostring(xml_item)

            except Exception, e:
                msg = 'Could not update the outgoing S3 connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 30
0
def add_warehouse_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_wh_name = validate.sql_escape(request.form["wh_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    if (wh.wh_add(form_wh_name, form_is_active)):
        return render_template('index.html',
                               page_title="Warehouses list: ",
                               message="Warehouse sucessfully added! ",
                               content=wh.wh_list())
    return render_template('index.html',
                           page_title="Warehouses list: ",
                           warning="Error - Warehouse wasn't added! ",
                           content=wh.wh_list())
Exemplo n.º 31
0
def update_user_page():
    if (login.is_logged_in_admin() == 0
        ):  #Only logged in ADMIN users can view this page!
        return redirect("/login/not_admin")

    form_u_id = validate.is_user(request.form["u_id"])
    form_u_name = validate.sql_escape(request.form["u_name"])
    form_d_name = validate.sql_escape(request.form["d_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    return render_template('index.html',
                           page_title="Edit user: ",
                           message=users.user_update(form_u_id, form_u_name,
                                                     form_is_active,
                                                     form_d_name),
                           content=users.user_edit(form_u_id))
Exemplo n.º 32
0
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')
    change_password_form = ChangePasswordForm()

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster,
                'zato:security.tech-account.get-list', zato_message)
        
        if zato_path('data.definition_list.definition').get_from(zato_message) is not None:
            
            for definition_elem in zato_message.data.definition_list.definition:
                
                id = definition_elem.id.text
                name = definition_elem.name.text
                is_active = is_boolean(definition_elem.is_active.text)
                
                account = TechnicalAccount(id, name, is_active=is_active)
                items.append(account)
                

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        'change_password_form':change_password_form
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/security/tech-account.html', return_data,
                              context_instance=RequestContext(req))
Exemplo n.º 33
0
def update_warehouse_page():
    if (login.is_logged_in() == 0):  #Only logged in users can view this page!
        return redirect("/login/not_logged_in")

    form_wh_id = validate.is_wh(request.form["wh_id"])
    form_wh_name = validate.sql_escape(request.form["wh_name"])
    form_is_active = validate.is_boolean(request.form["is_active"])
    if (wh.wh_update(form_wh_id, form_wh_name, form_is_active)):
        return render_template('index.html',
                               page_title="Edit warehouse: ",
                               message="Warehouse updated! ",
                               content=wh.wh_edit(form_wh_id))
    return render_template('index.html',
                           page_title="Edit warehouse: ",
                           warning="Update failed! ",
                           content=wh.wh_edit(form_wh_id))
Exemplo n.º 34
0
    def __init__(self, name, config, config_no_sensitive):
        self.name = name
        self.config = config
        self.logger = getLogger(self.__class__.__name__)

        # Safe for printing out to logs, any sensitive data has been shadowed
        self.config_no_sensitive = config_no_sensitive

        _extra = {}
        extra = self.config.get('extra')  # Will be None at times
        if extra:
            extra = ';'.join(extra.splitlines())
            for line in extra.split(';'):
                original_line = line
                if line:
                    line = line.split('=')
                    if not len(line) == 2:
                        raise ValueError(
                            'Each line must be a single key=value entry, not [{}]'
                            .format(original_line))

                    key, value = line
                    value = value.strip()

                    try:
                        value = is_boolean(value)
                    except VdtTypeError:
                        # It's cool, not a boolean
                        pass

                    try:
                        value = is_integer(value)
                    except VdtTypeError:
                        # OK, not an integer
                        pass

                    _extra[key.strip()] = value

        engine_url = engine_def.format(**config)
        self.engine = create_engine(engine_url,
                                    pool_size=int(config['pool_size']),
                                    **_extra)

        event.listen(self.engine, 'checkin', self.on_checkin)
        event.listen(self.engine, 'checkout', self.on_checkout)
        event.listen(self.engine, 'connect', self.on_connect)
        event.listen(self.engine, 'first_connect', self.on_first_connect)
Exemplo n.º 35
0
Arquivo: zmq.py Projeto: brtsz/zato
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')
            
            core_params = ['cluster_id', 'name', 'is_active', 'address', 'socket_type']
            core_params = _get_params(payload, core_params, 'data.')
            
            name = core_params['name']
            cluster_id = core_params['cluster_id']
            
            existing_one = session.query(OutgoingZMQ.id).\
                filter(OutgoingZMQ.cluster_id==cluster_id).\
                filter(OutgoingZMQ.name==name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing ZeroMQ connection [{0}] already exists on this cluster'.format(name))
            
            created_elem = Element('out_zmq')
            
            try:

                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = OutgoingZMQ()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.address = core_params['address']
                item.socket_type = core_params['socket_type']
                item.cluster_id = core_params['cluster_id']
                
                session.add(item)
                session.commit()
                
                created_elem.id = item.id
                start_connector(self.server.repo_location, item.id)
                
                return ZATO_OK, etree.tostring(created_elem)
                
            except Exception, e:
                msg = 'Could not create an outgoing ZeroMQ connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise 
Exemplo n.º 36
0
def any_checker(value):
    ''' Convert value to its built-in data type if possible

    Convert a string value to its built-in data type (integer, float, boolean, str
    or list of these) if possible

    Args:
        value (:obj:`object`): a value to be converted

    Returns:
        :obj:`type`: the converted value

    Raises:
        :obj:`VdtTypeError`: if the value cannot be converted
    '''

    if not isinstance(value, float) or not math.isnan(value):
        # if statement needed because `_handle_value` doesn't seem to be able to handle nan
        value, _ = ConfigObj()._handle_value(value)

    # parse to integer
    try:
        return is_integer(value)
    except VdtTypeError:
        pass

    # parse to float
    try:
        return is_float(value)
    except VdtTypeError:
        pass

    # parse to bool
    try:
        return is_boolean(value)
    except VdtTypeError:
        pass

    # parse to list
    try:
        return [any_checker(val) for val in is_list(value)]
    except VdtTypeError:
        pass

    # parse to string
    return is_string(value)
Exemplo n.º 37
0
    def handle(self):
        input = self.request.input

        # If we have a rate limiting definition, let's check it upfront
        DefinitionParser.check_definition_from_input(input)

        with closing(self.odb.session()) as session:
            try:
                service = session.query(Service).filter_by(
                    id=input.id).one()  # type: Service
                service.is_active = input.is_active
                service.slow_threshold = input.slow_threshold

                set_instance_opaque_attrs(service, input)

                # Configure JSON Schema validation if service has a schema assigned by user.
                class_info = self.server.service_store.get_service_info_by_id(
                    input.id)  # type: dict
                class_ = class_info['service_class']  # type: Service
                if class_.schema:
                    self.server.service_store.set_up_class_json_schema(
                        class_, input)

                # Set up rate-limiting each time an object was edited
                self.server.service_store.set_up_rate_limiting(service.name)

                session.add(service)
                session.commit()

                input.action = SERVICE.EDIT.value
                input.impl_name = service.impl_name
                input.name = service.name
                self.broker_client.publish(input)

                self.response.payload = service
                internal_del = is_boolean(self.server.fs_server_config.misc.
                                          internal_services_may_be_deleted)
                self.response.payload.may_be_deleted = internal_del if service.is_internal else True

            except Exception:
                self.logger.error('Service could not be updated, e:`%s`',
                                  format_exc())
                session.rollback()

                raise
Exemplo n.º 38
0
Arquivo: sql.py Projeto: Adniel/zato
 def __init__(self, name, config, config_no_sensitive):
     self.name = name
     self.config = config
     self.logger = getLogger(self.__class__.__name__)
     
     # Safe for printing out to logs, any sensitive data has been shadowed
     self.config_no_sensitive = config_no_sensitive 
     
     _extra = {}
     extra = self.config.get('extra') # Will be None at times
     if extra:
         extra = ';'.join(extra.splitlines())
         for line in extra.split(';'):
             original_line = line
             if line:
                 line = line.split('=')
                 if not len(line) == 2:
                     raise ValueError('Each line must be a single key=value entry, not [{}]'.format(original_line))
                 
                 key, value = line
                 value = value.strip()
                 
                 try:
                     value = is_boolean(value)
                 except VdtTypeError:
                     # It's cool, not a boolean
                     pass 
                 
                 try:
                     value = is_integer(value)
                 except VdtTypeError:
                     # OK, not an integer
                     pass 
                 
                 _extra[key.strip()] = value
     
     engine_url = engine_def.format(**config)
     self.engine = create_engine(engine_url, pool_size=int(config['pool_size']), **_extra)
     
     event.listen(self.engine, 'checkin', self.on_checkin)
     event.listen(self.engine, 'checkout', self.on_checkout)
     event.listen(self.engine, 'connect', self.on_connect)
     event.listen(self.engine, 'first_connect', self.on_first_connect)
Exemplo n.º 39
0
    def handle(self, *args, **kwargs):

        with closing(self.server.odb.session()) as session:
            payload = kwargs.get("payload")
            request_params = ["cluster_id", "tech_account_id", "name", "is_active"]
            params = _get_params(payload, request_params, "data.")

            cluster_id = params["cluster_id"]
            tech_account_id = params["tech_account_id"]
            name = params["name"]

            existing_one = (
                session.query(TechnicalAccount)
                .filter(Cluster.id == cluster_id)
                .filter(TechnicalAccount.name == name)
                .filter(TechnicalAccount.id != tech_account_id)
                .first()
            )

            if existing_one:
                raise Exception("Technical account [{0}] already exists on this cluster".format(name))

            tech_account = session.query(TechnicalAccount).filter(TechnicalAccount.id == tech_account_id).one()
            old_name = tech_account.name

            tech_account.name = name
            tech_account.is_active = is_boolean(params["is_active"])

            tech_account_elem = Element("tech_account")

            try:
                session.add(tech_account)
                session.commit()

                tech_account_elem.id = tech_account.id

            except Exception, e:
                msg = "Could not update the technical account, e=[{e}]".format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
            else:
Exemplo n.º 40
0
def parse_extra_into_dict(lines, convert_bool=True):
    """ Creates a dictionary out of key=value lines.
    """
    _extra = {}

    if lines:
        extra = ';'.join(lines.splitlines())

        for line in extra.split(';'):
            original_line = line
            if line:
                line = line.split('=')
                if not len(line) == 2:
                    raise ValueError('Each line must be a single key=value entry, not [{}]'.format(original_line))

                key, value = line
                value = value.strip()

                if convert_bool:
                    try:
                        value = is_boolean(value)
                    except VdtTypeError:
                        # It's cool, not a boolean
                        pass

                try:
                    value = is_integer(value)
                except VdtTypeError:
                    # OK, not an integer
                    pass

                # Could be a dict or another simple type then
                try:
                    value = literal_eval(value)
                except Exception:
                    pass

                # OK, let's just treat it as string
                _extra[key.strip()] = value

    return _extra
Exemplo n.º 41
0
 def handle(self, *args, **kwargs):
     
     with closing(self.server.odb.session()) as session:
         payload = kwargs.get('payload')
         request_params = ['id', 'is_active', 'name']
         
         params = _get_params(payload, request_params, 'data.')
         id = int(params['id'])
         is_active = is_boolean(params['is_active'])
         name = params['name']
         
         service_elem = Element('service')
         
         try:
             
             service = session.query(Service).filter_by(id=id).one()
             service.is_active = is_active
             service.name = name
             
             session.add(service)
             session.commit()
             
             service_elem.id = service.id
             service_elem.name = service.name
             service_elem.impl_name = service.impl_name
             service_elem.is_internal = service.is_internal
             service_elem.usage_count = 'TODO edit'
             
             params['action'] = SERVICE.EDIT
             self.broker_client.send_json(params, msg_type=MESSAGE_TYPE.TO_PARALLEL_SUB)
             
             return ZATO_OK, etree.tostring(service_elem)
             
         except Exception, e:
             msg = 'Could not update the service, e=[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise         
Exemplo n.º 42
0
Arquivo: wss.py Projeto: dsuch/zato
def index(req):
    items = []
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')
    change_password_form = ChangePasswordForm()

    if req.zato.cluster_id and req.method == 'GET':
        
        zato_message, soap_response  = invoke_admin_service(req.zato.cluster,'zato:security.wss.get-list', {'cluster_id':req.zato.cluster_id})
        
        if zato_path('response.item_list.item').get_from(zato_message) is not None:
            for definition_elem in zato_message.response.item_list.item:
                id = definition_elem.id.text
                name = definition_elem.name.text
                is_active = is_boolean(definition_elem.is_active.text)
                username = definition_elem.username.text
                password_type = ZATO_WSS_PASSWORD_TYPES[definition_elem.password_type.text]
                password_type_raw = definition_elem.password_type.text
                reject_empty_nonce_creat = definition_elem.reject_empty_nonce_creat
                reject_stale_tokens = definition_elem.reject_stale_tokens
                reject_expiry_limit = definition_elem.reject_expiry_limit
                nonce_freshness_time = definition_elem.nonce_freshness_time

                wss = WSSDefinition(id, name, is_active, username, None,
                        password_type, reject_empty_nonce_creat, reject_stale_tokens,
                        reject_expiry_limit, nonce_freshness_time, password_type_raw=password_type_raw)

                items.append(wss)

    return_data = {'zato_clusters':req.zato.clusters,
        'cluster_id':req.zato.cluster_id,
        'choose_cluster_form':req.zato.choose_cluster_form,
        'items':items,
        'create_form': create_form,
        'edit_form': edit_form,
        'change_password_form': change_password_form
        }

    return TemplateResponse(req, 'zato/security/wss.html', return_data)
Exemplo n.º 43
0
    def handle(self):
        input = self.request.input
        with closing(self.odb.session()) as session:
            try:
                service = session.query(Service).filter_by(id=input.id).one()
                service.is_active = input.is_active
                service.slow_threshold = input.slow_threshold

                set_instance_opaque_attrs(service, input)

                # Configure JSON Schema validation if service has a schema assigned by user.
                class_info = self.server.service_store.get_service_class_by_id(
                    input.id)  # type: dict
                class_ = class_info['service_class']  # type: Service
                if class_.json_schema:
                    self.server.service_store.set_up_class_json_schema(
                        class_, input)

                session.add(service)
                session.commit()

                input.action = SERVICE.EDIT.value
                input.impl_name = service.impl_name
                self.broker_client.publish(input)

                self.response.payload = service

                internal_del = is_boolean(self.server.fs_server_config.misc.
                                          internal_services_may_be_deleted)
                self.response.payload.may_be_deleted = internal_del if service.is_internal else True

            except Exception:
                msg = 'Service could not be updated, e:`{}`'.format(
                    format_exc())
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 44
0
def wsdl(req, service_name):
    service = Service(name=service_name)
    has_wsdl = False
    wsdl_public_url = get_public_wsdl_url(req.zato.cluster, service_name)

    input_dict = {
        'name': service_name,
        'cluster_id': req.zato.cluster_id
    }
    zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.has-wsdl', input_dict)

    if zato_path('response.item').get_from(zato_message) is not None:
        service.id = zato_message.response.item.service_id.text
        has_wsdl = is_boolean(zato_message.response.item.has_wsdl.text)

    return_data = {
        'cluster_id':req.zato.cluster_id,
        'service':service,
        'has_wsdl':has_wsdl,
        'wsdl_public_url':wsdl_public_url,
        }

    return TemplateResponse(req, 'zato/service/wsdl.html', return_data)
Exemplo n.º 45
0
    def handle(self):
        with closing(self.odb.session()) as session:
            service = self.get_data(session)
            internal_del = is_boolean(self.server.fs_server_config.misc.internal_services_may_be_deleted)
            
            self.response.payload.id = service.id
            self.response.payload.name = service.name
            self.response.payload.is_active = service.is_active
            self.response.payload.impl_name = service.impl_name
            self.response.payload.is_internal = service.is_internal
            self.response.payload.slow_threshold = service.slow_threshold
            self.response.payload.may_be_deleted = internal_del if service.is_internal else True
            self.response.payload.usage = self.server.kvdb.conn.get('{}{}'.format(KVDB.SERVICE_USAGE, service.name)) or 0

            time_key = '{}{}'.format(KVDB.SERVICE_TIME_BASIC, service.name)            
            self.response.payload.time_last = self.server.kvdb.conn.hget(time_key, 'last')
            
            for name in('min_all_time', 'max_all_time', 'mean_all_time'):
                setattr(self.response.payload, 'time_{}'.format(name), float(
                    self.server.kvdb.conn.hget(time_key, name) or 0))
                
            self.response.payload.time_min_all_time = int(self.response.payload.time_min_all_time)
            self.response.payload.time_max_all_time = int(self.response.payload.time_max_all_time)
            self.response.payload.time_mean_all_time = round(self.response.payload.time_mean_all_time, 1)
Exemplo n.º 46
0
def index(req):
    items = []
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if req.zato.cluster_id and req.method == 'GET':
        def_ids = _get_def_ids(req.zato.cluster)
        create_form.set_def_id(def_ids)
        edit_form.set_def_id(def_ids)

        zato_message, soap_response  = invoke_admin_service(req.zato.cluster, 'zato:outgoing.jms_wmq.get-list', {'cluster_id': req.zato.cluster_id})
        
        if zato_path('response.item_list.item').get_from(zato_message) is not None:
            for msg_item in zato_message.response.item_list.item:
                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                delivery_mode = int(msg_item.delivery_mode.text)
                priority = msg_item.priority.text
                expiration = msg_item.expiration.text
                delivery_mode_text = delivery_friendly_name[delivery_mode]
                def_name = msg_item.def_name.text
                def_id = msg_item.def_id.text
                
                item = OutgoingWMQ(id, name, is_active, delivery_mode, priority, expiration, def_id, delivery_mode_text, def_name)
                items.append(item)

    return_data = {'zato_clusters':req.zato.clusters,
        'cluster_id':req.zato.cluster_id,
        'choose_cluster_form':req.zato.choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }

    return TemplateResponse(req, 'zato/outgoing/jms_wmq.html', return_data)
Exemplo n.º 47
0
def overview(req, service_name):
    cluster_id = req.GET.get('cluster')
    service = None

    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':

        input_dict = {'name': service_name, 'cluster_id': req.zato.cluster_id}

        response = req.zato.client.invoke('zato.service.get-by-name',
                                          input_dict)
        if response.has_data:
            service = Service()

            for name in ('id', 'name', 'is_active', 'impl_name', 'is_internal',
                         'usage', 'time_last', 'time_min_all_time',
                         'time_max_all_time', 'time_mean_all_time'):

                value = getattr(response.data, name)
                if name in ('is_active', 'is_internal'):
                    value = is_boolean(value)

                setattr(service, name, value)

            now = datetime.utcnow()
            start = now + relativedelta(minutes=-60)

            response = req.zato.client.invoke('zato.stats.get-by-service', {
                'service_id': service.id,
                'start': start,
                'stop': now
            })
            if response.has_data:
                for name in ('mean_trend', 'usage_trend', 'min_resp_time',
                             'max_resp_time', 'mean', 'usage', 'rate'):
                    value = getattr(response.data, name)
                    if not value or value == ZATO_NONE:
                        value = ''

                    setattr(service, 'time_{}_1h'.format(name), value)

            for channel_type in ('plain_http', 'soap', 'amqp', 'jms-wmq',
                                 'zmq'):
                channels = _get_channels(req.zato.client, req.zato.cluster,
                                         service.id, channel_type)
                getattr(service,
                        channel_type.replace('jms-', '') +
                        '_channels').extend(channels)

            for item in req.zato.client.invoke(
                    'zato.service.get-deployment-info-list',
                {'id': service.id}):
                service.deployment_info.append(
                    DeploymentInfo(item.server_name, item.details))

            # TODO: There needs to be a new service added zato.service.scheduler.job.get-by-service
            #       or .get-list should start accept a service name. Right now we pull all the
            #       jobs which is suboptimal.
            response = req.zato.client.invoke('zato.scheduler.job.get-list',
                                              {'cluster_id': cluster_id})
            if response.has_data:
                for item in response.data:
                    if item.service_name == service_name:
                        url = reverse('scheduler')
                        url += '?cluster={}'.format(cluster_id)
                        url += '&highlight={}'.format(item.id)
                        service.scheduler_jobs.append(
                            ExposedThrough(item.id, item.name, url))

    return_data = {
        'zato_clusters': req.zato.clusters,
        'service': service,
        'cluster_id': cluster_id,
        'search_form': req.zato.search_form,
        'create_form': create_form,
        'edit_form': edit_form,
    }

    return TemplateResponse(req, 'zato/service/overview.html', return_data)
Exemplo n.º 48
0
 def __init__(self, value):
     self._str = value
     self._bool = is_boolean(value)
Exemplo n.º 49
0
def is_preset_param(value):
    parsed = is_tuple(value, min=2, max=2)
    return is_boolean(parsed[0]), is_integer(parsed[1], min=0)
Exemplo n.º 50
0
def _exists(value, exists):
    if not isinstance(exists, bool):
        # Raises VdtTypeError on fail
        exists = is_boolean(exists)
    if exists and not os.path.exists(value):
        raise ValidateError('Path "%s" does not exist.' % value)