def _make_request(scheme, host, port, username, password, path, method='GET', data=None, query=None, timeout=None, content_type=None): path = _DOUBLE_SLASH_REGEX.sub('/', path) url = '%(scheme)s://%(host)s%(port)s%(path)s' % { 'scheme': scheme, 'host': host, 'port': ':' + str(port) if port else '', 'path': path or ''} query = dict(query or {}) query['_username'] = username or '' query['_admin'] = 'true' # always use the admin account if url.count('?'): url += '&' else: url += '?' url += '&'.join([(n + '=' + v) for (n, v) in query.iteritems()]) url += '&_signature=' + utils.compute_signature(method, url, data, password) if timeout is None: timeout = settings.REMOTE_REQUEST_TIMEOUT headers = {} if content_type: headers['Content-Type'] = content_type return HTTPRequest(url, method, body=data, connect_timeout=timeout, request_timeout=timeout, headers=headers)
def _make_request(scheme, host, port, username, password, path, method='GET', data=None, query=None, timeout=None): path = _DOUBLE_SLASH_REGEX.sub('/', path) url = '%(scheme)s://%(host)s%(port)s%(path)s' % { 'scheme': scheme, 'host': host, 'port': ':' + str(port) if port else '', 'path': path or ''} query = dict(query or {}) query['_username'] = username or '' query['_admin'] = 'true' # always use the admin account if url.count('?'): url += '&' else: url += '?' url += '&'.join([(n + '=' + v) for (n, v) in query.iteritems()]) url += '&_signature=' + utils.compute_signature(method, url, data, password) if timeout is None: timeout = settings.REMOTE_REQUEST_TIMEOUT return HTTPRequest(url, method, body=data, connect_timeout=timeout, request_timeout=timeout)
def _make_request(scheme, host, port, username, password, path, method="GET", data=None, query=None, timeout=None): path = _DOUBLE_SLASH_REGEX.sub("/", path) url = "%(scheme)s://%(host)s%(port)s%(path)s" % { "scheme": scheme, "host": host, "port": ":" + str(port) if port else "", "path": path or "", } query = dict(query or {}) query["_username"] = username or "" query["_admin"] = "true" # always use the admin account if url.count("?"): url += "&" else: url += "?" url += "&".join([(n + "=" + v) for (n, v) in query.iteritems()]) url += "&_signature=" + utils.compute_signature(method, url, data, password) if timeout is None: timeout = settings.REMOTE_REQUEST_TIMEOUT return HTTPRequest(url, method, body=data, connect_timeout=timeout, request_timeout=timeout)
def main(parser, args): import meyectl options = parse_options(parser, args) meyectl.configure_logging('relayevent', options.log_to_file) meyectl.configure_tornado() logging.debug('hello!') logging.debug('event = %s' % options.event) logging.debug('thread_id = %s' % options.thread_id) if options.filename: logging.debug('filename = %s' % options.filename) admin_username, admin_password = get_admin_credentials() data = { '_username': admin_username, 'thread_id': options.thread_id, 'event': options.event } if options.filename: data['filename'] = options.filename path = '/_relay_event/' body = json.dumps(data) signature = utils.compute_signature('POST', path, body, admin_password) url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature url = url % {'port': settings.PORT} request = urllib2.Request(url, data=body, headers={'Content-Type': 'application/json'}) try: response = urllib2.urlopen(request) response = json.load(response) if response.get('error'): raise Exception(response['error']) logging.debug('event successfully relayed') except Exception as e: logging.error('failed to relay event: %s' % e) logging.debug('bye!')
def main(parser, args): import meyectl options = parse_options(parser, args) meyectl.configure_logging('relayevent', options.log_to_file) meyectl.configure_tornado() logging.debug('hello!') logging.debug('event = %s' % options.event) logging.debug('thread_id = %s' % options.thread_id) if options.filename: logging.debug('filename = %s' % options.filename) admin_username, admin_password = get_admin_credentials() data = { '_username': admin_username, 'thread_id': options.thread_id, 'event': options.event } if options.filename: data['filename'] = options.filename path = '/_relay_event/' body = json.dumps(data) signature = utils.compute_signature('POST', path, body, admin_password) url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature url = url % {'port': settings.PORT} request = urllib2.Request(url, data=body, headers={'Content-Type': 'application/json'}) try: response = urllib2.urlopen(request) response = json.load(response) if response.get('error'): raise Exception(response['error']) logging.debug('event successfully relayed') except Exception as e: logging.error('failed to relay event: %s' % e) logging.debug('bye!')
def main(parser, args): import meyectl options = parse_options(parser, args) meyectl.configure_logging('relayevent', options.log_to_file) meyectl.configure_tornado() logging.debug('hello!') logging.debug('event = %s' % options.event) logging.debug('thread_id = %s' % options.thread_id) admin_username, admin_password = get_admin_credentials() uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % { 'username': admin_username, 'thread_id': options.thread_id, 'event': options.event } signature = utils.compute_signature('POST', uri, '', admin_password) url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature url = url % {'port': settings.PORT} try: response = urllib.urlopen(url, data='') response = json.load(response) if response.get('error'): raise Exception(response['error']) logging.debug('event successfully relayed') except Exception as e: logging.error('failed to relay event: %s' % e) logging.debug('bye!')
def main(parser, args): import meyectl options = parse_options(parser, args) meyectl.configure_logging("relayevent", options.log_to_file) meyectl.configure_tornado() logging.debug("hello!") logging.debug("event = %s" % options.event) logging.debug("thread_id = %s" % options.thread_id) admin_username, admin_password = get_admin_credentials() path = "/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s" % { "username": admin_username, "thread_id": options.thread_id, "event": options.event, } signature = utils.compute_signature("POST", path, "", admin_password) url = "http://127.0.0.1:%(port)s" + path + "&_signature=" + signature url = url % {"port": settings.PORT} try: response = urllib.urlopen(url, data="") response = json.load(response) if response.get("error"): raise Exception(response["error"]) logging.debug("event successfully relayed") except Exception as e: logging.error("failed to relay event: %s" % e) logging.debug("bye!")
def main(parser, args): import meyectl options = parse_options(parser, args) meyectl.configure_logging('relayevent', options.log_to_file) meyectl.configure_tornado() logging.debug('hello!') logging.debug('event = %s' % options.event) logging.debug('thread_id = %s' % options.thread_id) admin_username, admin_password = get_admin_credentials() uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % { 'username': admin_username, 'thread_id': options.thread_id, 'event': options.event} signature = utils.compute_signature('POST', uri, '', admin_password) url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature url = url % {'port': settings.PORT} try: response = urllib.urlopen(url, data='') response = json.load(response) if response.get('error'): raise Exception(response['error']) logging.debug('event successfully relayed') except Exception as e: logging.error('failed to relay event: %s' % e) logging.debug('bye!')