Esempio n. 1
0
    def _create_generic_connection(self,
                                   msg,
                                   needs_roundtrip=False,
                                   skip=None,
                                   raise_exc=True):

        # This roundtrip is needed to re-format msg in the format the underlying .from_bunch expects
        # in case this is a broker message rather than a startup one.
        if needs_roundtrip:
            conn = GenericConnection.from_dict(msg, skip)
            msg = conn.to_sql_dict(True)

        item = GenericConnection.from_bunch(msg)
        item_dict = item.to_dict(True)

        for key in msg:
            if key not in item_dict:
                if key != 'action':
                    item_dict[key] = msg[key]

        item_dict.queue_build_cap = self.server.fs_server_config.misc.queue_build_cap
        item_dict.auth_url = msg.address

        # Normalize the contents of the configuration message
        self.generic_normalize_config(item_dict)

        config_attr = self.generic_conn_api[item.type_]
        wrapper = self._generic_conn_handler[item.type_]

        config_attr[msg.name] = item_dict
        config_attr[msg.name].conn = wrapper(item_dict, self.server)
        config_attr[msg.name].conn.build_wrapper()
Esempio n. 2
0
    def handle(self):
        data = deepcopy(self.request.input)
        for key, value in self.request.raw_request.items():
            if key not in data:
                data[key] = self._convert_sio_elem(key, value)

        conn = GenericConnection.from_dict(data)
        conn.secret = self.server.encrypt(self.crypto.generate_secret())
        conn_dict = conn.to_sql_dict()

        with closing(self.server.odb.session()) as session:

            if self.is_edit:
                model = self._get_instance_by_id(session, ModelGenericConn,
                                                 data.id)
            else:
                model = self._new_zato_instance_with_cluster(ModelGenericConn)

            for key, value in conn_dict.items():
                setattr(model, key, value)

            session.add(model)
            session.commit()

            instance = self._get_instance_by_name(session, ModelGenericConn,
                                                  data.type_, data.name)

            self.response.payload.id = instance.id
            self.response.payload.name = instance.name

        data[
            'action'] = GENERIC.CONNECTION_EDIT.value if self.is_edit else GENERIC.CONNECTION_CREATE.value
        data['id'] = instance.id
        self.broker_client.publish(data)
Esempio n. 3
0
    def handle(self):

        data = deepcopy(self.request.input)

        raw_request = self.request.raw_request
        if isinstance(raw_request, basestring):
            raw_request = loads(raw_request)

        for key, value in raw_request.items():
            if key not in data:

                value = parse_simple_type(value)
                value = self._sio.eval_(key, value, self.server.encrypt)

                data[key] = value

        conn = GenericConnection.from_dict(data)

        # Make sure not to overwrite the seceret in Edit
        if not self.is_edit:
            conn.secret = self.server.encrypt('auto.generated.{}'.format(
                self.crypto.generate_secret()))
        conn_dict = conn.to_sql_dict()

        with closing(self.server.odb.session()) as session:

            if self.is_edit:
                model = self._get_instance_by_id(session, ModelGenericConn,
                                                 data.id)
            else:
                model = self._new_zato_instance_with_cluster(ModelGenericConn)

            # This will be needed in case this is a rename
            old_name = model.name

            for key, value in sorted(conn_dict.items()):
                if key == 'secret':
                    continue
                setattr(model, key, value)

            hook_func = hook.get(data.type_)
            if hook_func:
                hook_func(self, data, model, old_name)

            session.add(model)
            session.commit()

            instance = self._get_instance_by_name(session, ModelGenericConn,
                                                  data.type_, data.name)

            self.response.payload.id = instance.id
            self.response.payload.name = instance.name

        data['old_name'] = old_name
        data[
            'action'] = GENERIC.CONNECTION_EDIT.value if self.is_edit else GENERIC.CONNECTION_CREATE.value
        data['id'] = instance.id
        self.broker_client.publish(data)
Esempio n. 4
0
    def _create_generic_connection(self, msg, needs_roundtrip=False, skip=None):

        # This roundtrip is needed to re-format msg in the format the underlying .from_bunch expects
        # in case this is a broker message rather than a startup one.
        if needs_roundtrip:
            conn = GenericConnection.from_dict(msg, skip)
            msg = conn.to_sql_dict(True)

        item = GenericConnection.from_bunch(msg)
        item_dict = item.to_dict(True)

        item_dict.queue_build_cap = self.server.fs_server_config.misc.queue_build_cap
        item_dict.auth_url = msg.address

        config_attr = self.generic_conn_api[item.type_]
        wrapper = self._generic_conn_handler[item.type_]

        config_attr[msg.name] = item_dict
        config_attr[msg.name].conn = wrapper(item_dict, self.server)
        config_attr[msg.name].conn.build_queue()
Esempio n. 5
0
    def handle(self):
        out = {'_meta': {}, 'response': []}

        with closing(self.odb.session()) as session:

            search_result = self.get_data(session)
            out['_meta'].update(search_result.to_dict())

            for item in search_result:
                conn = GenericConnection.from_model(item)
                conn_dict = conn.to_dict()
                self._enrich_conn_dict(conn_dict)
                out['response'].append(conn_dict)

        self.response.payload = dumps(out)