def handle_DELETE(self): actions = ('ack', 'reject') try: self.request.input.require_any(*actions) except ValueError: raise BadRequest( self.cid, 'Missing state to set, should be one of `{}`'.format( ', '.join(actions))) if self.request.input.ack and self.request.input.reject: raise BadRequest(self.cid, 'Cannot both acknowledge and reject a message') func = self.pubsub.acknowledge if self.request.input.ack else self.pubsub.reject result = func(self.environ['sub_key'], self.request.input.item) if self.request.input.item in result: status = ZATO_OK details = '' else: status = ZATO_ERROR details = 'Message not found `{}`'.format(self.request.input.item) self._set_payload_data({'status': status, 'details': details})
def init(self, cid, path_info, request, headers, transport, data_format): if transport == 'soap': # HTTP headers are all uppercased at this point. soap_action = headers.get('HTTP_SOAPACTION') if not soap_action: raise BadRequest(cid, 'Client did not send the SOAPAction header') # SOAP clients may send an empty header, i.e. SOAPAction: "", # as opposed to not sending the header at all. soap_action = soap_action.lstrip('"').rstrip('"') if not soap_action: raise BadRequest(cid, 'Client sent an empty SOAPAction header') else: soap_action = '' _soap_actions = self.http_soap.getall(path_info) for _soap_action_info in _soap_actions: # TODO: Remove the call to .keys() when this pull request is merged in # https://github.com/dsc/bunch/pull/4 if soap_action in _soap_action_info.keys(): service_info = _soap_action_info[soap_action] break else: msg = '[{0}] Could not find the service config for URL:[{1}], SOAP action:[{2}]'.format( cid, path_info, soap_action) logger.warn(msg) raise NotFound(cid, msg) logger.debug('[{0}] impl_name:[{1}]'.format(cid, service_info.impl_name)) if (logger.isEnabledFor(TRACE1)): buff = StringIO() pprint(self.server.service_store.services, stream=buff) logger.log( TRACE1, '[{0}] service_store.services:[{1}]'.format( cid, buff.getvalue())) buff.close() self.server.service_store.service_data( service_info.impl_name ) # TODO - check if this call is needed at all? return service_info
def validate_input(self): username, password = get_basic_auth_credentials( self.wsgi_environ.get('HTTP_AUTHORIZATION')) if not username: self._raise_unauthorized() for item in self.server.worker_store.request_dispatcher.url_data.basic_auth_config.values( ): if item.config.username == username and item.config.password == password: client = item break else: self._raise_unauthorized() if self.request.input.item_type not in PUB_SUB.URL_ITEM_TYPE: raise BadRequest( self.cid, 'None of the supported resources `{}` found in URL path'. format(', '.join(PUB_SUB.URL_ITEM_TYPE))) sub_key = self.wsgi_environ.get('HTTP_X_ZATO_PUBSUB_KEY', ZATO_NONE) is_consumer = self.request.input.item_type == PUB_SUB.URL_ITEM_TYPE.MESSAGES.id # Deletes don't access topics, they operate on messages. if self.wsgi_environ['REQUEST_METHOD'] != 'DELETE': if not self.pubsub.can_access_topic( client.config.id, self.request.input.item, is_consumer): raise Forbidden( self.cid, 'You are not authorized to access this resource') self.environ['sub_key'] = sub_key self.environ['client_id'] = client.config.id self.environ[ 'format'] = self.request.input.format if self.request.input.format else PUB_SUB.GET_FORMAT.DEFAULT.id self.environ['is_json'] = self.environ[ 'format'] == PUB_SUB.GET_FORMAT.JSON.id