def handle(self): input = self.request.input input.sec_use_rbac = input.security_id == ZATO_SEC_USE_RBAC input.security_id = input.security_id if input.security_id not in ( ZATO_NONE, ZATO_SEC_USE_RBAC) else None input.soap_action = input.soap_action if input.soap_action else '' input.timeout = input.get('timeout') or MISC.DEFAULT_HTTP_TIMEOUT if input.content_encoding and input.content_encoding != 'gzip': raise Exception( 'Content encoding must be empty or equal to `gzip`') with closing(self.odb.session()) as session: existing_one = session.query(HTTPSOAP.id).\ filter(HTTPSOAP.cluster_id==input.cluster_id).\ filter(HTTPSOAP.name==input.name).\ filter(HTTPSOAP.connection==input.connection).\ filter(HTTPSOAP.transport==input.transport).\ first() if existing_one: raise Exception( 'An object of that name `{}` already exists on this cluster' .format(input.name)) # Is the service's name correct? service = session.query(Service).\ filter(Cluster.id==input.cluster_id).\ filter(Service.cluster_id==Cluster.id).\ filter(Service.name==input.service).first() if input.connection == CONNECTION.CHANNEL and not service: msg = 'Service `{}` does not exist on this cluster'.format( input.service) self.logger.error(msg) raise Exception(msg) # Will raise exception if the security type doesn't match connection # type and transport sec_info = self._handle_security_info(session, input.security_id, input.connection, input.transport) # Make sure this combination of channel parameters does not exist already if input.connection == CONNECTION.CHANNEL: self.ensure_channel_is_unique(session, input.url_path, input.soap_action, input.cluster_id) try: item = self._new_zato_instance_with_cluster(HTTPSOAP) item.connection = input.connection item.transport = input.transport item.is_internal = input.is_internal item.name = input.name item.is_active = input.is_active item.host = input.host item.url_path = input.url_path item.method = input.method item.soap_action = input.soap_action item.soap_version = input.soap_version or None item.data_format = input.data_format item.service = service item.ping_method = input.get( 'ping_method') or DEFAULT_HTTP_PING_METHOD item.pool_size = input.get( 'pool_size') or DEFAULT_HTTP_POOL_SIZE item.merge_url_params_req = input.get( 'merge_url_params_req') or True item.url_params_pri = input.get( 'url_params_pri') or URL_PARAMS_PRIORITY.DEFAULT item.params_pri = input.get( 'params_pri') or PARAMS_PRIORITY.DEFAULT item.serialization_type = input.get( 'serialization_type' ) or HTTP_SOAP_SERIALIZATION_TYPE.DEFAULT.id item.timeout = input.timeout item.has_rbac = input.get( 'has_rbac') or input.sec_use_rbac or False item.content_type = input.get('content_type') item.sec_use_rbac = input.sec_use_rbac item.cache_id = input.cache_id or None item.cache_expiry = input.cache_expiry item.content_encoding = input.content_encoding if input.security_id: item.security = get_security_by_id(session, input.security_id) else: input.security_id = None # To ensure that SQLite doesn't reject '' sec_tls_ca_cert_id = input.get('sec_tls_ca_cert_id') item.sec_tls_ca_cert_id = sec_tls_ca_cert_id if sec_tls_ca_cert_id and sec_tls_ca_cert_id != ZATO_NONE else None # Opaque attributes set_instance_opaque_attrs(item, input) session.add(item) session.commit() if input.connection == CONNECTION.CHANNEL: input.impl_name = service.impl_name input.service_id = service.id input.service_name = service.name cache = cache_by_id( session, input.cluster_id, item.cache_id) if item.cache_id else None if cache: input.cache_type = cache.cache_type input.cache_name = cache.name else: input.cache_type = None input.cache_name = None if item.sec_tls_ca_cert_id and item.sec_tls_ca_cert_id != ZATO_NONE: self.add_tls_ca_cert(input, item.sec_tls_ca_cert_id) input.id = item.id input.update(sec_info) if input.connection == CONNECTION.CHANNEL: action = CHANNEL.HTTP_SOAP_CREATE_EDIT.value else: action = OUTGOING.HTTP_SOAP_CREATE_EDIT.value self.notify_worker_threads(input, action) self.response.payload.id = item.id self.response.payload.name = item.name except Exception: msg = 'Could not create the object, e:`{}'.format(format_exc()) self.logger.error(msg) session.rollback() raise
def handle(self): # If we have a rate limiting definition, let's check it upfront DefinitionParser.check_definition_from_input(self.request.input) input = self.request.input input.sec_use_rbac = input.get('sec_use_rbac') or (input.security_id == ZATO_SEC_USE_RBAC) input.security_id = input.security_id if input.security_id not in (ZATO_NONE, ZATO_SEC_USE_RBAC) else None input.soap_action = input.soap_action if input.soap_action else '' if input.content_encoding and input.content_encoding != 'gzip': raise Exception('Content encoding must be empty or equal to `gzip`') with closing(self.odb.session()) as session: existing_one = session.query(HTTPSOAP.id).\ filter(HTTPSOAP.cluster_id==input.cluster_id).\ filter(HTTPSOAP.id!=input.id).\ filter(HTTPSOAP.name==input.name).\ filter(HTTPSOAP.connection==input.connection).\ filter(HTTPSOAP.transport==input.transport).\ first() if existing_one: raise Exception('An object of that input.name:`{}` already exists in this cluster ' \ '(input.connection:`{}` input.transport:`{}` input.id:`{}` existing_one.id:`{}`)'.format( input.name, input.connection, input.transport, input.id, existing_one.id)) # Is the service's name correct? service = session.query(Service).\ filter(Cluster.id==input.cluster_id).\ filter(Service.cluster_id==Cluster.id).\ filter(Service.name==input.service).first() if input.connection == CONNECTION.CHANNEL and not service: msg = 'Service `{}` does not exist on this cluster'.format(input.service) self.logger.error(msg) raise Exception(msg) # Will raise exception if the security type doesn't match connection # type and transport sec_info = self._handle_security_info(session, input.security_id, input.connection, input.transport) # TLS data comes in combinations, i.e. certain elements are required only if TLS keys/certs are used self._validate_tls(input, sec_info) try: item = session.query(HTTPSOAP).filter_by(id=input.id).one() opaque = parse_instance_opaque_attr(item) old_name = item.name old_url_path = item.url_path old_soap_action = item.soap_action old_http_method = item.method old_http_accept = opaque.get('http_accept') item.name = input.name item.is_active = input.is_active item.host = input.host item.url_path = input.url_path item.security_id = input.security_id or None # So that SQLite does not reject '' item.connection = input.connection item.transport = input.transport item.cluster_id = input.cluster_id item.method = input.method item.soap_action = input.soap_action item.soap_version = input.soap_version or None item.data_format = input.data_format item.service = service item.ping_method = input.get('ping_method') or DEFAULT_HTTP_PING_METHOD item.pool_size = input.get('pool_size') or DEFAULT_HTTP_POOL_SIZE item.merge_url_params_req = input.get('merge_url_params_req') or False item.url_params_pri = input.get('url_params_pri') or URL_PARAMS_PRIORITY.DEFAULT item.params_pri = input.get('params_pri') or PARAMS_PRIORITY.DEFAULT item.serialization_type = input.get('serialization_type') or HTTP_SOAP_SERIALIZATION_TYPE.DEFAULT.id item.timeout = input.get('timeout') or MISC.DEFAULT_HTTP_TIMEOUT item.has_rbac = input.get('has_rbac') or input.sec_use_rbac or False item.content_type = input.get('content_type') item.sec_use_rbac = input.sec_use_rbac item.cache_id = input.cache_id or None item.cache_expiry = input.cache_expiry item.content_encoding = input.content_encoding sec_tls_ca_cert_id = input.get('sec_tls_ca_cert_id') item.sec_tls_ca_cert_id = sec_tls_ca_cert_id if sec_tls_ca_cert_id and sec_tls_ca_cert_id != ZATO_NONE else None # Opaque attributes set_instance_opaque_attrs(item, input) session.add(item) session.commit() if input.connection == CONNECTION.CHANNEL: input.impl_name = service.impl_name input.service_id = service.id input.service_name = service.name input.merge_url_params_req = item.merge_url_params_req input.url_params_pri = item.url_params_pri input.params_pri = item.params_pri cache = cache_by_id(session, input.cluster_id, item.cache_id) if item.cache_id else None if cache: input.cache_type = cache.cache_type input.cache_name = cache.name else: input.cache_type = None input.cache_name = None else: input.ping_method = item.ping_method input.pool_size = item.pool_size input.is_internal = item.is_internal input.old_name = old_name input.old_url_path = old_url_path input.old_soap_action = old_soap_action input.old_http_method = old_http_method input.old_http_accept = old_http_accept input.update(sec_info) if item.sec_tls_ca_cert_id and item.sec_tls_ca_cert_id != ZATO_NONE: self.add_tls_ca_cert(input, item.sec_tls_ca_cert_id) if input.connection == CONNECTION.CHANNEL: action = CHANNEL.HTTP_SOAP_CREATE_EDIT.value else: action = OUTGOING.HTTP_SOAP_CREATE_EDIT.value self.notify_worker_threads(input, action) self.response.payload.id = item.id self.response.payload.name = item.name except Exception: self.logger.error('Object could not be updated, e:`%s`', format_exc()) session.rollback() raise
def handle(self): input = self.request.input input.sec_use_rbac = input.security_id == ZATO_SEC_USE_RBAC input.security_id = input.security_id if input.security_id not in (ZATO_NONE, ZATO_SEC_USE_RBAC) else None input.soap_action = input.soap_action if input.soap_action else '' with closing(self.odb.session()) as session: existing_one = session.query(HTTPSOAP.id).\ filter(HTTPSOAP.cluster_id==input.cluster_id).\ filter(HTTPSOAP.id!=input.id).\ filter(HTTPSOAP.name==input.name).\ filter(HTTPSOAP.connection==input.connection).\ filter(HTTPSOAP.transport==input.transport).\ first() if existing_one: raise Exception('An object of that name `{}` already exists on this cluster'.format(input.name)) # Is the service's name correct? service = session.query(Service).\ filter(Cluster.id==input.cluster_id).\ filter(Service.cluster_id==Cluster.id).\ filter(Service.name==input.service).first() if input.connection == 'channel' and not service: msg = 'Service `{}` does not exist on this cluster'.format(input.service) self.logger.error(msg) raise Exception(msg) # Will raise exception if the security type doesn't match connection # type and transport sec_info = self._handle_security_info(session, input.security_id, input.connection, input.transport) # TLS data comes in combinations, i.e. certain elements are required only if TLS keys/certs are used self._validate_tls(input, sec_info) try: item = session.query(HTTPSOAP).filter_by(id=input.id).one() old_name = item.name old_url_path = item.url_path old_soap_action = item.soap_action item.name = input.name item.is_active = input.is_active item.host = input.host item.url_path = input.url_path item.security_id = input.security_id or None # So SQLite doesn't reject '' item.connection = input.connection item.transport = input.transport item.cluster_id = input.cluster_id item.method = input.method item.soap_action = input.soap_action item.soap_version = input.soap_version or None item.data_format = input.data_format item.service = service item.ping_method = input.get('ping_method') or DEFAULT_HTTP_PING_METHOD item.pool_size = input.get('pool_size') or DEFAULT_HTTP_POOL_SIZE item.merge_url_params_req = input.get('merge_url_params_req') or False item.url_params_pri = input.get('url_params_pri') or URL_PARAMS_PRIORITY.DEFAULT item.params_pri = input.get('params_pri') or PARAMS_PRIORITY.DEFAULT item.serialization_type = input.get('serialization_type') or HTTP_SOAP_SERIALIZATION_TYPE.DEFAULT.id item.timeout = input.get('timeout') or MISC.DEFAULT_HTTP_TIMEOUT item.has_rbac = input.get('has_rbac') or input.sec_use_rbac or False item.content_type = input.get('content_type') item.sec_use_rbac = input.sec_use_rbac item.cache_id = input.cache_id item.cache_expiry = input.cache_expiry sec_tls_ca_cert_id = input.get('sec_tls_ca_cert_id') item.sec_tls_ca_cert_id = sec_tls_ca_cert_id if sec_tls_ca_cert_id and sec_tls_ca_cert_id != ZATO_NONE else None session.add(item) session.commit() if input.connection == 'channel': input.impl_name = service.impl_name input.service_id = service.id input.service_name = service.name input.merge_url_params_req = item.merge_url_params_req input.url_params_pri = item.url_params_pri input.params_pri = item.params_pri cache = cache_by_id(session, input.cluster_id, item.cache_id) if item.cache_id else None if cache: input.cache_type = cache.cache_type input.cache_name = cache.name else: input.cache_type = None input.cache_name = None else: input.ping_method = item.ping_method input.pool_size = item.pool_size input.is_internal = item.is_internal input.old_name = old_name input.old_url_path = old_url_path input.old_soap_action = old_soap_action input.update(sec_info) if item.sec_tls_ca_cert_id and item.sec_tls_ca_cert_id != ZATO_NONE: self.add_tls_ca_cert(input, item.sec_tls_ca_cert_id) if input.connection == 'channel': action = CHANNEL.HTTP_SOAP_CREATE_EDIT.value else: action = OUTGOING.HTTP_SOAP_CREATE_EDIT.value self.notify_worker_threads(input, action) self.response.payload.id = item.id self.response.payload.name = item.name except Exception, e: msg = 'Could not update the object, e:[{e}]'.format(e=format_exc(e)) self.logger.error(msg) session.rollback() raise